求一个JAVA的学生成绩管理系统,能直接用eclipse导入的最好了
发布网友
发布时间:2022-04-26 00:04
我来回答
共2个回答
热心网友
时间:2023-10-20 10:23
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
/*class Stu implements java.io.Serializable{
String number,name,specialty,grade,borth,sex;
public Stu(){};
public void setNumber(String number){ this.number=number;}
public String getNumber(){ return number;}
public void setName(String name){ this.name=name;}
public String getName(){ return name;}
public void setSex(String sex){ this.sex=sex;}
public String getSex(){ return sex;}
public void setSpecialty(String specialty){ this.specialty=specialty;}
public String getSpecialty(){ return specialty;}
public void setGrade(String grade){ this.grade=grade;}
public String getGrade(){ return grade;}
public void setBorth(String borth){ this.borth=borth;}
public String getBorth(){ return borth;}
}*/
public class asdd extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setTitle("信息管理系统");
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container container = frame.getContentPane();
container.setLayout(new FlowLayout());
JLabel lb=new JLabel("录入请先输入记录,查询、删除请先输入学号,修改是对查询" +
"内容改后的保存!");
JTextField 学号,姓名,专业,年级,出生;
JRadioButton 男,女;
ButtonGroup group=null;
JButton 录入,查询,删除,修改,显示;
JPanel p1,p2,p3,p4,p5,p6,pv,ph;
学号=new JTextField(10);
姓名=new JTextField(10);
专业=new JTextField(10);
年级=new JTextField(10);
出生=new JTextField(10);
group=new ButtonGroup();
男=new JRadioButton("男");
女=new JRadioButton("女");
group.add(男);
group.add(女);
录入=new JButton("录入");
查询=new JButton("查询");
删除=new JButton("删除");
修改=new JButton("修改");
显示=new JButton("显示");
修改.setEnabled(false);
//添加输入框及文本框
p1=new JPanel();
p1.add(new JLabel("学号:",JLabel.CENTER));
p1.add(学号);
p2=new JPanel();
p2.add(new JLabel("姓名:",JLabel.CENTER));
p2.add(姓名);
p3=new JPanel();
p3.add(new JLabel("性别:",JLabel.CENTER));
p3.add(男);
p3.add(女);
p4=new JPanel();
p4.add(new JLabel("专业:",JLabel.CENTER));
p4.add(专业);
p5=new JPanel();
p5.add(new JLabel("年级:",JLabel.CENTER));
p5.add(年级);
p6=new JPanel();
p6.add(new JLabel("出生:",JLabel.CENTER));
p6.add(出生);
pv=new JPanel();
pv.setLayout(new GridLayout(6,1));
pv.add(p1);
pv.add(p2);
pv.add(p3);
pv.add(p4);
pv.add(p5);
pv.add(p6);
ph=new JPanel();
ph.add(录入);
ph.add(查询);
ph.add(修改);
ph.add(删除);
ph.add(显示);
frame.add(lb);
frame.add(ph);
frame.add(p1);
frame.add(p2);
frame.add(p3);
frame.add(p4);
frame.add(p5);
frame.add(p6);
frame.add(pv);
frame.add(ph);
class MyListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
//判断选中是男是女
/*if(e.getSource().equals(男)){
if(男.isSelected()) {
System.out.println("男被选中了");
} else {
System.out.println("男被取消选中了");
}
}
if(e.getSource().equals(女)){
if(女.isSelected()) {
System.out.println("女被选中了");
} else {
System.out.println("女被取消选中了");
}
}*/
//录入 的功能
if(e.getActionCommand() == "录入") {
String text1 = 学号.getText().trim();
String text2 = 姓名.getText();
String text3 = 专业.getText();
String text4 = 年级.getText();
String text5 = 出生.getText();
String text6 = null;
String text7 = "- - - - -我是分割线 - - - - -";
if(男.isSelected()) {
text6 = "男";
}
if(女.isSelected()) {
text6 = "女";
}
try {
File file = new File("D:/file.txt");
if(!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file,true);
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.write(text1 + "\n");
writer.write(text2 + "\n");
writer.write(text6 + "\n");
writer.write(text3 + "\n");
writer.write(text4 + "\n");
writer.write(text5 + "\n");
writer.write(text7 + "\n");
writer.close();
} catch (Exception e1) {
e1.printStackTrace();
}
System.out.println("学号: " + text1 + "\n" + "姓名: "
+ " " + text2 + "\n" + "性别: " + text6 + "\n专业: " + text3 + "\n" + "年级: " + text4 + "\n" + "出生: " + text5 + "\n" + text7);
}
//显示 的功能
if(e.getActionCommand() == "显示") {
try {
File file = new File("D:/file.txt");
InputStreamReader reader = new InputStreamReader(
new FileInputStream(file));//创建一个输入流对象
BufferedReader bufferReader = new BufferedReader(reader);
String line = "";
line = bufferReader.readLine();
while(line != null) {
line = line ;
System.out.println(line);
line = bufferReader.readLine();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
//查询 的功能
if(e.getActionCommand() == "查询") {
File file = new File("D:/file.txt");
BufferedReader reader = null;
String text7 = "- - - - -我是分割线 - - - - -";
try {
//InputStreamReader reader = new InputStreamReader(
//new FileInputStream(file));//创建一个输入流对象
reader = new BufferedReader(new FileReader(file));
//暂时仅允许查询学号
String text1 = 学号.getText();
String line = null;
//int cout = 2;
while((line = reader.readLine())!= null) {
if(line.equals(text1)) {
System.out.println(line);
while(!line.equals("text7")){
line = reader.readLine();
System.out.println(line);
}
}
//cout++;
} reader.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if(reader != null) {
try {
reader.close();
}catch (IOException e1){
}
}
}
}
}
}
//注册监听
MyListener listener = new MyListener();
MyListener listen = new MyListener();
显示.addActionListener(listener);
录入.addActionListener(listener);
查询.addActionListener(listener);
男.addActionListener(listen);
女.addActionListener(listen);
frame.setVisible(true);
}
}
热心网友
时间:2023-10-20 10:23
可以写的 来 写吗