简体   繁体   English

Java:在单击第一帧的按钮时创建第二帧

[英]Java: create second frame while clicking on button of first frame

In my application one frame is there on which one button is there. 在我的应用程序中,一帧上有一个按钮。 If this button is clicked then second frame will open and it will take some data from the client. 如果单击此按钮,则第二个框架将打开,它将从客户端获取一些数据。 And after submitting (Submit Button on Second frame) these data, frame will close.I use JFrame for first frame. 提交(第二帧上的“提交按钮”)后,这些数据将关闭。我将JFrame用于第一帧。

Now what I use for the second frame. 现在我用于第二帧。

These type of question previously asked on this site but lot of people say that use JDesktopPane, JDialog and other things. 这些问题以前曾在此站点上提出过,但很多人说它们使用JDesktopPane,JDialog等。 I am confused so please clearly specify what is the right way. 我很困惑,所以请清楚说明什么是正确的方法。 currently I am using JFrame for first and second frame. 目前,我在第一帧和第二帧使用JFrame。 But I know this is bad idea to use two Jframe in one application and second frame also not work in that way which I want. 但是我知道在一个应用程序中使用两个Jframe,而第二个框架也无法按照我想要的方式工作是一个坏主意。

If your answer is to use JDialog then please mention how I customize this. 如果您的答案是使用JDialog,请提及我如何自定义它。

I am attaching the look of second frame which help you guy to understand what I want in my application. 我附上第二帧的外观,可帮助您了解我想要的应用程序。

在此处输入图片说明

Use JDialog and make it modal. 使用JDialog并将其设置为模态。 So when you call it you can process all the results just after cloging it in the same method. 因此,当您调用它时,可以使用相同的方法将其克隆后立即处理所有结果。

If you are using two frames then in the second frame use setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 如果您使用的是两帧,则在第二帧中使用setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); instead of setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 而不是setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM