?? student.java~257~
字號(hào):
raf.writeUTF(Integer.toString(
((setStudent)NewSetStudent.elementAt(i)).getIndex()));
raf.writeUTF("\n");
}
informationChange=false;
raf.seek(0) ;
raf.close() ;
}
catch(IOException io)
{
System.err .println(io.toString());
}
}
else
if(e.getActionCommand()=="打開(kāi)")
{
fd=new FileDialog(this ,"打開(kāi)文件",FileDialog.LOAD );
fd.setDirectory("C:\\Documents and Settings\\zhlab\\桌面");
fd.show();
try
{
File studentFile=new File(fd.getDirectory(),fd.getFile());
RandomAccessFile raf=new RandomAccessFile(studentFile,"rw");
int t=0;
String[] strr=new String[8];
float[] f=new float[7];
float[] f1={0,0,0,0,0,0};
while(raf.getFilePointer() <raf.length() )
{
if(t==0)
ta.setText(raf.readUTF());
NewSetStudent.addElement(
new setStudent("null","null" ,"null", "null" ,fl));
((setStudent)NewSetStudent.elementAt(t)).setName(raf.readUTF());
raf.readUTF();
((setStudent)NewSetStudent.elementAt(t)).setNumber(raf.readUTF());
raf.readUTF();
((setStudent)NewSetStudent.elementAt(t)).setToclass(raf.readUTF());
raf.readUTF();
((setStudent)NewSetStudent.elementAt(t)).setSex(raf.readUTF());
raf.readUTF();
for(int k=0;k<8;k++)
{
strr[k]=raf.readUTF();
raf.readUTF();
}
for(int k=0;k<6;k++)
{
f[k]=Float.parseFloat(strr[k]) ;
}
((setStudent)NewSetStudent.elementAt(t)).setMarks(f);
((setStudent)NewSetStudent.elementAt(t)).setAverage(
Float.parseFloat(strr[6]));
((setStudent)NewSetStudent.elementAt(t)).setIndex(
Integer.parseInt(strr[7]));
t++;
}
raf.seek(0) ;
raf.close();
showInformation();
}
catch(IOException io)
{
System.err .println(io.toString());
}
}
else
if(e.getActionCommand()=="另存為")
{
fd=new FileDialog(this ,"打開(kāi)文件",FileDialog.LOAD );
fd.setDirectory("C:\\Documents and Settings\\zhlab\\桌面");
fd.show();
try
{
File studentFile=new File(fd.getDirectory(),fd.getFile());
RandomAccessFile raf=new RandomAccessFile(studentFile,"rw");
raf.writeUTF("姓名\t學(xué)號(hào)\t班級(jí)\t性別\tJava\t匯編\t計(jì)組\t英語(yǔ)"+
"\t隨機(jī)\t圖論\t均分\t名次\n") ;
for(int i=0;i<NewSetStudent.size() ;i++)
{
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getName());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getNumber());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getToclass());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getSex());
raf.writeUTF("\t");
for(int k=0;k<6;k++)
{
raf.writeUTF(Float.toString(
((setStudent)NewSetStudent.elementAt(i)).getMark(k)));
raf.writeUTF("\t");
}
raf.writeUTF(Float.toString(
((setStudent)NewSetStudent.elementAt(i)).getAverage()));
raf.writeUTF("\t");
raf.writeUTF(Integer.toString(
((setStudent)NewSetStudent.elementAt(i)).getIndex()));
raf.writeUTF("\n");
}
informationChange=false;
raf.seek(0) ;
raf.close() ;
}
catch(IOException io)
{
System.err .println(io.toString());
}
}
else
if(e.getActionCommand() =="刷新")
{
ta.setText("");
ta.setText("\t\t\t\t歡迎您的使用\n") ;
new getAveIndex();
showInformation();
}
else
if(e.getActionCommand() =="是")
{
fd=new FileDialog(this ,"打開(kāi)文件",FileDialog.LOAD );
fd.setDirectory("C:\\Documents and Settings\\zhlab\\桌面");
fd.show();
try
{
File studentFile=new File(fd.getDirectory(),fd.getFile()+".txt");
RandomAccessFile raf=new RandomAccessFile(studentFile,"rw");
raf.writeUTF("姓名\t學(xué)號(hào)\t班級(jí)\t性別\tJava\t匯編\t計(jì)組\t英語(yǔ)"+
"\t隨機(jī)\t圖論\t均分\t名次\n") ;
for(int i=0;i<NewSetStudent.size() ;i++)
{
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getName());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getNumber());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getToclass());
raf.writeUTF("\t");
raf.writeUTF(
((setStudent)NewSetStudent.elementAt(i)).getSex());
raf.writeUTF("\t");
for(int k=0;k<6;k++)
{
raf.writeUTF(Float.toString(
((setStudent)NewSetStudent.elementAt(i)).getMark(k)));
raf.writeUTF("\t");
}
raf.writeUTF(Float.toString(
((setStudent)NewSetStudent.elementAt(i)).getAverage()));
raf.writeUTF("\t");
raf.writeUTF(Integer.toString(
((setStudent)NewSetStudent.elementAt(i)).getIndex()));
raf.writeUTF("\n");
}
raf.seek(0) ;
raf.close() ;
informationChange=false;
SaveFile.dispose() ;
dispose();
System.exit(0);
}
catch(IOException io)
{
System.err .println(io.toString());
}
}
else
if(e.getActionCommand() =="否")
{
SaveFile.dispose() ;
dispose();
System.exit(0);
}
else
if(e.getActionCommand() =="取消")
{
SaveFile.dispose() ;
}
else
if(e.getSource() ==text[0])
{
new drawPictures("Java",picture_divide);
}
else
if(e.getSource() ==text[1])
{
new drawPictures("匯編",picture_divide);
}
else
if(e.getSource() ==text[2])
{
new drawPictures("計(jì)組",picture_divide);
}
else
if(e.getSource() ==text[3])
{
new drawPictures("英語(yǔ)",picture_divide);
}
else
if(e.getSource() ==text[4])
{
new drawPictures("隨機(jī)",picture_divide);
}
else
if(e.getSource() ==text[5])
{
new drawPictures("圖論",picture_divide);
}
else
if(e.getSource() ==text[6])
{
new drawPictures("均分",picture_divide);
}
else
if(e.getActionCommand() =="標(biāo)準(zhǔn)")
{
new setPicture();
getNumber();
}
else
ta.setText("\n\n\n\n\n\t\t"+"你選擇的是"+e.getActionCommand());
}
//主菜單類到此結(jié)束
//學(xué)生信息輸入窗口類開(kāi)始
class enterInformationFrame extends Frame implements ActionListener
{
Label prompt,sub1_prompt,sub2_prompt,sub3_prompt,
sub4_prompt,sub5_prompt,sub6_prompt,nameprompt,
numberprompt,classprompt,sexprompt;
TextField inputname,inputnumber,inputclass,inputsex,
input_sub1_mark,input_sub2_mark,input_sub3_mark,
input_sub4_mark,input_sub5_mark,input_sub6_mark;
Button btn1,btn2;
TextArea tea;
float[] fl={0,0,0,0,0,0};
int i=0;
enterInformationFrame()
{
super("信息輸入窗口");
tea=new TextArea(25,100);
btn1=new Button("確定");
btn2=new Button("結(jié)束");
nameprompt=new Label("姓名");
numberprompt=new Label("學(xué)號(hào)");
classprompt=new Label("班級(jí)");
sexprompt=new Label("性別");
prompt=new Label(" 請(qǐng)按操作進(jìn)行");
sub1_prompt=new Label("Java");
sub2_prompt=new Label("匯編");
sub3_prompt=new Label("計(jì)組");
sub4_prompt=new Label("英語(yǔ)");
sub5_prompt=new Label("隨機(jī)");
sub6_prompt=new Label("圖論");
inputname=new TextField(8);
inputnumber=new TextField(8);
inputclass=new TextField(8);
inputsex=new TextField(8);
input_sub1_mark=new TextField(8);
input_sub2_mark=new TextField(8);
input_sub3_mark=new TextField(8);
input_sub4_mark=new TextField(8);
input_sub5_mark=new TextField(8);
input_sub6_mark=new TextField(8);
btn1.addActionListener(this);
btn2.addActionListener(this);
setLayout(new FlowLayout());
add(nameprompt);
add(inputname);
add(numberprompt);
add(inputnumber);
add(classprompt);
add(inputclass);
add(sexprompt);
add(inputsex);
add(sub1_prompt);
add(input_sub1_mark);
add(sub2_prompt);
add(input_sub2_mark);
add(sub3_prompt);
add(input_sub3_mark);
add(sub4_prompt);
add(input_sub4_mark);
add(sub5_prompt);
add(input_sub5_mark);
add(sub6_prompt);
add(input_sub6_mark);
add(btn1);
add(btn2);
add(prompt);
add(tea);
addWindowListener(new closeWin());
tea.append("姓名\t學(xué)號(hào)\t班級(jí)\t性別\tJava\t匯編\t計(jì)組\t英語(yǔ)\t隨機(jī)\t圖論\n");
setSize(818,818);
setVisible(true);
show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
tea.append(inputname.getText()+"\t"+inputnumber.getText()+"\t");
tea.append(inputclass.getText()+"\t"+inputsex.getText()+"\t");
tea.append(input_sub1_mark.getText()+"\t"+
input_sub2_mark.getText()+"\t");
tea.append(input_sub3_mark.getText()+"\t"+
input_sub4_mark.getText()+"\t");
tea.append(input_sub5_mark.getText()+"\t"+
input_sub6_mark.getText()+"\n");
prompt.setText("已經(jīng)讀入");
fl[0]=Float.parseFloat(input_sub1_mark.getText());//這里我懷疑這種
fl[1]=Float.parseFloat(input_sub2_mark.getText());//方法.因?yàn)闀?shū)上面
fl[2]=Float.parseFloat(input_sub3_mark.getText());//寫(xiě)著對(duì)float和
fl[3]=Float.parseFloat(input_sub3_mark.getText());//double沒(méi)有這種
fl[4]=Float.parseFloat(input_sub5_mark.getText());//轉(zhuǎn)換機(jī)制.但是為什
fl[5]=Float.parseFloat(input_sub6_mark.getText());//么我在這里使用卻很
NewSetStudent.addElement( //正常呢?值得研究
new setStudent(inputname.getText(),
inputnumber.getText() ,inputclass.getText(),
inputsex.getText() ,fl));
informationChange=true;
tea.append(Integer.toString(NewSetStudent.size())+"\n") ;
inputnumber.setText("");
inputclass.setText("");
inputsex.setText("");
input_sub1_mark.setText("");
input_sub2_mark.setText("");
input_sub3_mark.setText("");
input_sub4_mark.setText("");
input_sub5_mark.setText("");
input_sub6_mark.setText("");
inputname.setText("");
}
else if(e.getSource()==btn2)
{
prompt.setText("正在讀入.");
try
{
Thread.sleep(200);
prompt.setText("已經(jīng)讀入");
Thread.sleep(200);
}
catch(InterruptedException ee){}
dispose();
}
}
}
//學(xué)生信息輸入類結(jié)束
//學(xué)生信息數(shù)據(jù)庫(kù)類開(kāi)始
class setStudent
{
float total=0,average;
// StringBuffer name,number,toClass,sex;//最好不要這么用,否則因?yàn)楹芏嗪瘮?shù)
// int[] index = new int[7]; //返回的是String類型的值于在是造成很多麻煩
int index=1; //的同時(shí)也可能會(huì)出現(xiàn)大量錯(cuò)誤
float[] mark=new float[6];
String[] subject= new String[6];
String name=new String();
String number=new String();
String toClass=new String();
String sex=new String();
int i;
setStudent(String na,String nu,String cl, String se,float[] ma)
{
name=na;
number=nu;
toClass=cl;
sex=se;
for(int i=0;i<ma.length ;i++) mark[i]=ma[i];
for(int i=0;i<ma.length ;i++) total+=ma[i];
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -