📄 example_2.java
字号:
}
else {
JOptionPane.showMessageDialog(fam, "该学生分数不足,未录取");
}
}
//保存文件函数
void Save(){
filedialog_save.setVisible(true);
int state = filedialog_save.getMode();
if(state==FileDialog.SAVE){
File f = new File(filedialog_save.getDirectory(),filedialog_save.getFile());
try {
ObjectOutputStream bw = new ObjectOutputStream(new FileOutputStream(f));
for(int i=0;i<v.size();i++){
bw.writeObject(v.get(i));
}
bw.close();
}catch(FileNotFoundException e1){
e1.printStackTrace();
} catch(IOException e1){
e1.printStackTrace();
}
}
}
//打开文件函数
void Load(){
v.removeAllElements();
filedialog_load.setVisible(true);
int state = filedialog_load.getMode();
if(state==FileDialog.LOAD){
File f = new File(filedialog_load.getDirectory(),filedialog_load.getFile());
try {
ObjectInputStream in= new ObjectInputStream(new FileInputStream(f));
v.addElement(in.readObject());
in.close();
}catch(FileNotFoundException e1){}
catch(IOException e1){}
catch (ClassNotFoundException e1) {}
}
this.ShowValue();
}
//为显示信息的表格填值
void ShowValue(){
for(int i=0;i<v.size();i++)
{
a[i][0]=((Student)v.get(i)).GetName();
a[i][1]=((Student)v.get(i)).GetID();
a[i][2]=String.valueOf(((Student)v.get(i)).GethomeAddress());
a[i][3]=String.valueOf(((Student)v.get(i)).GettelNum());
}
jlb.setText("共录取了学生 "+ v.size()+"名");
dlg.setSize(350,300);
dlg.setVisible(true);
}
//实现监听的函数
public void actionPerformed(ActionEvent e){
//监听统计按扭
if(e.getSource()==item_statist||e.getSource()==btn_statist)ShowValue();
//监听保存按扭
else if(e.getSource()==Fitem_exit){//添加保存信息
System.exit(0);
}
//监听录取按扭
else if(e.getSource()==item_receave||e.getSource()==btn_receave){
if(name.getText().equals("")||id.getText().equals(""))
{
JOptionPane.showMessageDialog(fam, "学号或姓名不能为空!");
return;
}
JudgeReceave(two);
}
//监听帮助中的关于按扭
else if(e.getSource()==item_about){
JOptionPane.showMessageDialog(fam, "作者:杨伟明"+"\n"+"时间:2007年5月6日"+"\n"+
"版本号: version 3.8"+"\n"+"God is in his heaven."+"\n"+"All's Right with the world.");
}
//监听录取线选项
else if(e.getSource()==item_setScore){fam_luqu.setVisible(true);}
//监听设置录取线
else if(e.getSource()==btn_luqu){
// lb_luqu.setText("当前录取分数线为:"+one.GetScoreLine());
try{
if(Double.parseDouble(tf_luqu.getText())<0||Double.parseDouble(tf_luqu.getText())>750)
{
JOptionPane.showMessageDialog(fam, "录取分数已经超出范围");
lb_luqu.setText("当前录取分数线为:"+one.GetScoreLine());
fam_luqu.setVisible(false);
return;
}
if(tf_luqu.getText().equals("")){fam_luqu.setVisible(false);return;}
else
one.SetScoreLine(Double.parseDouble(tf_luqu.getText()));
fam_luqu.setVisible(false);
}catch(Exception e1){
fam_luqu.setVisible(false);
lb_luqu.setText("当前录取分数线为:"+one.GetScoreLine());
}
}
//监听查找选项
else if(e.getSource()==item_find){
fam_cha.setVisible(true);
}
//监听查找按扭
else if(e.getSource()==btn_cha){
area.setText("");
for(int i=0;i<v.size();i++){
if(tf_chaname.getText().equals(((Student)v.get(i)).GetName())||tf_chaid.getText().equals(((Student)v.get(i)).GetID())){
area.append("学号:"+((Student)v.get(i)).GetID()+"\t"+"姓名:"+((Student)v.get(i)).GetName()+"\t"+
"综合成绩:"+((Student)v.get(i)).GethomeAddress()+"\t"+"体育成绩:"+((Student)v.get(i)).GettelNum()+"\n");
}
}
dlg_1.setVisible(true);
}
//监听保存选项
else if(e.getSource()==item_save)Save();
//监听打开选项
else if(e.getSource()==item_open)Load();
}
//处理TEXTFIELD中的一些相关信息
public void textValueChanged(TextEvent e){
if(e.getSource()==name){
name.setSelectionEnd(name.getText().length());
two.SetName(name.getText());
}
//监听录取分数
else if(e.getSource()==tf_luqu){
lb_luqu.setText("当前录取分数线为:"+tf_luqu.getText());
}
else if(e.getSource()==id){
id.setSelectionEnd(id.getText().length());
two.SetId(id.getText());
}
else if(e.getSource()==homeAddress){
try{
j_1=Double.parseDouble(homeAddress.getText());
}catch(Exception liwai){
j_1=0.0;
}
if(j_1>750){
JOptionPane.showMessageDialog(fam, "总分不能超过750分");
homeAddress.setText("");
j_1=0.0;
return;
}
two.SethomeAddress(j_1);
}
else if(e.getSource()==telNum){
try{
j_2=Double.parseDouble(telNum.getText());
}catch(Exception liwai){
j_2=0.0;
}
if(Double.parseDouble(telNum.getText())>100){
JOptionPane.showMessageDialog(fam, "体育分数不能超过100分");
telNum.setText("");
j_2=0.0;
return;
}
two.SettelNum(j_2);
}
}
public static void main(String args[]){
Example_2 Win= new Example_2();
}
}
//学校类
class School{
static double scoreLine=400;
void SetScoreLine(double sl){
scoreLine=sl;
}
static double GetScoreLine(){
return scoreLine;
}
}
//学生类
class Student implements Serializable {
private String name="";
private String id="";
private double homeAddress,telNum;
Student(String Sna,String Sid,double ShomeAddress,double StelNum){
name=Sna;
id=Sid;
homeAddress=ShomeAddress;
telNum=StelNum;
}
public void SetName(String Sna){
name=Sna;
}
public void SetId(String Sid){
id=Sid;
}
public void SethomeAddress(double ShomeAddress){
homeAddress=ShomeAddress;
}
public void SettelNum(double StelNum){
telNum=StelNum;
}
public String GetName(){
return name;
}
public String GetID(){
return id;
}
public double GethomeAddress(){
return homeAddress;
}
public double GettelNum(){
return telNum;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -