Topic: 能看懂的进来帮调试一下错误(我是新手)

  Print this page

1.能看懂的进来帮调试一下错误(我是新手) Copy to clipboard
Posted by: kkkrnm
Posted on: 2007-05-09 08:05

程序:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Example1 extends Applet implements ActionListener{
  TextField tf1;
  TextField tf2;
  TextField tf3;
  Button bt1;
  Button bt2;
  Button bt3;
  Button bt4;
  public void init(){
    tf1=new TextField("输入一个数字",10);
    tf2=new TextField("输入一个数字",10);
    tf3=new TextField("10");
    bt1=new Button("加");
    bt2=new Button("减");
    bt3=new Button("乘");
    bt4=new Button("除");
    add(tf1);
    add(tf2);
    add(tf3);
    add(bt1);
    add(bt2);
    add(bt3);
    add(bt4);
    bt1.addActionListener(this);
    bt2.addActionListener(this);
    bt3.addActionListener(this);
    bt4.addActionListener(this);
  }
  public void actionperformed(ActionEvent e){
    float count,i,j;
    if(e.getSource()==bt1){
      count=i+j;
      }
   if(e.getSource()==bt2){
   count=i-j;
   }
    if(e.getSource()==bt3){
      count=i*j;
     }
    if(e.getSource()==bt4){
     count=i/j;
      }
tf3.setText(""+count);
}
}
错误:class Example1 is public ,should be declared in a file named Example1.java
本人是新手。如果程序上有什么大的错误,希望会的人帮忙解决一下。感激不尽~

2.Re:能看懂的进来帮调试一下错误(我是新手) [Re: kkkrnm] Copy to clipboard
Posted by: aaarong
Posted on: 2007-05-13 18:11

/*
  <applet code="Example1" width=300 height=60>
  </applet>
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Example1 extends Applet implements ActionListener{
  TextField tf1;
TextField tf2;
TextField tf3;
  Button bt1;
Button bt2;
  Button bt3;
  Button bt4;
  float count,k,p;
  String i,j;
public void init(){
tf1=new TextField("输入一个数字",10);
tf2=new TextField("输入一个数字",10);
tf3=new TextField();
bt1=new Button("加");
bt2=new Button("减");
bt3=new Button("乘");
bt4=new Button("除");
add(tf1);
add(tf2);
add(tf3);
add(bt1);
add(bt2);
add(bt3);
add(bt4);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
bt4.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==bt1)
  {   i=tf1.getText();
    j=tf2.getText();
    k=Float.parseFloatLight Bulb;
    p=Float.parseFloat(j);
    count=k+p;
  }
  if(e.getSource()==bt2)
  {   i=tf1.getText();
    j=tf2.getText();
    k=Float.parseFloatLight Bulb;
    p=Float.parseFloat(j);
    count=k-p;
  }
  if(e.getSource()==bt3)
  {   i=tf1.getText();
    j=tf2.getText();
    k=Float.parseFloatLight Bulb;
    p=Float.parseFloat(j);
    count=k*p;
  }
  if(e.getSource()==bt4)
  {   i=tf1.getText();
    j=tf2.getText();
    k=Float.parseFloatLight Bulb;
    p=Float.parseFloat(j);
    count=k/p;
  }
   tf3.setText(""+count);
}
}

3.Re:能看懂的进来帮调试一下错误(我是新手) [Re: aaarong] Copy to clipboard
Posted by: kkkrnm
Posted on: 2007-05-15 20:37

就没人帮忙看下吗?我哭了就~

4.Re:能看懂的进来帮调试一下错误(我是新手) [Re: kkkrnm] Copy to clipboard
Posted by: kkkrnm
Posted on: 2007-05-15 20:42

k=Float.parseFloatLight Bulb;
p=Float.parseFloat(j);
改的人能帮忙解释一下为什么这么改吗?我有点看的不太明白~

5.Re:能看懂的进来帮调试一下错误(我是新手) [Re: kkkrnm] Copy to clipboard
Posted by: zcjl
Posted on: 2007-05-15 21:46

class Example1 is public ,should be declared in a file named Example1.java


我想,这个错误提示已经很明确了

6.Re:能看懂的进来帮调试一下错误(我是新手) [Re: kkkrnm] Copy to clipboard
Posted by: aaarong
Posted on: 2007-05-16 12:32

k=Float.parseFloatLight Light Bulb;
p=Float.parseFloat(j);
由于从getText()得到的是String类型,所以要把它转化成float类再进行运算


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923