我是一个小菜鸟.嘻嘻package suanFa;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class firstProblem extends JFrame {
JTextField jt;
JPasswordField jw,jw1;
Font fw=new Font("",Font.BOLD,20);
public firstProblem() {
setTitle("注册窗口");
setBounds(500,100,607,469);
setLayout(null);
setDefaultCloseOperation(2);
setIconImage(new ImageIcon("image\\icon.png").getImage());
JLabel jl1=new JLabel(new ImageIcon("image/zhuce.png"));
jl1.setBounds(0,0,607,180);
add(jl1);
JPanel jp1=new JPanel();
JLabel jl=new JLabel(" 用 户 名: ");
jl.setFont(fw);
jl.setBounds(130,195,120,35);
add(jl);
jt=new JTextField();
jt.setBounds(230,195,200,35);
add(jt);
JLabel jl2=new JLabel("密 码:");
jl2.setFont(fw);
jl2.setBounds(130,245,120,35);
add(jl2);
jw=new JPasswordField();
jw.setBounds(230,245,200,35);
add(jw);
JLabel jl3=new JLabel("确认密码:");
jl3.setFont(fw);
jl3.setBounds(130,295,120,25);
add(jl3);
jw1=new JPasswordField();
jw1.setBounds(230,295,200,35);
add(jw1);
JButton ju=new JButton("提交");
ju.setBounds(180,370,80,30);
ju.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String buttonname=e.getActionCommand();
if(buttonname.equals("提交")) {
String str=jw.getText();
String str1=jw1.getText();
if(str.equals(str1)) {
String str2=jt.getText()+","+str;
File f=new File("file/gy.txt");
//File f=new File("c:/info.txt");
try {
if(!f.exists()) {
f.createNewFile();
}
FileWriter hu=new FileWriter(f,true);
BufferedWriter buff=new BufferedWriter(hu);
buff.write(str2);
buff.newLine();
buff.flush();
buff.close();
JOptionPane.showMessageDialog(null, "写入成功");
dispose();
new firstProblem().setVisible(true);
}catch(Exception e1) {
e1.printStackTrace();
}
}
else {
JOptionPane.showMessageDialog(null, "两次密码不相同,请重新输入密码");
jw.setText("");
jw1.setText("");
}
}
// dispose();
// new Test().setVisible(true);
}
});
add(ju);
JButton ju1=new JButton("取消");
ju1.setBounds(300,370,80,30);
ju1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
jt.setText("");
jw.setText("");
jw1.setText("");
}
});
add(ju1);
}
}