团队合作的部分程序,求论坛中的高人继续下面的程序
import
import
import
import
import
import
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class A extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private JButton b1;
private JButton b2 ;
private JButton b3 ;
private JButton b4 ;
static JTextField f1;
private JPasswordField f2;
public A() throws IOException{
super("登陆系统");
setLayout(new GridLayout(4, 2,8,8));
JLabel l1 = new JLabel("学(工)号:");
f1= new JTextField(12);
JLabel l2 = new JLabel("密码:");
f2=new JPasswordField(16);
b1 = new JButton("学生登录");
b2 = new JButton("老师登录");
b3 = new JButton("退出");
b4 = new JButton("学生注册");
add(l1);
add(f1);
add(l2);
add(f2);
add(b1);
add(b2);
add(b4);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
setBounds(300,300,360,240);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
File file2=new File("D:\\myfolder");
file2.mkdir();
File file9=new File("D:\\myfolder\\teacher.txt");
file9.createNewFile();
File file23=new File("D:\\myfolder\\teacherdenglu.txt");
file23.createNewFile();
File file20=new File("D:\\myfolder\\studentname.txt");
file20.createNewFile();
File file11=new File("D:\\myfolder\\studentscore.txt");
file11.createNewFile();
File file8=new File("D:\\myfolder\\yixuancourse.txt");
file8.createNewFile();
File file10=new File("D:\\myfolder\\student.txt");
file10.createNewFile();
FileWriter file12=new FileWriter("D:\\myfolder\\teacher.txt",true);
BufferedWriter bf5=new BufferedWriter(file12);
try{
FileReader file1=new FileReader("D:\\myfolder\\teacher.txt");
BufferedReader bf=new BufferedReader(file1);
String s4 = bf.readLine();
int flag=0;
while(s4!=null)
{
if(s4.indexOf("老师:张老师
工号:001") != -1)
flag=1;
s4=bf.readLine();
}
if(flag==0)
bf5.write("老师:张老师
工号:001");
bf5.newLine();
bf5.close();
FileReader file15=new FileReader("D:\\myfolder\\student.txt");
BufferedReader bfg=new BufferedReader(file15);
String s5 = bfg.readLine();
int flag1=0;
while(s5!=null)
{
if(s5.indexOf("学号:001
密码:123456") != -1)
flag1=1;
s5=bfg.readLine();
}
if(flag1==0)
try{
FileWriter file16=new FileWriter("D:\\myfolder\\student.txt");
BufferedWriter bf6=new BufferedWriter(file16);
bf6.write("姓名:小王
学号:001
密码:123456"+"\r\n"+"姓名:小明
学号:002
密码:123456"+"\r\n"+"姓名:小张
学号:003
密码:123456");
bf6.close();
}catch (IOException e1) { e1.printStackTrace(); }
FileWriter file24=new FileWriter("D:\\myfolder\\teacherdenglu.txt");
BufferedWriter bf11=new BufferedWriter(file24);
FileReader file25=new FileReader("D:\\myfolder\\teacherdenglu.txt");
BufferedReader bfa=new BufferedReader(file25);
String s9 = bfg.readLine();
int flag3=0;
while(s9!=null)
{
if(s9.indexOf("姓名:张老师
学号:001
密码:123456") != -1)
flag3=1;
s9=bfa.readLine();
}
if(flag3==0)
bf11.write("姓名:张老师
学号:001
密码:123456");
bf11.newLine();
bf11.close();
FileReader file22=new FileReader("D:\\myfolder\\studentname.txt");
BufferedReader bfgg=new BufferedReader(file22);
String s8 = bfgg.readLine();
int flag2=0;
while(s8!=null)
{
if(s8.indexOf("学生:小王
学号:001") != -1)
flag2=1;
s8=bfgg.readLine();
}
if(flag2==0)
try{
FileWriter file21=new FileWriter("D:\\myfolder\\studentname.txt");
BufferedWriter bf10=new BufferedWriter(file21);
bf10.write("学生:小王
学号:001"+"\r\n"+"学生:小明
学号:002"+"\r\n"+"学生:小张
学号:003");
bf10.close();
}catch (IOException e1) { e1.printStackTrace(); }
}catch (IOException e1) { e1.printStackTrace(); }
}
public void actionPerformed(ActionEvent e)
{
if( e.getSource()==b1)
{
try {
FileReader ff = new FileReader("D:\\myfolder\\student.txt");
BufferedReader bf=new BufferedReader(ff);
String s = bf.readLine();
int flag=0;
while(s!=null)
{
if(s.indexOf(f1.getText().trim()) != -1
&&s.indexOf(new String(f2.getPassword()))!= -1 )
flag=1;
s=bf.readLine();
}bf.close();
if(f1.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"\t请输入用户名!","用户名空提示",JOptionPane.OK_OPTION);
}
else if(new String(f2.getPassword()).equals("")){
JOptionPane.showMessageDialog(null,"\t请输入密码!","密码空提示",JOptionPane.OK_OPTION);}
else if(flag==1)
{
student a=new student();//进入学生选课界面
a.student();
dispose();
}
else if(flag==0){
JOptionPane.showMessageDialog(null,"\t用户名或密码错误,请重新输入!","提示",JOptionPane.OK_OPTION);}
}catch (IOException e1) { e1.printStackTrace(); }
}
else if( e.getSource()==b2)
{
try {
FileReader ff = new FileReader("D:\\myfolder\\teacherdenglu.txt");
BufferedReader bf=new BufferedReader(ff);
String s = bf.readLine();
int flag=0;
while(s!=null)
{
if(s.indexOf(f1.getText().trim()) != -1
&&s.indexOf(new String(f2.getPassword())) != -1 )
flag=1;
s=bf.readLine();
break;
}
if(f1.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"\t请输入用户名!","用户名空提示",JOptionPane.OK_OPTION);
}
else if(new String(f2.getPassword()).equals("")){
JOptionPane.showMessageDialog(null,"\t请输入密码!","密码空提示",JOptionPane.OK_OPTION);}
else if(flag==1)
{
teacher a=new teacher();//进入老师界面
a.teacher();
dispose();
}
else{
JOptionPane.showMessageDialog(null,"\t用户名或密码错误,请重新输入!","提示",JOptionPane.OK_OPTION);}
}catch (IOException e1) { e1.printStackTrace(); }
}
else if(e.getSource()==b3)
{
System.exit(0);
}
else if(e.getSource()==b4)
{
final JFrame d=new JFrame("学生注册");
d.setLayout(new GridLayout(5, 2,8,8));
JButton bb1=new JButton("确定");
JButton bb2=new JButton("取消");
final JTextField ff1=new
JTextField(12);
final JTextField ff2=new
JTextField(12);
final JPasswordField ff3=new
JPasswordField(12);
final JPasswordField ff4=new
JPasswordField(12);
JLabel l1 = new JLabel("请输入姓名:");
JLabel l2 = new JLabel("请输入学号:");
JLabel l3 = new JLabel("请输入登陆密码:");
JLabel l4 = new JLabel("请输入登陆密码:");
d.add(l1);
d.add(ff1);
d.add(l2);
d.add(ff2);
d.add(l3);
d.add(ff3);
d.add(l4);
d.add(ff4);
d.add(bb1);
d.add(bb2);
bb1.addActionListener(new ActionListener(){//内部类
public void actionPerformed(final ActionEvent e){
int flag=0;
try{
FileReader file1=new FileReader("D:\\myfolder\\student.txt");
BufferedReader bf=new BufferedReader(file1);
String s4 = bf.readLine();
while(s4!=null)
{
if(s4.indexOf(ff2.getText())!= -1)
flag=1;
s4=bf.readLine();
break;
}
}catch (IOException e1) { e1.printStackTrace();}
if(flag==0)
{
if((new String(ff3.getPassword())).equals(new String(ff4.getPassword())))
{
try{
FileWriter file1=new FileWriter("D:\\myfolder\\studentname.txt",true);
BufferedWriter bf=new BufferedWriter(file1);
bf.write("姓名:"+ff1.getText()+"
学号:"+ff2.getText());
bf.newLine();
bf.close();
FileWriter file2=new FileWriter("D:\\myfolder\\student.txt",true);
BufferedWriter bff=new BufferedWriter(file2);
bff.write("姓名:"+ff1.getText()+"
学号:"+ff2.getText()+"密码:"+new String(ff3.getPassword()));
bff.newLine();
bff.close();
JOptionPane.showMessageDialog(null, "注册成功", "提示", JOptionPane.ERROR_MESSAGE);
d.dispose();
}catch (IOException e1) { e1.printStackTrace();}
}
else
{
JOptionPane.showMessageDialog(null, "您两次输入的密码不一致,请重新输入", "提示",
JOptionPane.ERROR_MESSAGE);
}
}
else if(flag==1)
{
JOptionPane.showMessageDialog(null, "这个账号已经注册过了,请重新注册", "提示",
JOptionPane.ERROR_MESSAGE);
}
}});
bb2.addActionListener(new ActionListener(){//内部类
public void actionPerformed(final ActionEvent e){
d.dispose();
}});
d.setBounds(300,300,360,240);
d.dispose();
d.setVisible(true);
}
}
public static void main(String[] args) throws IOException
{
new A();
}
}