java信息管理_java成绩信息管理
展開全部
import?java.awt.*;
import?javax.swing.*;
import?java.awt.event.ActionListener;
import?java.awt.event.ActionEvent;
import?java.io.*;
//score文件在d盤下
public?class?MinimalElements?{
private?static?JTextField?textField;
private?static?JTextField?textField_1;
private?static?JTextField?textField_2;
public?static?void?main(String[]?args){
try{
File?file=new?File("D://score.txt");
file.createNewFile();
}catch(IOException?eq){eq.printStackTrace();}
Stack?s=new?Stack();
finalJFrame?jf=new?JFrame();
32313133353236313431303231363533e58685e5aeb931333337393634jf.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
jf.setLocation(new?Point(300,?200));
jf.setSize(new?Dimension(450,?300));
jf.setVisible(true);
jf.setFont(new?Font("Dialog",?Font.PLAIN,?12));
jf.getContentPane().setBackground(new?Color(30,?144,?255));
jf.setTitle("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF");
jf.setForeground(Color.BLUE);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setBackground(Color.BLUE);
jf.getContentPane().setLayout(null);
JLabel?lblNewLabel?=?new?JLabel("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF?");
lblNewLabel.setFont(new?Font("方正蘭亭超細黑簡體",?Font.BOLD,?16));
lblNewLabel.setToolTipText("");
lblNewLabel.setBounds(140,?10,?169,?23);
jf.getContentPane().add(lblNewLabel);
JLabel?lblNewLabel_1?=?new?JLabel("\u59D3\u540D");
lblNewLabel_1.setBounds(62,?58,?54,?15);
jf.getContentPane().add(lblNewLabel_1);
JLabel?lblNewLabel_2?=?new?JLabel("\u6570\u5B66");
lblNewLabel_2.setBounds(62,?128,?54,?15);
jf.getContentPane().add(lblNewLabel_2);
JLabel?label?=?new?JLabel("\u8BED\u6587");
label.setBounds(62,?92,?54,?15);
jf.getContentPane().add(label);
textField?=?new?JTextField();
textField.setBounds(124,?55,?204,?21);
jf.getContentPane().add(textField);
textField.setColumns(10);
textField_1?=?new?JTextField();
textField_1.setBounds(124,?89,?204,?21);
jf.getContentPane().add(textField_1);
textField_1.setColumns(10);
textField_2?=?new?JTextField();
textField_2.setBounds(124,?125,?204,?21);
jf.getContentPane().add(textField_2);
textField_2.setColumns(10);
JButton?btnNewButton?=?new?JButton("\u6DFB\u52A0");
btnNewButton.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{//添加
String?name=textField.getText();
String?yuwen=textField_1.getText();
String?math=textField_2.getText();
if((!(name.equals("")&&yuwen.equals("")&&math.equals("")))
&&(Integer.valueOf(yuwen)<=100&&Integer.valueOf(math)<=100)&&Integer.valueOf(yuwen)>=0&&Integer.valueOf(math)>=0){
try?{int?num=0,i=0;
BufferedReader?br=new?BufferedReader(new?FileReader("D://score.txt"));
while(br.readLine()!=null){num+=1;}br.close();
br=new?BufferedReader(new?FileReader("D://score.txt"));
String?all[]=new?String[num];
String?buffer="";
while((buffer=br.readLine())!=null){
all[i]=buffer;
i+=1;
}
br.close();
BufferedWriter?bw=new?BufferedWriter(new?FileWriter("D://score.txt"));
for(int?j=0;j
bw.write(all[j]);
bw.newLine();
}
bw.write(name+";"+yuwen+";"+math);
bw.close();
JOptionPane.showConfirmDialog(null,?"寫入成功",?"寫入成功!",?JOptionPane.CLOSED_OPTION);
}?catch?(IOException?e1)?{
e1.printStackTrace();
}
}
else{
JOptionPane.showMessageDialog(null,?"信息輸入不完整,等待完善",?"信息輸入不完整,等待完善",?JOptionPane.ERROR_MESSAGE);
}
}
});
btnNewButton.setBounds(62,?181,?93,?23);
jf.getContentPane().add(btnNewButton);
JButton?btnNewButton_1?=?new?JButton("\u4E0B\u4E00\u4E2A");
btnNewButton_1.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?arg0)?{
BufferedReader?br=null;
try?{
br=new?BufferedReader(new?FileReader("D://score.txt"));
while(br.readLine()!=null){s.ln+=1;}br.close();
br=new?BufferedReader(new?FileReader("D://score.txt"));
int?sl=s.line+=1;
if(sl>=s.ln){s.line=0;}
String?infor="";
for(int?i=0;i
infor=br.readLine();
}
int?ii=infor.indexOf(";");
String?name=infor.substring(0,?ii);
int?li=infor.lastIndexOf(";");
String?yuwen=infor.substring(ii+1,?li);
String?math=infor.substring(li+1,?infor.length());
textField.setText(name);
textField_1.setText(yuwen);
textField_2.setText(math);
br.close();
s.ln=0;
}?catch?(FileNotFoundException?e)?{
e.printStackTrace();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
});
btnNewButton_1.setBounds(185,?181,?93,?23);
jf.getContentPane().add(btnNewButton_1);
JButton?button?=?new?JButton("\u91CD\u7F6E");
button.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?arg0)?{
textField.setText("");
textField_1.setText("");
textField_2.setText("");
}
});
button.setBounds(300,?181,?93,?23);
jf.getContentPane().add(button);
jf.setSize(jf.getWidth()+1,?jf.getHeight()+1);
}
}
class?Stack{
int?line=0;
int?ln=0;
}
總結
以上是生活随笔為你收集整理的java信息管理_java成绩信息管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DIY客制化键盘
- 下一篇: KsWEB以及Termux使用,把项目部