import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class weixin extends JFrame implements ActionListener {
JPanel panmain; //面板
JLabel lblname,lblpassword,lblphoto; //标签
JLabel first,second,three;
JButton btnlogin; //按钮
JTextField txtname; // 单行文本框
JTextField txtpassword; //单行文本框
JPasswordField pwdpassword; //密码框
JCheckBox chkbold; //复选框
Dimension dsSize;
Toolkit toolkit=Toolkit.getDefaultToolkit();
public weixin(){
super("登录微信");
panmain =new JPanel(); //实例化面板
this.getContentPane().add(panmain);
lblname=new JLabel("账号:");
txtname=new JTextField(18); //实例化长度为18的文本框对象
lblpassword=new JLabel("密码:");
txtpassword=new JTextField(18);
pwdpassword=new JPasswordField(18); //实例化长度为18的文本框对象
chkbold=new JCheckBox("显示密码");
btnlogin=new JButton("登录");
first=new JLabel("忘记密码?");
second=new JLabel("创建新账号");
three=new JLabel("切换接入点?");
// Font fontstr=new Font("宋体",Font.PLAIN,12);
// lblname.setFont(fontstr);
// lblname.setForeground(Color.GREEN);
// lblpassword.setForeground(Color.GREEN);
btnlogin.setBackground(Color.GREEN); //设置按钮颜色为绿色
panmain.setLayout(null); //空布局
lblname.setBounds(6,50,400,25); //对‘账号’实行空布局
txtname.setBounds(40,50,210,25); // 对文本框实行空布局
lblpassword.setBounds(6,80,500,25); //对’密码‘实行空布局
pwdpassword.setBounds(40,80,210,25); //对密码文本框实行空布局
txtpassword.setBounds(40,80,210,25);
chkbold.setBounds(5,116,80,25); //对复选框实行空布局
btnlogin.setBounds(150,120,99,25); //对按钮实行空布局
first.setBounds(6,160,600,25);
second.setBounds(6,190,700,25);
three.setBounds(6,220,800,25);
//pwdpassword=new JPasswordField();
//panmain.setToolTipText("登录到服务器");
// lblphoto=new JLabel(); //添加主面板背景(方法1)
// Image image1=new ImageIcon("./src/weixin1.jpg").getImage();
// lblphoto.setIcon(new ImageIcon(image1));
//panmain.setBackground(Color.black);
Icon logol=new ImageIcon("./src/weixin1.jpg"); // //添加主面板背景(方法2)
lblphoto=new JLabel(logol);
lblphoto.setBounds(0,0,266,394);
panmain.add(lblphoto);
chkbold.addActionListener(this);
txtpassword.addActionListener(this);
// panmain.add(lblname); //添加标签‘账号’到主面板
// panmain.add(lblpassword); //添加标签‘密码’到主面板
//panmain.add(txtname); //添加单行文本框到主面板
//panmain.add(pwdpassword); //添加密码框到主面板
//panmain.add(chkbold); //添加复选框到主面板
//panmain.add(btnlogin); //添加按钮到主面板
// lblname.setFont (fontstr);
lblphoto.add(lblname);
lblphoto.add(lblpassword);
lblphoto.add(txtname);
lblphoto.add(pwdpassword);
lblphoto.add(chkbold);
lblphoto.add(btnlogin);
lblphoto.add(first);
lblphoto.add(second);
lblphoto.add(three);
lblphoto.add(txtpassword);
setContentPane(lblphoto);
setSize(266,400);
setVisible(true);
setResizable(false);
dsSize=toolkit.getScreenSize();
//this.setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(dsSize.width/2-this.getWidth()/2,
dsSize.height/2-this.getHeight()/2);
Image img=toolkit.getImage("./src/1.jpg");
setIconImage(img);
}
public static void main(String args[]) {
new weixin();
}
public void actionPerformed1(ActionEvent ae)
{
if(ae.getSource()==btnlogin){
if(pwdpassword.getText().equals("admin")) && (pwdpassword.getText().equals("admin")))
JOptionPane.showMessageDialog(null,"用户登录成功");
else
JOptionPane.showMessageDialog(null,"用户名或密码错误");
}
}
}