新手求助
我是一个JAVA的初学者,在我编写一个applet时使用JFrame函数
却发现程序总是告诉我初始化失败,怎么回事?
小弟我把程序放在下边,希望各位大虾多多帮助!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class TheTwoStudent extends JApplet implements ActionListener {
JLabel number1Label,number2Label,number3Label,number4Label,number5Label,
number6Label,student1Label,student2Label,resultLabel;
JTextField number1Field,number2Field,number3Field,number4Field,
number5Field,number6Field,resultField;
JButton button;
String display;
JTextArea outArea;
public void init() {
Container cont = getContentPane();
cont.setLayout(new FlowLayout());
//cont.setVisible(true);
//load student1
student1Label = new JLabel("Enter Student A's marks : ");
cont.add(number1Label);
number1Label = new JLabel("Enter mark of Subject A : ");
cont.add(number1Label);
number1Field = new JTextField(10);
cont.add(number1Field);
number2Label = new JLabel("Enter mark of Subject B : ");
cont.add(number2Label);
number2Field = new JTextField(10);
cont.add(number2Field);
number3Label = new JLabel("Enter mark of Subject C : ");
cont.add(number2Label);
number3Field = new JTextField(10);
cont.add(number3Field);
//load student2
student2Label = new JLabel("Enter Student B's marks : ");
cont.add(number2Label);
number4Label = new JLabel("Enter mark of Subject A : ");
cont.add(number4Label);
number4Field = new JTextField(10);
cont.add(number1Field);
number5Label = new JLabel("Enter mark of Subject B : ");
cont.add(number5Label);
number5Field = new JTextField(10);
cont.add(number1Field);
number6Label = new JLabel("Enter mark of Subject C : ");
cont.add(number6Label);
number6Field = new JTextField(10);
cont.add(number1Field);
//load button
button = new JButton("DISPLAY");
button.addActionListener(this);
cont.add(button);
//load result area
outArea = new JTextArea(10,15);
cont.add(outArea);
}//end init()
public void actionPerformed(ActionEvent actionEvent){
display = "THE Calculate rusult:\n";
float max,min,average,sum;
float [][]mark=new float[2][3];
mark[0][0] = Float.parseFloat(number1Field.getText());
mark[0][1] = Float.parseFloat(number2Field.getText());
mark[0][2] = Float.parseFloat(number3Field.getText());
mark[1][0] = Float.parseFloat(number4Field.getText());
mark[1][1] = Float.parseFloat(number5Field.getText());
mark[1][2] = Float.parseFloat(number6Field.getText());
max=mark[0][0];
min=mark[0][0];
sum=0;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++){
if(max<=mark[i][j])max=mark[i][j];
if(min>=mark[i][j])min=mark[i][j];
sum+=mark[i][j];
}
average=sum/6;
display += "The max mark is "+max+"\n";
display += "The min mark is "+min+"\n";
display += "The average mark is"+average+"\n";
outArea.setText(display);
}
}