import java.awt.event.*;import java.io.*;class login extends JFrame implements ActionListener { public JPasswordField password;public JTextField name;JButton ok;login(){ setSize(300,200);//大小 setLocation(200,100);JPanel panel = new JPanel();//创建一个面板对象 panel.setLayout(...
java写一个登录界面
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class login extends JFrame implements ActionListener
{
public JPasswordField password;
public JTextField name;
JButton ok;
login()
{
setSize(300,200);//大小
setLocation(200,100);
JPanel panel = new JPanel();//创建一个面板对象
panel.setLayout(new GridBagLayout());
Container cn = this.getContentPane();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5,2,5,5);
c.gridheight = 1;
JLabel user = new JLabel("User:");
c.gridx = 1;
c.gridy = 1;
panel.add(user,c);
name = new JTextField(10);
c.gridx = 2;
panel.add(name,c);
JLabel pass = new JLabel("assword:");
c.gridx = 1;
c.gridy = 2;
panel.add(pass,c);
password = new JPasswordField(10);
c.gridx = 2;
c.gridy = 2;
panel.add(password,c);
c.gridx = 1;
c.gridy = 3;
ok = new JButton("login");
ok.addActionListener(this);
panel.add(ok,c);
cn.add(panel);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == ok)
{
String username = this.name.getText();
String password = this.password.getText();
String message = username + " "+password;
try
{
byte[] b = message.getBytes();
FileOutputStream fos = new FileOutputStream("login.txt");
fos.write(b,0,b.length);
this.dispose();
}catch(Exception ex)
{
}
}
}
public static void main(String args[])
{
new login().show();
}
}2010-03-20
随便找一本JSP的书都有。2010-03-20