package zzDemo;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class QQlogin {
public static void main(String[] args) {
Frame f = new Frame();
f.setSize(300, 200);
f.setLocation(500, 200);
f.setLayout(null);
f.setResizable(false);
f.setIconImage(Toolkit.getDefaultToolkit().getImage("img/qq_3d.png"));
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
f.dispose();
}
@Override
public void windowClosed(WindowEvent e) {
}
});
Label name = new Label("账号");
name.setSize(50, 30);
name.setLocation(30, 50);
f.add(name);
Label pwd = new Label("密码:");
pwd.setSize(50, 30);
pwd.setLocation(30, 80);
f.add(pwd);
TextField zh = new TextField();
zh.setSize(150, 20);
zh.setLocation(80, 55);
zh.addKeyListener(new KeyListener() {
@SuppressWarnings("static-access")
@Override
public void keyTyped(KeyEvent e) {
int key=e.getKeyChar();
if(key>=e.VK_0 && key<=e.VK_9){
}else{
e.consume();
}
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
});
f.add(zh);
TextField mm = new TextField();
mm.setSize(150, 20);
mm.setLocation(80, 85);
mm.setEchoChar('*');
f.add(mm);
Button login = new Button();
login.setLabel("登录");
login.setSize(100, 30);
login.setLocation(30, 130);
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String t1=zh.getText();
String t2=mm.getText();
if(t1.equals("112233")&&t2.equals("1111")){
System.out.println("登录成功!即将跳转至QQ主页……");
f.dispose();
new Main();
}else if(t1.equals("112233") && !t2.equals("1111")){
System.out.println("密码错误");
}else if(t1.equals("")){
System.out.println("账号不能为空");
}else if(t2.equals("")){
System.out.println("密码不能为空");
}else{
System.out.println("账号或密码错误");
}
}
});
f.add(login);
Button reg = new Button("注册");
reg.setSize(100, 30);
reg.setLocation(140, 130);
f.add(reg);
f.setVisible(true);
f.setResizable(false);
}
}
package zzDemo;
import java.awt.Frame;
public class Main {
public Main(){
Frame f=new Frame();
f.setSize(500, 800);
f.setLocation(100, 50);
f.setVisible(true);
}
}