日期:2014-05-20 浏览次数:21300 次
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class login extends JFrame implements ActionListener {
private JTextField name=new JTextField();
private JPasswordField password=new JPasswordField();
private JButton beSure=new JButton();
private JButton quit=new JButton();
private JButton register=new JButton();
private String na;
private String pass;
private MyPanel pnlMain;
private Image icon=new ImageIcon("Image/login.gif").getImage();
public login(){
pnlMain = new MyPanel(icon);
pnlMain.setLayout(null);
name.setBounds(560 ,87,121,34);//尺寸和位置都是固定好的,因为在图片上面PS了一段空白的地方
password.setBounds(560 ,136,121,34);//尺寸和位置都是固定好的,因为在图片上面PS了一段空白的地方
password.setEchoChar('*');
beSure.setBounds(488,200 ,75 ,40 );//确定按钮显示
beSure.setText( "确定");
beSure.setFont(new Font("华文行楷",Font.BOLD,18));
beSure.setContentAreaFilled(false);
quit.setBounds(595,200 ,75 ,40 );//取消按钮
quit.setText( "取消");
quit.setFont(new Font("华文行楷",Font.BOLD,18));
quit.setContentAreaFilled(false);
register.setBounds(490,260,180,40);//新用户注册按钮
register.setText( "新用户注册");
register.setFont( new Font("华文行楷",Font.BOLD,25));
register.setContentAreaFilled(false);
pnlMain.add(name);
name.setHorizontalAlignment(JTextField.CENTER);
pnlMain.add(password);
password.setHorizontalAlignment(JTextField.CENTER);
pnlMain.add(beSure);
pnlMain.add(quit);
pnlMain.add(register);
Container container = getContentPane();
container.add(pnlMain);
setSize( 716, 371);//框架设置成图片的大小
setTitle( "test");
setLocationRelativeTo(null);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
beSure.addActionListener( this);
quit.addActionListener(this);
register.addActionListener(this);
}
public static void main(String []args){
login l=new login();
l.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==beSure){
System.out.println(name.getText());
System.out.println(password.getText());
}
else if(e.getSource()==quit){
dispose();
}
else if(e.getSource()==register){
dispose();
}
}
class MyPanel extends JPanel {
private Image back;
public MyPanel(Image image) {
super();
back = image;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(back, 0, 0, 716,371,this);
}
}
}