📄 student.java
字号:
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class LoginFrame extends JFrame
{
JPanel p=new JPanel(new GridLayout(0,1));
JTextField UserName=new JTextField();
JPasswordField Password=new JPasswordField();
JButton button1=new JButton("OK");
LoginFrame()
{
final JFrame frame=this;
this.getContentPane().add(p);
p.add(new JLabel("Username:"));
p.add(UserName);
p.add(new JLabel("Password:"));
p.add(Password);
p.add(button1);
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(UserName.getText().equals("1")&&Password.getText().equals("1"))
{
frame.setVisible(false);
SystemFrame f2=new SystemFrame();
f2.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null,"Username or Password Error!","Message",0);
}
}
});
this.setSize(300,200);
this.setResizable(false);
this.setVisible(true);
this.setTitle("Login");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class SystemFrame extends JFrame
{
JPanel p=new JPanel(new GridLayout(0,1));
JMenuBar menubar=new JMenuBar();
JMenu menu1=new JMenu("Search");
JMenu menu2=new JMenu("Add");
JMenu menu3=new JMenu("Delete");
JMenuItem item11=new JMenuItem("Auto");
JMenuItem item12=new JMenuItem("Hand");
JMenuItem item1=new JMenu("Search");
JMenuItem item2=new JMenuItem("Add");
JMenuItem item3=new JMenuItem("Delete");
JMenuItem item4=new JMenuItem("Exit");
SystemFrame()
{
final JFrame frame=this;
this.getContentPane().add(p);
item11.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item11)
{
JOptionPane.showMessageDialog(null,"Building...","Message",0);
}
}
});
item12.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item12)
{
HandSearchFrame hand=new HandSearchFrame();
}
}
});
item2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item2)
{
Add add=new Add();
}
}
});
item3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item3)
{
JOptionPane.showMessageDialog(null,"Building...","Message",0);
}
}
});
item4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item4)
{
int result=JOptionPane.showConfirmDialog(null,"Are you sure to exit?","Warning",JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_OPTION)
{
System.exit(0);
}
}
}
});
menu1.add(item1);
menu1.addSeparator();
menu1.add(item4);
menu2.add(item2);
menu3.add(item3);
item1.add(item11);
item1.add(item12);
menubar.add(menu1);
menubar.add(menu2);
menubar.add(menu3);
setJMenuBar(menubar);
this.setSize(300,200);
this.setResizable(false);
this.setVisible(false);
this.setTitle("System");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.show();
}
}
public class Student
{
public static void main(String args[])
{
LoginFrame f1=new LoginFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -