新手求助

instigator 2003-10-16 09:00:50
我是一个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);
}
}
...全文
34 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
instigator 2003-10-18
  • 打赏
  • 举报
回复
小弟我已经解决那个问题了
不过还是要谢谢你!
呵呵
LoveRose 2003-10-16
  • 打赏
  • 举报
回复
修改为

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


代码://load student1
student1Label = new JLabel("Enter Student A's marks : ");
cont.add(number1Label);

修改为
//load student1
student1Label = new JLabel("Enter Student A's marks : ");
cont.add(student1Label);

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧