gpt4 book ai didi

java - 如何打开主框架?

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:46 25 4
gpt4 key购买 nike

我该如何打开主框架,请查看我的代码并更正,或者告诉我哪里有错误。

这是授权窗口的代码,我想在单击“登录”按钮时看到主框架。请帮我。我不知道该怎么做。我参加这个项目已经超过 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

这可能会有所帮助。

关于java - 如何打开主框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53177120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com