Java的:等待第一帧,而retriving然后泡上关闭按钮和控制从第二帧的数据也来到弗里斯特框架 [英] Java: wait first frame while retriving data from second frame then on hitting on close button and control also come to the frist frame

查看:295
本文介绍了Java的:等待第一帧,而retriving然后泡上关闭按钮和控制从第二帧的数据也来到弗里斯特框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序两种帧是存在的。在主框架服务器按钮是存在的。当我点击服务器按钮,第二帧将打开并进入当我点击了一些细节后,提交按钮,这是第二架该框架将关闭,控制再次转到服务器按钮,在这里我把这个框架,使我会尽我的任务休息。
还有一件事我想在我的应用程序时,第二架是开放则没有活动第一帧。

我的第一帧是:的JFrame框架;

在此帧中的一个服务器按钮有:的JButton btnSaveOnServer;

在此按钮的addActionListener方法,我写这篇code打开第二帧:

  btnSaveOnServer.addActionListener(新的ActionListener(){
            @覆盖
            公共无效的actionPerformed(ActionEvent的为arg0){
                    ServerClass窗口=新ServerClass();
                    window.serverFrame.setVisible(真);
            }
        });

code的第二帧:

 公共类ServerClass {
公众的JFrame serverFrame;
私人JLabel的用户名;
私人JLabel的密码;
私人的JTextField textUsername;
私人JPasswordField中textPassword;
私人的JButton btnOk;
保护ServerClass(){
尝试{
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());        serverFrame =新的JFrame(服务器条目令牌);        serverFrame.setBounds(500,280,335,250);
        serverFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        serverFrame.getContentPane()的setLayout(空)。        字体=新的字体(宋体,Font.BOLD,15);        的userName =新的JLabel(用户名);
        userName.setBounds(4,40,100,15);
        userName.setFont(字体);        密码=新的JLabel(密钥);
        password.setBounds(4,69,100,15);
        password.setFont(字体);        textUsername =新的JTextField();
        textUsername.setBounds(110,35,200,25);
        textUsername.setFont(字体);
        textPassword =新JPasswordField(10);
        textPassword.setBounds(110,65,200,25);
        textPassword.setEchoChar(CH);        btnOk =的新的JButton(提交);
        btnOk.setBounds(30,170,85,25);        serverFrame.add(用户名);
        serverFrame.add(密码);
        serverFrame.add(textUsername);
        serverFrame.add(textPassword);
        serverFrame.add(btnOk);        btnOk.addActionListener(新的ActionListener(){
            @覆盖
            公共无效的actionPerformed(ActionEvent的为arg0){
                如果(!textUsername.getText()。等于()
                        &功放;&安培; !textPassword.getText()。等于()){                    tArea.append(用户名:\\ t+ textUsername.getText()+\\ n);
                    tArea.append(通行证:\\ t+ textPassword.getText()+\\ n);
// TAREA是第一架在那里我显示输入的数据的区域。
            serverFrame.dispose();
                }            }
        });
}}

下面我添加了code serverFrame.dispose(); 在提交按钮,关闭框架,但控制未来的第一帧。
所以,我的问题是:


  1. 如何禁用或不活动我的第一帧,而第二帧是开放的。

  2. 在我的code,我呼吁在第一帧的服务器按钮,第二帧。这是写方法来调用第二帧到第一帧?

  3. 我如何关闭第二个框架,使框架将关闭和控制会去第一帧的服务器按钮(点击提交按钮后)。


解决方案

1)在我的应用程序两种帧是有

不要使用两个 JFrames ,那ISN ŧ无需使用( JNI或JNA ),这些容器不农具,还有艰苦的工作招一的JFrame toFront() / 调用toBack() /实 FocusRecycle 是残酷的笑话

2)使用的JDialog ,用 setModal ModalityType

3)纯香草的JOptionPane 是最好的办法豪做到这一点,

4)的JFrame /的JDialog /的JWindow 不农具完成(),那么不要紧,如果您致电调用setVisible(假)的Dispose()

In my application two frame is there. In main frame "Server" button is there. When I click on "Server" button second frame will open and after enter some detail when i click on "submit" button which is on second frame this frame will close and control again go to the "Server" button where I call this frame so I will do my rest of task. And one more thing I want in my application when the second frame is open then no activity is on first frame.

My first frame is : JFrame frame;

In this frame one Server button is there: JButton btnSaveOnServer;

In addActionListener of this button I write this code to open second frame:

btnSaveOnServer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                    ServerClass window = new ServerClass();
                    window.serverFrame.setVisible(true);
            }
        });

Code for the Second Frame:

public class ServerClass{
public JFrame serverFrame;
private JLabel userName;
private JLabel password;
private JTextField textUsername;
private JPasswordField textPassword;
private JButton btnOk;
protected ServerClass(){
try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        serverFrame = new JFrame("Server Entry Token");

        serverFrame.setBounds(500, 280, 335, 250);
        serverFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        serverFrame.getContentPane().setLayout(null);

        font = new Font("Arial", Font.BOLD, 15);

        userName = new JLabel("Username");
        userName.setBounds(4, 40, 100, 15);
        userName.setFont(font);

        password = new JLabel("PassKey");
        password.setBounds(4, 69, 100, 15);
        password.setFont(font);

        textUsername = new JTextField();
        textUsername.setBounds(110, 35, 200, 25);
        textUsername.setFont(font);


        textPassword = new JPasswordField(10);
        textPassword.setBounds(110, 65, 200, 25);
        textPassword.setEchoChar(ch);

        btnOk = new JButton("Submit");
        btnOk.setBounds(30, 170, 85, 25);

        serverFrame.add(userName);
        serverFrame.add(password);
        serverFrame.add(textUsername);
        serverFrame.add(textPassword);
        serverFrame.add(btnOk);

        btnOk.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (!textUsername.getText().equals("")
                        && !textPassword.getText().equals("")) {

                    tArea.append("Username:\t"+textUsername.getText()+"\n");
                    tArea.append("Pass:\t"+textPassword.getText()+"\n");
//tArea is the area in first frame where I display the entered data.
            serverFrame.dispose();      
                }

            }
        });
}

}

Here I add the code serverFrame.dispose(); in "Submit" button which close the frame but control not come to the first frame. So my problem is:

  1. How I disable or inactive my first frame while second frame is open.
  2. in my code I am calling second frame in "server" button of first frame. Is this write way to call second frame into first frame?
  3. how I close the second frame (after clicking on submit button) so frame will close and control will go to the "Server" button of first frame.

解决方案

1) In my application two frame is there

don't use two JFrames, thats isn't possible without using (JNI or JNA), these containers doesn't implements parent, there is hard job move one JFrame toFront() / toBack() / real FocusRecycle is cruel joke

2) use JDialog, with setModal or ModalityType,

3) plain vanilla JOptionPane is best way ho to do it,

4) JFrame / JDialog / JWindow doesn't implements finalize(), then doesn't matter if you call for setVisible(false) or dispose()

这篇关于Java的:等待第一帧,而retriving然后泡上关闭按钮和控制从第二帧的数据也来到弗里斯特框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆