java - 如何打开主机?
问题描述
我该怎么做才能打开主机,请查看我的代码并更正,或者告诉我哪里有错误。
这是授权窗口的代码,我想在单击“登录”按钮时看到主框架。请帮我。我不知道该怎么做。我参加这个项目超过 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
这可能会有所帮助。
推荐阅读
- php - 我可以使用 PHP 连接到 FTP 服务器,但即使使用被动模式也无法 ftp_nlist
- c++11 - cpu如何使用'mfence'来保护顺序一致性?
- node.js - Google Actions 是否可以将 CameraStream 与 Dialogflow 实现结合使用?
- excel - 平均相同的,然后在列表中找到最大值
- php - 使用 VB.net、PHP 和 Java 从 MySQL DB 保存和检索图像
- c# - 使用正则表达式 C# 从字符串中获取十进制值
- blockchain - 动态地将参与者添加到corda状态?
- javascript - Angular 2 在其他组件中显示具有相同数据的相同组件
- vim - Vim Formatprg 设置工作目录
- mysql - 如何在其他的基础上从表中选择数据