import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
public class QQ
{
public static void main(String args[])
{
WindowBox win=new WindowBox("QQ2011");
// Draw d=new Draw();
}
}
class WindowBox extends Frame implements ActionListener
{
Box baseBox,boxv1,boxv2,boxv3;
Button b1,b2;
TextField text1,text2;
WindowBox(String s)
{
super(s);
boxv1=Box.createVerticalBox();
boxv1.add(new Label("账号"));
boxv1.add(Box.createVerticalStrut(10));
boxv1.add(new Label("密码"));
boxv1.add(Box.createVerticalStrut(10));
//boxv1.add(new Label(""));
b1=new Button("登录");
b1.addActionListener(this);
b2=new Button("退出");
b2.addActionListener(this);
boxv3=Box.createHorizontalBox();
boxv3.add(b1);
boxv3.add(Box.createHorizontalStrut(10));
boxv3.add(b2);
text1=new TextField(10);
text2=new TextField(10);
text2.setEchoChar('*');
boxv2=Box.createVerticalBox();
boxv2.add(text1);
boxv2.add(Box.createVerticalStrut(10));
boxv2.add(text2);
boxv2.add(Box.createVerticalStrut(10));
boxv2.add(boxv3);
baseBox=Box.createHorizontalBox();
baseBox.add(boxv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxv2);
setLayout(new FlowLayout());
add(baseBox);
setBounds(600,125,400,260);
setVisible(true);
setResizable(true);
ImageIcon icon=new ImageIcon("qq.jpg");
setIconImage(icon.getImage());
setBackground(Color.pink);
}
/*class D extends JFrame
public void Draw()
{
MyPanel mp=null;
mp=new MyPanel();
this.add(mp);
this.setSize(400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
class MyPanel extends JPanel
{
public void paint(Graphics g)
{
super.paint(g);
// g.setColor(Color.blue);
// g.fillRect(10,10, 40,60);
// g.setColor(Color.red);
// g.fillRect(80,80, 40, 60);
// System.out.println("paint被调用");
// g.drawOval(10,10,30,30);
Image im=Toolkit.getDefaultToolkit().getImage
(Panel.class.getResource("\\aa.jpg"));
g.drawImage(im,90,90,200,150,this);
}
}*/
public void actionPerformed(ActionEvent e)
{
/*if(text1.getText().equals("123456")&&text2.getText().equals("123456"))
{
JOptionPane.showMessageDialog(null,"恭喜,登陆成功");
}
else
{
JOptionPane.showMessageDialog(null,"登陆失败,密码或账号错误,请重新登录");
text1.setText(null);
text2.setText(null);
}*/
if(e.getSource()==b1)
{
if(text1.getText().equals("123456")&&text2.getText().equals("123456"))
{
JOptionPane.showMessageDialog(null,"恭喜,登陆成功");
}
else
{
JOptionPane.showMessageDialog(null,"登陆失败,密码或账号错误,请重新登录");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==b2)
{
System.exit(0);
}
}
}