import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class Student extends JApplet implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2,t3,t4;
JButton bt;
JPanel p1,p2;public void init()
{
  l1=new JLabel("学生平时考试成绩");
  l1=new JLabel("学生机试成绩");
  l1=new JLabel("学生笔试成绩");
  l1=new JLabel("学生总评成绩");
  
  t1=new JTextField(30);
  t2=new JTextField(30);
  t3=new JTextField(30);
  t4=new JTextField(30);
  t4.setEditable(false);
  
  bt=new JButton("计算学生总评成绩");
  bt.addActionListener(this);
  
  p1=new JPanel(new GridLayout(4,2,2,2));
  p2=new JPanel();
  
  p1.add(l1);p1.add(t1);
  p1.add(l2);p1.add(t2);
  p1.add(l3);p1.add(t3);
  p1.add(l4);p1.add(t4);
  p2.add(bt);
  
  this.getContentPane().setLayout(new BorderLayout());
  this.getContentPane().add(p1,BorderLayout.NORTH);
  this.getContentPane().add(p2,BorderLayout.SOUTH);
}public void actionPerformed(ActionEvent ae)
{
  double a,b,c,d;
  try
  {
   if(t1.getText().equals("")||t2.getText().equals("")||t3.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"空值","错误",JOptionPane.ERROR_MESSAGE);
    t4.setText("");
   }
   else
   {
    a=Double.parseDouble(t1.getText());
    b=Double.parseDouble(t2.getText());
    c=Double.parseDouble(t3.getText());
    if(a<0||b<0||c<0||a>100||b>100||c>100)
    {
     t4.setText("输入的数值必须在0-100之间");
    }
    else
    {
     d=a*0.2+b*0.2+c*0.4;
     String str=String.valueOf(d);
     str=str.substring(0,str.indexOf(".")+1);
     t4.setText(str);
    }
   }
  }
  
  catch(Exception e)
  {
   t4.setText("错误");
  }
}
}HTML代码如下:<applet code=Student width=200 height=300>
</applet>