繁体   English   中英

如何打开主机架?

[英]How to open main frame?

我如何才能打开主机架,请查看我的代码,然后更正,或者告诉我哪里有误区。

这是授权窗口的代码,当我单击“登录”按钮时,我想查看主机框架。 请帮我。 我不知道该怎么做。 我在这个程序上坐了5天以上。

public static void authorizationWindow(){
    JButton createAcc = new JButton("Створити новий аккаунт");
    JButton loginIntoMy = new JButton("Ввійти в існуючий");
    loginIntoMy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel  jPanelCreateAcc = new JPanel();
            JLabel nameLabel = new JLabel("Введіть ваш email:");
            JLabel passLabel = new JLabel("Введіть пароль :");
            JTextField name = new JTextField(10);
            JPasswordField pass =new JPasswordField(10);

            jPanelCreateAcc.add(nameLabel);
            jPanelCreateAcc.add(name);
            jPanelCreateAcc.add(passLabel);
            jPanelCreateAcc.add(pass);

            JButton login = new JButton("Ввійти");
            JButton cancel = new JButton("Вийти");


            login.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {

                String text =   name.getText();
                char[] password = pass.getPassword();
                System.out.println(" "+ text + ""+new String(password));




                }
            }); 

     //              Кнопка вийти має виходити повністю з програми

            cancel.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);

                }
            });


            JOptionPane.showOptionDialog(createAcc,jPanelCreateAcc,"Вхід", JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null,new Object[]{login,cancel},null);   





        }
    });

    int n =JOptionPane.showOptionDialog(null, "", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{createAcc,loginIntoMy}, null);


}

这是一个主框架代码:

private static Component createWindow(int width, int height,
        String title ) throws IOException {





    window.setVisible(true);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setResizable(false);
    window.setLocationRelativeTo(null);
    window.pack();
    window.setTitle(title);
    window.setSize(width, height);
    JPanel jPanel = new JPanel();
    window.add(jPanel);


    screenButton.setLocation(25, 59);



 //      jtb.setFont(new Font("Times New Roman",1,14));

    jPanel.setBackground(Color.lightGray);
    jPanel.add(screenButton);
    jPanel.add(saveTextButton);

    jtb.setBackground(Color.green);
    JScrollPane jsp = new JScrollPane(jtb);
    jsp.setPreferredSize(new Dimension(900, 247));

    jpm.add(copy);
    jtb.setComponentPopupMenu(jpm);
    jPanel.add(jsp);

    jtb2.setBackground(Color.orange);
    JScrollPane jsp2 = new JScrollPane(jtb2);
    jsp2.setPreferredSize(new Dimension(900, 247));
    jtb2.setComponentPopupMenu(jpm);

    jtb3.setBackground(Color.white);
    JScrollPane jsp3 = new JScrollPane(jtb3);
    jsp3.setPreferredSize(new Dimension(300, 247));
    jtb3.setComponentPopupMenu(jpm);

    jPanel.add(time());
    jPanel.add(jsp2);
    jPanel.add(jsp3);

    window.setJMenuBar(jMenuBar);
    jMenuBar.add(jMenu);
    jMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jMenuItem, "");

        }
    });




    // GridBagLayout gbl = new GridBagLayout();
    //
    // jPanel.setLayout(gbl);
    // GridBagConstraints gbc = new GridBagConstraints();
    //
    // gbc.gridx = 0;
    // gbc.gridy = 0;
    //
    // gbc.weightx = 0.0 ;
    // gbc.weighty = 0.9;
    //
    // gbc.insets =new Insets(10,3,4,5);
    // gbc.anchor = GridBagConstraints.WEST;

    return jMenu.add(jMenuItem);
}

这是一个线程:

javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                try {
                    authorizationWindow();
            createWindow(1280, 720, "");
}

添加带有伪代码的东西

if button_press == true then
    show main_frame
endif

这可能会有所帮助。

CR7,看起来您的所有代码似乎都不在这里,但我可以告诉您

authorizationWindow()

有一个动作监听器

        login.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

            String text =   name.getText();
            char[] password = pass.getPassword();
            System.out.println(" "+ text + ""+new String(password));
            }
        }); 

这是您进行主窗口调用的地方,因此看起来更像

        login.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

            String text =   name.getText();
            char[] password = pass.getPassword();
            System.out.println(" "+ text + ""+new String(password));
            createWindow(1280, 720, "");
            }
        }); 

在您的线程上,删除createWindow(1280,720,“”); 否则,那将同时创建窗口。

我假设您在程序中的其他位置将“窗口”创建为JFrame

暂无
暂无

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

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