⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.java~257~

📁 图形化界面
💻 JAVA~257~
📖 第 1 页 / 共 4 页
字号:
      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 + -