天天看点

java 仿qq登陆界面

无聊中 想写的。。哎 迷茫啊。。

Main:

package 仿qq登录;
public class Main {
  public static void main(String args[]){
    WindowBuild win=new WindowBuild();
    win.setTitle("仿qq登录");
    win.setBounds(600,250,250,250);
  }
}      

WindowBuild:

package 仿qq登录;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowBuild extends JFrame implements ActionListener{
  JTextField input1;
  JPasswordField input2;
  JButton buttonEnter,buttonExit;
  JLabel zhangHao,miMa;
  JTextArea show;
  Box box1,box2,box3,baseBox;
  WindowBuild(){
    setLayout(new FlowLayout());
    init();
    input1.addActionListener(this);
    input2.addActionListener(this);
    buttonEnter.addActionListener(this);
    buttonExit.addActionListener(this);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  void init(){
    box1=Box.createHorizontalBox();
    zhangHao=new JLabel("账号");
    input1=new JTextField(5);
    box1.add(zhangHao);
    box1.add(Box.createHorizontalStrut(8));
    box1.add(input1);
    miMa=new JLabel("密码");
    input2=new JPasswordField(5);
    box2=Box.createHorizontalBox();
    box2.add(miMa);
    box2.add(Box.createHorizontalStrut(8));
    box2.add(input2);
    buttonExit=new JButton("清除");
    buttonEnter=new JButton("登录");
    box3=Box.createHorizontalBox();
    box3.add(buttonEnter);
    box3.add(Box.createHorizontalStrut(20));
    box3.add(buttonExit);
    baseBox=Box.createVerticalBox();
    baseBox.add(box1);
    baseBox.add(Box.createVerticalStrut(5));
    baseBox.add(box2);
    baseBox.add(Box.createVerticalStrut(1));
    baseBox.add(box3);
    baseBox.add(Box.createVerticalStrut(5));
    show=new JTextArea(6,20);
    baseBox.add(new JScrollPane(show));
    add(baseBox);
  }
  public void actionPerformed(ActionEvent e){
    String s1=input1.getText();
    String s2=input2.getText();
    if(e.getSource()==buttonEnter){
      int n=JOptionPane.showConfirmDialog(this, "确认是否正确","确认对话框",JOptionPane.YES_NO_CANCEL_OPTION);
      if(n==JOptionPane.YES_OPTION){
        show.append("成功录入!!!\n账号:"+s1+"  密码:"+s2+"\n");
        input1.setText(null);
        input2.setText(null);
      }
      else if(n==JOptionPane.NO_OPTION){
        show.append("录入失败!!!\n");
        input1.setText(null);
        input2.setText(null);
      }
    }
    else if(e.getSource()==buttonExit){
      input1.setText(null);
      input2.setText(null);
      show.append("已清除!!!\n");
    }
  }
}