不通过Java与数据库连接,实现学生信息管理系统

梅梅没梅 2013-12-16 08:35:43
这段代码我想实现学生记录的修改和删除,可是里面实现部分实在是乱得写不出来,能不能请会的朋友帮忙指点一下?下面是我目前写好的代码!if部分不会写了!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;

public class StudentManagement implements ActionListener {
JFrame frame ;
ButtonGroup bg_sex;
JRadioButton rb_man,rb_woman;
JLabel lab_name,lab_sex,lab_number,lab_subject;
JTextField tf_name,tf_number,tf_subject;
JButton b_save,b_edit,b_delete,b_select;
StringBuffer StudentInformation;
String sex;
String record ="";
String special;
public static void main(String[] args) {
StudentManagement sm = new StudentManagement();
sm.go();

}
public void go(){
frame = new JFrame("学生信息管理系统");

lab_name = new JLabel("姓名:");//设置姓名的面板;
tf_name = new JTextField(10);
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
p1.add(lab_name);
p1.add(tf_name);

lab_sex=new JLabel("性 别:");//设置性别的面板;
bg_sex = new ButtonGroup();
rb_man = new JRadioButton("男",true);
rb_woman = new JRadioButton("女");
bg_sex.add(rb_man);
bg_sex.add(rb_woman);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
p2.add(lab_sex);
p2.add(rb_man);
p2.add(rb_woman);

lab_number = new JLabel("学号:");//设置学号的面板;
tf_number = new JTextField(15);
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
p3.add(lab_number);
p3.add(tf_number);

lab_subject = new JLabel("专业班级:");//设置专业班级的面板;
tf_subject = new JTextField(15);
JPanel p4 = new JPanel();
p4.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
p4.add(lab_subject);
p4.add(tf_subject);

JPanel p5 = new JPanel();//将各面板加入P5面板中设置在frame的center;
p5.setLayout(new GridLayout(0,1));
p5.add(p1);
p5.add(p2);
p5.add(p3);
p5.add(p4);
Border etched = BorderFactory.createEtchedBorder();
Border border = BorderFactory.createTitledBorder(etched,"学生信息管理系统");
p5.setBorder(border);
frame.getContentPane().add(p5,BorderLayout.CENTER);

b_save = new JButton("保存");//设置按钮;
b_save.setActionCommand("保存");
b_save.addActionListener(this);

b_edit = new JButton("修改");
b_edit.setActionCommand("修改");
b_edit.addActionListener(this);

b_delete = new JButton("删除");
b_delete.setActionCommand("删除");
b_delete.addActionListener(this);

b_select = new JButton("查询");
b_select.setActionCommand("查询");
b_select.addActionListener(this);


JPanel p6 = new JPanel();//按钮加入P6面板设置在frame的south;
p6.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
p6.add(b_save);
p6.add(b_edit);
p6.add(b_delete);
p6.add(b_select);
frame.getContentPane().add(p6,BorderLayout.SOUTH);


frame.setSize(400,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(200,200);
frame.setVisible(true);
}

public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="保存"){//保存信息入myFile.txt;
if(rb_woman.isSelected()){
sex =new String("女");
}
else{
sex =new String("男");
}
try{
record = "姓名:" + tf_name.getText() + "\t" + "性别:" + sex + "\t" + "学号:" + tf_number.getText() + "\t" + "专业班级:" + tf_subject.getText() + "\t"+"\n";
FileWriter out = new FileWriter(new File("myFile.txt"),true);
out.write(record);
out.close();
JOptionPane.showMessageDialog(null,"保存成功","保存",JOptionPane.PLAIN_MESSAGE);
}catch( IOException ee){
ee.printStackTrace();//错误
}
}

else if(e.getActionCommand()== "修改" ){//修改信息;

JOptionPane.showMessageDialog(frame,"请输入您要修改的姓名:","修改",JOptionPane.PLAIN_MESSAGE);
try{
FileReader in1 = new FileReader("myFile.txt");
BufferedReader reader1 = new BufferedReader(in1);
String s1;
s1 = reader1.readLine();//从myFile文件读出内容赋值给s;
String s2;
s2 = tf_name.getText();
boolean b1 = s1.contains(s2);
if(b1 == true){//判断s中是否包含tf-name.getText(),即用户输入的名字;


}


}catch(IOException e2){
e2.printStackTrace();
}
}
else if(e.getActionCommand()== "删除" ){
JOptionPane.showMessageDialog(frame,"请输入您要删除的姓名:","删除",JOptionPane.PLAIN_MESSAGE);
try{
FileReader in2 = new FileReader("myFile.txt");
BufferedReader reader2 = new BufferedReader(in2);
String s3;
s3 = reader2.readLine();//从myFile文件读出内容赋值给s;
String s4;
s4 = tf_name.getText();
boolean b2 = s3.contains(s4);
if(b2 == true){//判断s中是否包含tf-name.getText(),即用户输入的名字;

}

}catch(IOException e2){
e2.printStackTrace();
}
}
else if(e.getActionCommand()== "查询" ){
JOptionPane.showMessageDialog(frame,"请输入您要查询的姓名:","查询",JOptionPane.PLAIN_MESSAGE);
try{
FileReader in3 = new FileReader("myFile.txt");
BufferedReader reader3 = new BufferedReader(in3);
String s5;
s5 = reader3.readLine();//从myFile文件读出内容赋值给s;
String s6;
s6 = tf_name.getText();
boolean b3 = s5.contains(s6);
if(b3 == true){//判断s中是否包含tf-name.getText(),即用户输入的名字;
}

}catch(IOException e2){
e2.printStackTrace();
}
}
else{

}
}




}


...全文
243 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,533

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧