展开全部
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class Output_GUI extends JFrame implements MouseListener
{
JLabel jLabel1,jLabel2,jLabel3;//定义三个标签32313133353236313431303231363533e4b893e5b19e31333337393539
JTextField jTextField1;//密码框
JPasswordField jPasswordField1;//
JButton jButton1,jButton2;
public Output_GUI()
{
this.setTitle("注册界面");
this.setBounds(100, 50, 330, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane();
con.setLayout(null);
jLabel1 = new JLabel("注册");
jLabel2 = new JLabel("帐号:");
jTextField1 = new JTextField();
jLabel3 = new JLabel("密码:");
jPasswordField1 = new JPasswordField();
jButton1 = new JButton("注册");
jButton2 = new JButton("取消");
jButton1.addMouseListener(this);
jLabel1.setFont(new Font("宋体",Font.PLAIN ,12));
jLabel2.setFont(new Font("宋体",Font.PLAIN ,12));
jTextField1.setFont(new Font("宋体",Font.PLAIN ,12));
jLabel3.setFont(new Font("宋体",Font.PLAIN ,12));
jPasswordField1.setFont(new Font("宋体",Font.PLAIN ,12));
jButton1.setFont(new Font("宋体",Font.PLAIN ,12));
jButton2.setFont(new Font("宋体",Font.PLAIN ,12));
jButton2.setForeground(Color.blue);
jLabel1.setBounds(60, 10, 50, 25);
jLabel2.setBounds(60, 50, 50, 25);
jTextField1.setBounds(100, 50, 120, 20);
jLabel3.setBounds(60, 90, 50, 25);
jPasswordField1.setBounds(100, 90, 120, 20);
jButton1.setBounds(80, 150, 60, 25);
jButton2.setBounds(150, 150, 60, 25);
con.add(jLabel1);
con.add(jLabel2);
con.add(jTextField1);
con.add(jLabel3);
con.add(jPasswordField1);
con.add(jButton1);
con.add(jButton2);
}
public static void main(String[] args)
{
Output_GUI iO_GUI = new Output_GUI();
iO_GUI.setVisible(true);
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==jButton1)
{
Map map = new HashMap();
map.put(jTextField1.getText(),jPasswordField1.getText());
FileOutputStream outFileStream = null;
ObjectOutputStream out = null;
try
{
outFileStream = new FileOutputStream("abc.txt");
out = new ObjectOutputStream(outFileStream);
out.writeObject(map);
}
catch (FileNotFoundException e3)
{
e3.printStackTrace();
}
catch (IOException e2)
{
e2.printStackTrace();
}
finally
{
try
{
out.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
JOptionPane.showMessageDialog(this, "注册成功");
}
else if (e.getSource()==jButton2)
{
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
}
刚刚写的,望采纳,谢谢楼主!