这对我来说毫无意义。我有一个从我的主类调用的完整登录屏幕,问题是用于保存文本区域等的 JPanel 在我单击窗口边缘之前不会显示(展开它)
这是我的代码:
主要的
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SchoolSystem
{
public static void main (String [] args)
{
Login lg = new Login();
}
}
登录
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login extends JFrame implements ActionListener
{
JFrame frame;
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
public Menus m = new Menus();
final JTextField text1,text2;
{
frame = new JFrame("Welcome");
frame.setSize(310,110);
frame.setVisible(true);
label1 = new JLabel();
label1.setText("User ID:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
SUBMIT=new JButton("LOGIN");
panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
text2.addActionListener(this);
setTitle("Welcome");
frame.add(panel);
}
public void actionPerformed(ActionEvent ae)
{
//Gets the text inside the User ID and Password Panels
String value1=text1.getText();
String value2=text2.getText();
//Compare text to actual ID and password, Act accordingly
//In this case show a Menu for the Head Teacher
if ((value1.equals("Admin") && value2.equals("1234"))){
m.adminMenu();
frame.setVisible(false);
}
else{
if (value1.equals("Teach") && value2.equals("0000")) {
m.teacherMenu();
frame.setVisible(false);
}
else{
JOptionPane.showMessageDialog(this,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
}