Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在JavaSwing上调用setVisible,但什么也没发生_Java_User Interface - Fatal编程技术网

我在JavaSwing上调用setVisible,但什么也没发生

我在JavaSwing上调用setVisible,但什么也没发生,java,user-interface,Java,User Interface,我正在尝试在框架和setVisible之间创建导航,但什么都不做。我想在移动到下一个窗口后关闭主窗口。我一直在eclipse和其他平台上使用windows builder。java也扩展到了JFrame public class LoginF extends JFrame{ private JFrame frame; private JTextField textField; private JTextField textField_1; /** * Launch the applicat

我正在尝试在框架和setVisible之间创建导航,但什么都不做。我想在移动到下一个窗口后关闭主窗口。我一直在eclipse和其他平台上使用windows builder。java也扩展到了JFrame

public class LoginF extends JFrame{

private JFrame frame;
private JTextField textField;
private JTextField textField_1;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                LoginF window = new LoginF();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public LoginF() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 536, 421);
    setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
    gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
    gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    frame.getContentPane().setLayout(gridBagLayout);        

    JButton btnLogin = new JButton("Login");
    btnLogin.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
这里什么也没发生

    JButton btnRegister = new JButton("Register");
            btnRegister.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Registration nw = new Registration();
                    nw.regScreen();
                    LoginF.this.setVisible(false);


            }
        });
    }

}

您的代码有几个问题:

  • 您的类
    LoginF
    扩展了
    JFrame
    ,因此
    这是您的框架。你不需要再创建一个
  • 您不会像这样使用
    GridBagLayout

  • 您的按钮不会添加到任何框架中

我建议您阅读一两本书。

我认为最好将主框架设置为不可见,然后将新框架设置为可见,如:

Registration nw = new Registration();
LoginF.this.setVisible(false);  
nw.regScreen();
这确保在显示新帧之前终止第一个主(GUI)循环。 还有什么是
LoginF.this.setVisible(false)
LoginF.setVisible(false)
还不够吗?因为
LoginF
已经扩展了
JFrame


另外,请确保在@Maurice Perry评论的地方添加了JButton。

显然,在调用LoginF.this.setVisible(false)时,应该将其排除在外;同样,我们也不清楚为什么要调用window.frame.setVisible,因为您的LoginF没有任何组件?扩展JFrame的目的是什么?当类已经在扩展JFrame时,为什么会有JFrame字段?您的按钮没有添加到任何帧,因此它们是不可见的。