package Login_Frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import Main_Frame.*;
public class LoginFrame {
JFrame f ;
JTextField usernametext;
JPasswordField passwordtext;
JPanel panel_0;
ImageIcon background;
Font font = new Font("楷体GB2312", 1, 14);
//private ImageIcon[] imageIcon = new ImageIcon[1];
JLabel jjj= new JLabel(new ImageIcon("图片\\登陆.jpg"));
JLabel j = new JLabel();
public static void main(String[] args) {
new LoginFrame();
}
public LoginFrame(){
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
f= new JFrame("登陆");
f.setVisible(true);
//f.setSize(370,330);
f.setSize(360,330);
f.setLocation(600,220);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
panel_0 =new JPanel();
final JPanel panel = new JPanel();
BorderLayout border = new BorderLayout();
border.setVgap(20);
panel.setLayout(border);
panel_0.add(panel);
panel_0.setOpaque(false);
panel.setOpaque(false);
f.add(panel_0);
JPanel panel_2 = new JPanel();
GridLayout gridlayout = new GridLayout(3,1);
gridlayout.setVgap(0);
gridlayout.setHgap(10);
panel_2.setLayout(gridlayout);
panel_2.setSize(20, 20);
JPanel j1 = new JPanel();
JLabel username = new JLabel("用户名 ");
username.setFont(font);
j1.add(username);
usernametext = new JTextField(13);
usernametext.setFont(font);
j1.add(usernametext);
panel_2.add(j1);
JPanel j2= new JPanel();
JLabel password = new JLabel("密 码 ");
password.setFont(font);
j2.add(password);
passwordtext = new JPasswordField(14);
passwordtext.setEchoChar('*');
j2.add(passwordtext);
panel_2.add(j2);
JPanel panel_3 = new JPanel();
FlowLayout flowlayout = new FlowLayout();
flowlayout.setHgap(10);
panel_3.setLayout(flowlayout);
JButton button1 = new JButton("登陆");
panel_3.add(button1);
JButton button2 = new JButton("重置");
panel_3.add(button2);
JButton button3 = new JButton("取消");
panel_3.add(button3);
panel_2.add(panel_3);
panel.add(jjj,BorderLayout.NORTH);
panel.add(panel_2,BorderLayout.CENTER);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String s = usernametext.getText();
String s1 = passwordtext.getText();
if(s.equals("")||s1.equals("")){
JOptionPane.showMessageDialog(null,"用户名或密码不能为空!","提示!",JOptionPane.YES_NO_OPTION);
return;
}
if(s.equals("admin")&& s1.equals("admin")){
new MainFrame();
f.setVisible(false);
}else{
JOptionPane.showMessageDialog(null,"登陆失败!用户名或密码错误","警告!",JOptionPane.ERROR_MESSAGE);
usernametext.setText("");
passwordtext.setText("");
return;
}
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
usernametext.setText("");
passwordtext.setText("");
}
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
}
}