package lele;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class cbl{
JFrame f1;JTextField t;JPasswordField p;final String n="admin";
final String n1="123";
cbl()
{
JFrame f1 =new JFrame();
JPanel j1=new JPanel();
JPanel j2=new JPanel();
JPanel j3=new JPanel();
JLabel l=new JLabel("用户名");
JLabel l1=new JLabel("密 码");
t =new JTextField(10);
p= new JPasswordField(10);
JButton b=new JButton("登录");
b.addActionListener(new EventListener3());
JButton b1=new JButton("重置");
b1.addActionListener(new EventListener3());
f1.setLayout(new GridLayout(3, 1));
j1.add(l);
j1.add(t);
j2.add(l1);
j2.add(p);
j3.add(b);
j3.add(b1);
f1.add(j1);
f1.add(j2);
f1.add(j3);
f1.setSize(300, 150);
f1.setTitle("用户登录");
f1.setVisible(true);
f1.setResizable(false);
f1.setLocationRelativeTo(null);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class EventListener3 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JDialog dialog;
JLabel w;
JButton b=(JButton)e.getSource();
String m=e.getActionCommand();
if(m=="登录")
{
if(n.equals(t.getText())&&n1.equals(p.getText())){
w=new JLabel("登录成功",JLabel.CENTER);
dialog=new JDialog();
dialog.setTitle("登录成功");
dialog.add(w);
dialog.setLocationRelativeTo(null);
dialog.setSize(250,100);
dialog.setVisible(true);
dialog.setResizable(false);}
else
{
dialog=new JDialog();
dialog.setTitle("登录失败");
w=new JLabel("用户名或密码错误,请重新输入",JLabel.CENTER);
dialog.add(w);
dialog.setLocationRelativeTo(null);
dialog.setSize(250,100);
dialog.setVisible(true);
dialog.setResizable(false);
t.setText(null);
p.setText(null);
}
}
if(m=="重置")
{
t.setText(null);
p.setText(null);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new cbl();
}
}
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class cbl{
JFrame f1;JTextField t;JPasswordField p;final String n="admin";
final String n1="123";
cbl()
{
JFrame f1 =new JFrame();
JPanel j1=new JPanel();
JPanel j2=new JPanel();
JPanel j3=new JPanel();
JLabel l=new JLabel("用户名");
JLabel l1=new JLabel("密 码");
t =new JTextField(10);
p= new JPasswordField(10);
JButton b=new JButton("登录");
b.addActionListener(new EventListener3());
JButton b1=new JButton("重置");
b1.addActionListener(new EventListener3());
f1.setLayout(new GridLayout(3, 1));
j1.add(l);
j1.add(t);
j2.add(l1);
j2.add(p);
j3.add(b);
j3.add(b1);
f1.add(j1);
f1.add(j2);
f1.add(j3);
f1.setSize(300, 150);
f1.setTitle("用户登录");
f1.setVisible(true);
f1.setResizable(false);
f1.setLocationRelativeTo(null);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class EventListener3 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JDialog dialog;
JLabel w;
JButton b=(JButton)e.getSource();
String m=e.getActionCommand();
if(m=="登录")
{
if(n.equals(t.getText())&&n1.equals(p.getText())){
w=new JLabel("登录成功",JLabel.CENTER);
dialog=new JDialog();
dialog.setTitle("登录成功");
dialog.add(w);
dialog.setLocationRelativeTo(null);
dialog.setSize(250,100);
dialog.setVisible(true);
dialog.setResizable(false);}
else
{
dialog=new JDialog();
dialog.setTitle("登录失败");
w=new JLabel("用户名或密码错误,请重新输入",JLabel.CENTER);
dialog.add(w);
dialog.setLocationRelativeTo(null);
dialog.setSize(250,100);
dialog.setVisible(true);
dialog.setResizable(false);
t.setText(null);
p.setText(null);
}
}
if(m=="重置")
{
t.setText(null);
p.setText(null);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new cbl();
}
}