?? student.java~257~
字號:
sexprompt=new Label("性別");
prompt=new Label(" 請輸入對象特征");
sub1_prompt=new Label("Java");
sub2_prompt=new Label("匯編");
sub3_prompt=new Label("計組");
sub4_prompt=new Label("英語");
sub5_prompt=new Label("隨機");
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);
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(btn3);
add(prompt);
add(tea);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
addWindowListener(new closeWin());
//setEditables與etEnabled有什么區別?
inputclass.setEditable(false);
inputsex.setEditable(false);
input_sub1_mark.setEditable(false);
input_sub2_mark.setEditable(false);
input_sub3_mark.setEditable(false);
input_sub4_mark.setEditable(false);
input_sub5_mark.setEditable(false);
input_sub6_mark.setEditable(false);
tea.append(" 姓名\t學號\t班級\t性別\tJava\t匯編\t計組\t英語"
+"\t隨機\t圖論\t均分\t名次\n原:");
setSize(818,818);
setVisible(true);
show();
}
public void actionPerformed(ActionEvent ap)
{
if(ap.getActionCommand()=="關閉")
{
dispose();
}
else
if(ap.getActionCommand()=="查找")
{
if(inputclass.isEditable() ==false)
{
for(i=0;i<NewSetStudent.size();i++)
{
if (((setStudent)NewSetStudent.elementAt(i)).getName()
.equals( inputname.getText())
&&((setStudent) NewSetStudent.elementAt(i)).getNumber()
.equals( inputnumber.getText()) )
{
find=true;
r=i;
tea.append(((setStudent)NewSetStudent.elementAt(i)).getName()+"\t");
tea.append(((setStudent) NewSetStudent.elementAt(i)).getNumber()+"\t");
tea.append(((setStudent) NewSetStudent.elementAt(i)).getToclass()+"\t");
tea.append(((setStudent) NewSetStudent.elementAt(i)).getSex()+"\t");
for (int j= 0; j< 6; j++)
{
srta[j] = Float.toString(
((setStudent)NewSetStudent.elementAt(i)).getMark(j));
tea.append(srta[j] + "\t");
}
srta[6]=Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getAverage()) ;
srta[7]=Integer.toString(
((setStudent) NewSetStudent.elementAt(i)).getIndex()) ;
tea.append(srta[6]+"\t");
tea.append(srta[7]+"\n");
inputclass.setEditable(true);
inputsex.setEditable(true);
input_sub1_mark.setEditable(true);
input_sub2_mark.setEditable(true);
input_sub3_mark.setEditable(true);
input_sub4_mark.setEditable(true);
input_sub5_mark.setEditable(true);
input_sub6_mark.setEditable(true);
inputclass.setText(
((setStudent) NewSetStudent.elementAt(i)).getToclass());
inputsex.setText(
((setStudent) NewSetStudent.elementAt(i)).getSex());
input_sub1_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(0)));
input_sub2_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(1)));
input_sub3_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(2)));
input_sub4_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(3)));
input_sub5_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(4)));
input_sub6_mark.setText(Float.toString(
((setStudent) NewSetStudent.elementAt(i)).getMark(5)));
}
if(find==false)
tea.append("\n未找到\n");
}
}
}
else
if(ap.getActionCommand()=="修改")
{
find=false;
if(inputclass.isEditable() ==true)
{
informationChange=true;
fl[0]=Float.parseFloat(input_sub1_mark.getText());
fl[1]=Float.parseFloat(input_sub2_mark.getText());
fl[2]=Float.parseFloat(input_sub3_mark.getText());
fl[3]=Float.parseFloat(input_sub3_mark.getText());
fl[4]=Float.parseFloat(input_sub5_mark.getText());
fl[5]=Float.parseFloat(input_sub6_mark.getText());
NewSetStudent.setElementAt(new setStudent(inputname.getText(),
inputnumber.getText() ,inputclass.getText(),
inputsex.getText() ,fl),r);
tea.append("現:"+((setStudent)NewSetStudent.elementAt(r)).getName()+"\t");
tea.append(((setStudent)NewSetStudent.elementAt(r)).getNumber()+"\t");
tea.append(((setStudent)NewSetStudent.elementAt(r)).getToclass()+"\t");
tea.append(((setStudent)NewSetStudent.elementAt(r)).getSex()+"\t");
for (int j= 0; j< 6; j++)
{
srta[j] = Float.toString(
((setStudent)NewSetStudent.elementAt(r)).getMark(j));
tea.append(srta[j] + "\t");
}
srta[6]=Float.toString(
((setStudent)NewSetStudent.elementAt(r)).getAverage());
srta[7]=Integer.toString(((setStudent)NewSetStudent.elementAt(r)).getIndex());
tea.append(srta[6]+"\t");
tea.append(srta[7]+"\n");
inputname.setText("");
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("");
inputclass.setEditable(false);
inputsex.setEditable(false);
input_sub1_mark.setEditable(false);
input_sub2_mark.setEditable(false);
input_sub3_mark.setEditable(false);
input_sub4_mark.setEditable(false);
input_sub5_mark.setEditable(false);
input_sub6_mark.setEditable(false);
}
else
{
ta.setText("\t\t\t請先確定目標");
}
}
}
}//修改類結束
//作圖標準設置類開始
class setPicture extends Frame implements ActionListener,ItemListener
{
Button btn;
TextField fd1,fd2;
Label prompt1, prompt2;
Choice size;
setPicture()
{ // 這里完全是為了訓練而有意這么做
prompt1 =new Label("設置分數段(始/末)");
fd1=new TextField("0",5);
fd2=new TextField("100",5);
prompt2 =new Label("設置密度");
size=new Choice();
size.add("5");
size.add("10");
size.add("20");
size.add("25");
size.add("30");
btn=new Button("設置");
setLayout(new FlowLayout());
add(prompt1);
add(fd1);
add(fd2);
add(prompt2);
add(size);
add(btn);
btn.addActionListener(this);
size.addItemListener(this);
setSize(300,200);
setLocation(100,100) ;
setVisible(true) ;
show() ;
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() =="設置")
{
picture_start=Integer.parseInt(fd1.getText()) ;
picture_end=Integer.parseInt(fd2.getText()) ;
dispose() ;
}
}
public void itemStateChanged(ItemEvent IE)
{
Choice temp;
picture_divide=5;
if(IE.getItemSelectable() instanceof Choice)
{
temp=(Choice)(IE.getItemSelectable());
picture_divide=Integer.parseInt(temp.getSelectedItem()) ;
}
}
}
//作圖標準設置類結束
//繪制圖表類
class drawPictures extends Frame
{
PCanvas cd;
Label prompt;
int markLabel;
drawPictures(String name,int min_divide)
{
super("圖表");
if(name=="Java")
markLabel=1;
else
if(name=="匯編")
{
markLabel=2;
}
else
if(name=="計組")
{
markLabel=3;
}
else
if(name=="英語")
{
markLabel=4;
}
else
if(name=="隨機")
{
markLabel=5;
}
else
if(name=="圖論")
{
markLabel=6;
}
else
if(name=="均分")
{
markLabel=7;
}
prompt=new Label("學生"+name+"成績一覽表");
setLayout(new FlowLayout());
cd=new PCanvas(min_divide,markLabel);
cd.setSize(500,300);
cd.setBackground(Color.blue ) ;
add(prompt);
add(cd);
// cd.requestFocus() ;
cd.repaint() ;
setSize(550,400);
addWindowListener(new closeWin());
setVisible(true);
setLocation(100,100);
show();
}
}
class PCanvas extends Canvas
{
int minD;
int markB;
public PCanvas(int m,int n)
{
minD=m;
markB=n;
}
public void paint(Graphics g)
{
g.drawLine(20,240,420,240) ;//畫X軸,每4格為一分
g.drawLine(20,30,20,250) ;//畫Y軸,每3格為一人
g.drawString("0",5,240) ;
g.drawString("5",5,225) ;
g.drawString("10",5,210) ;
g.drawString("15",5,195) ;
g.drawString("20",5,180) ;
g.drawString("25",5,165) ;
g.drawString("30",5,150) ;
g.drawString("35",5,135) ;
g.drawString("40",5,120) ;
g.drawString("45",5,105) ;
g.drawString("50",5,90) ;
g.drawString("55",5,75) ;
g.drawString("60",5,60) ;
for(int k=0;k<195;k+=15)
{
g.drawLine(20,225-k,24,225-k) ;
}
int p;
for(p=0;p<400;p+=(picture_divide*4))
{
g.drawRect(20+p,
240-divide_student_number[ markB-1][p/(picture_divide*4)]*3,
picture_divide*4,
divide_student_number[ markB-1][p/(picture_divide*4)]*3);
if(divide_student_number[markB-1][p/(picture_divide*4)]!=0)
g.drawString(
Integer.toString(divide_student_number[markB-1][p/(picture_divide*4)]),
20+p+2,
240-divide_student_number[ markB-1][p/(picture_divide*4)]*3-5);
if(p!=0)
g.drawString(Integer.toString(p/4),20+p,240+15);
}
}
}
//Windows窗口事件的處理類
class closeWin extends WindowAdapter
{
public void windowClosing(WindowEvent ee)
{
Frame frm=(Frame)(ee.getSource());
frm.dispose();
// System.exit(0);
}
}
class HandelMouse extends MouseAdapter
{
menuFrame mf;
HandelMouse(menuFrame m)
{
mf=m;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
mf.popM.show((Component)e.getSource(),e.getX(),e.getY());
}
}
}
// 包括了很多個內類的主類至此結束
// 程序結束。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -