public void actionPerformed(ActionEvent e)
{}
此函数的最后一句加上repaint();就行了~~~~~

解决方案 »

  1.   

    //程序将10个学生的信息从界面输入,包括学生的学号,姓名,成绩,班级,以及成绩查询密码.
    //但界面上不会显示学生的成绩以及查询密码
    //输入完毕后,将学生按学号进行排序,程序具有查询功能,当对学生进行成绩查询功能时,密码通过才会输出成绩.
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Student1 extends Applet implements ActionListener
    {
    int Datainputed1,Datainputed2;
    Label prompt=new Label("请输入学生的信息(最多10个): ");
    TextField input=new TextField(5);
    Button sorbtn=new Button("排序");
    String [][]student=new String [10][5];
    String msg="";
    public void init()
    {
    add(prompt);
    add(input);
    add(sorbtn);
    input.addActionListener(this);
    sorbtn.addActionListener(this);
    }
    public void paint(Graphics g)
    {
    for(int i=0;i<10;i++)
    for(int j=0;j<3;j++)
    {

    g.drawString(student[i][j],10+50*j,10+50*i);
    }
    g.drawString(msg,10,400);


    }


    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==input)
    {
    student[Datainputed1][Datainputed2++]=input.getText();
    if(Datainputed1==9&&Datainputed2>4)
    {
    prompt.setText("已输入10个学生的信息,不能再输入");
                             input.setVisible(false);

    }
                     else
                     {
                     prompt.setText("已输入"+Datainputed1+"个数据,请继续第"+(Datainputed1+1)+"个数据的输入");
    input.setText(" ");
    }

    if(Datainputed2==5)
    {
    Datainputed1++;
    Datainputed2=0;
    input.setText("");
    }
    }
    if(e.getActionCommand()=="排序")
    {
    SortProcedure();
    sorbtn.setLabel("查找");
    prompt.setText("请输入欲查找学生的学号");
    input.setVisible(true);
    input.setText("");
    repaint();
    }

    if(e.getActionCommand()=="查找")
    {
    String s1=input.getText();
    input.setText("");
    prompt.setText("请输入该学生的成绩查询密码");
    String s2=input.getText();
    if(MiMa(s1,s2))
    {
    int f=ChaZhao(s1);
    msg="您所查询的学生成绩为"+student[f][3];
    }
    else
    msg="对不起,你没有该学生的成绩查询权限";
    repaint();
    }
    repaint();
    }

    void SortProcedure()
    {

    String temp;
    for(int i=0;i<10;i++)
    for(int j=0;j<9-i;j++)
    {
    if(Integer.parseInt(student[j][0])>Integer.parseInt(student[j+1][0]))
    {
    temp=student[j][0];
    student[j][0]=student[j+1][0];
    student[j+1][0]=temp;
    }
    }
    }
    int ChaZhao(String s)
    {
    int k = -1;
    for(int i=0;i<10;i++)
    {
    if(student[i][0]==s)
    k = i;

    }
    return k;
    }
    boolean MiMa(String xuehao,String mima)
    {
    int i = -1;
    String temp;
    boolean j;
    for(int k=0;k<10;k++)
    {
    if(student[k][0]==xuehao)
    i=k;
    }
    temp=student[i][4];
    j=temp.equals(mima);
    return j;
    }
    }