当前位置: 代码迷 >> Java相关 >> Average编译不能通过
  详细解决方案

Average编译不能通过

热度:161   发布时间:2007-01-21 22:22:00.0
Average编译不能通过

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

//<applet code=Average.class width=400 height=300></applet>

public class Average extends Applet implements ActionListener
{
public TextField input1,input2,display;
public Label labelTitle,label1input,label2input,label3display;
public Button b1;
public int num1,num2;
public double avg;

public void init()
{
input1=new TextField(12);
input2=new TextField(12);
display=new TextField(12);

input1.setText("0");
input2.setText("0");
display.setText("");
display.setEditable(false);

labelTitle=new Label("Average Calculator");
label1input=new Label("First Number");
label2input=new Label("Second Number");
label3display=new Label("Computed Average");

b1=new Button("Push to Compute Average");
b1.addActionListener(this);
add(labelTitle);add(label1input);add(input1);
add(label2input);add(input2);
add(b1);add(label3display);add(display);
}

public void actionPerformed(ActionEvent e);
{
num1=Integer.parseInt(input1.getText());
num2=Integer.parseInt(input2.getText());

avg=((double)num1+num2)/2;
display.setText(""+avg);
}
}

搜索更多相关的解决方案: Average  编译  

----------------解决方案--------------------------------------------------------
以下是引用cnlg11349745在2007-1-21 22:22:00的发言:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

//<applet code=Average.class width=400 height=300></applet>

public class Average extends Applet implements ActionListener
{
public TextField input1,input2,display;
public Label labelTitle,label1input,label2input,label3display;
public Button b1;
public int num1,num2;
public double avg;

public void init()
{
input1=new TextField(12);
input2=new TextField(12);
display=new TextField(12);

input1.setText("0");
input2.setText("0");
display.setText("");
display.setEditable(false);

labelTitle=new Label("Average Calculator");
label1input=new Label("First Number");
label2input=new Label("Second Number");
label3display=new Label("Computed Average");

b1=new Button("Push to Compute Average");
b1.addActionListener(this);
add(labelTitle);add(label1input);add(input1);
add(label2input);add(input2);
add(b1);add(label3display);add(display);
}

public void actionPerformed(ActionEvent e);//这里多了一个冒号,服了你,如此不小心
{
num1=Integer.parseInt(input1.getText());
num2=Integer.parseInt(input2.getText());

avg=((double)num1+num2)/2;
display.setText(""+avg);
}
}


----------------解决方案--------------------------------------------------------

真不小心!诸原没看出来。
----------------解决方案--------------------------------------------------------

  相关解决方案