急:小弟有个程序出错,请各位高手指点,Thank you!!! public void actionPerformed(ActionListener e) 改成public void actionPerformed(ActionEvent e) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class BL implements ActionListener { public void actionPerformed(ActionEvent e) {//原来的有错 给你一帖看:偶上周看了<thinking in java>《java编程思想》很好,深受启发!!发现原来写的是乱七八糟。我的程序写完了,还有一点没有完成,就是如何判断输入框输入的一定是数字,还有为什么30/100 = 0.300000002 。请大家指正!import java.awt.*;import java.applet.*;import java.awt.event.*;public class MyWork extends Applet{ TextField tf1 = new TextField("10",3); TextField tf2 = new TextField("20",3); TextField tf3 = new TextField("30",3); TextField tf4 = new TextField("40",3); Button bt1 = new Button("确定"); Button bt2 = new Button("关闭"); Checkbox cb1,cb2; Panel p1 = new Panel(); public void init(){ Label lb1 = new Label("第一季度"); Label lb2 = new Label("第二季度"); Label lb3 = new Label("第三季度"); Label lb4 = new Label("第四季度"); p1.setLayout(new FlowLayout()); p1.add(lb1); p1.add(tf1); p1.add(lb2); p1.add(tf2); p1.add(lb3); p1.add(tf3); p1.add(lb4); p1.add(tf4); Panel p2 = new Panel(); p2.setLayout(new FlowLayout()); CheckboxGroup cbg = new CheckboxGroup(); p2.add(cb1 = new Checkbox("柱状", cbg, true)); p2.add(cb2 = new Checkbox("饼状", cbg, false)); p2.setLayout(new FlowLayout()); p2.add(bt1); bt1.addActionListener(new B1()); p2.add(bt2); bt2.addActionListener(new B2()); add("North", p1); add("North", p2); Panel p3 = new Panel(); add("Center", p3); } public void paint(Graphics g){ float x1,x2,x3,x4; int i; char temp; int wide = getSize().width/2 ; int high = getSize().height/2 ; x1 = Float.parseFloat(tf1.getText().trim()); x2 = Float.parseFloat(tf2.getText().trim()); x3 = Float.parseFloat(tf3.getText().trim()); x4 = Float.parseFloat(tf4.getText().trim()); /*判断是否为数字 for(i=0;i<tf1.getText().length();i++){ ????????????????? temp = tf1.getText().charAt(i); } */ float p; int p1,p2,p3,p4; p = x1 + x2 + x3 + x4; //画图例 g.drawRect(50,100,100,100); g.setColor(Color.red); g.fillRect(55,110,10,10); g.setColor(Color.BLACK); g.drawString("一季度"+tf1.getText().trim()+"--"+x1/p*100+"%",70,120); g.setColor(Color.green); g.fillRect(55,130,10,10); g.setColor(Color.BLACK); g.drawString("二季度"+tf2.getText().trim()+"--"+x2/p*100+"%",70,140); g.setColor(Color.blue); g.fillRect(55,150,10,10); g.setColor(Color.BLACK); g.drawString("三季度"+tf3.getText().trim()+"--"+x3/p*100+"%",70,160); g.setColor(Color.yellow); g.fillRect(55,170,10,10); g.setColor(Color.BLACK); g.drawString("四季度"+tf4.getText().trim()+"--"+x4/p*100+"%",70,180); if(cb1.getState()== true ){ //画柱状图 p1 = (int)((x1 / p) * 460); p2 = (int)((x2 / p) * 460); p3 = (int)((x3 / p) * 460); p4 = (int)((x4 / p) * 460); if (p1>240 || p2> 240 || p3 > 240 || p4 > 240){ p1 = (int)((x1 / p) * 240); p2 = (int)((x2 / p) * 240); p3 = (int)((x3 / p) * 240); p4 = (int)((x4 / p) * 240); } //坐标轴 g.drawLine(wide-120,high+120,wide+230,high+120); g.drawLine(wide+230,high+120,wide+225,high+125); g.drawLine(wide+230,high+120,wide+225,high+115); g.drawLine(wide-120,high+120,wide-120,high-120); g.drawLine(wide-120,high-120,wide-125,high-115); g.drawLine(wide-120,high-120,wide-115,high-115); for(i=wide-120;i<wide+230;i++){ if (i%20 == 0){ g.drawLine(i,high+120,i,high+122); } } for(i=high+120;i>high-120;i--){ if (i%20 == 0){ g.drawLine(wide-120,i,wide-118,i); } } //柱状图 g.setColor(Color.red); g.fillRect(wide-90,high+120-p1,50,p1); g.setColor(Color.green); g.fillRect(wide-10,high+120-p2,50,p2); g.setColor(Color.blue); g.fillRect(wide+70,high+120-p3,50,p3); g.setColor(Color.yellow); g.fillRect(wide+150,high+120-p4,50,p4); } else if(cb2.getState()== true ){ //画饼状图 p1 = (int)((x1 / p) * 360); p2 = (int)((x2 / p) * 360); p3 = (int)((x3 / p) * 360); p4 = (int)((x4 / p) * 360); g.setColor(Color.red); g.fillArc(wide-150,high-120,320,320,0,p1); g.setColor(Color.green); g.fillArc(wide-150,high-120,320,320,p1,p2); g.setColor(Color.blue); g.fillArc(wide-150,high-120,320,320,p1+p2,p3); g.setColor(Color.yellow); g.fillArc(wide-150,high-120,320,320,p1+p2+p3,360-p1-p2-p3); } } class B1 implements ActionListener{ public void actionPerformed(ActionEvent e){ repaint(); } } class B2 implements ActionListener{ public void actionPerformed(ActionEvent e){ System.exit(0); } }} 对象比较 jtree的问题 讨教下。。下Socket通讯。。。。 帮帮忙啊!谢谢 关于条件运算符的 来看看 我写的这个ping的实现。 想和志同道合的朋友联合请1位Java高手,有兴趣的朋友请进来。(南京) 一个文件中只能有一个public 类吗? 请问各位一个有关java的问题? help,关于空值的问题 求助關JDBC連到SQL2000的問題 怎么把sql server8.0的驱动加入到jb8里面去?
public void actionPerformed(ActionEvent e) {//原来的有错
偶上周看了<thinking in java>《java编程思想》很好,深受启发!!
发现原来写的是乱七八糟。我的程序写完了,还有一点没有完成,就是如何判断输入框输入的一定是数字,还有为什么30/100 = 0.300000002 。请大家指正!
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MyWork extends Applet{
TextField tf1 = new TextField("10",3);
TextField tf2 = new TextField("20",3);
TextField tf3 = new TextField("30",3);
TextField tf4 = new TextField("40",3);
Button bt1 = new Button("确定");
Button bt2 = new Button("关闭");
Checkbox cb1,cb2;
Panel p1 = new Panel();
public void init(){
Label lb1 = new Label("第一季度");
Label lb2 = new Label("第二季度");
Label lb3 = new Label("第三季度");
Label lb4 = new Label("第四季度");
p1.setLayout(new FlowLayout());
p1.add(lb1);
p1.add(tf1);
p1.add(lb2);
p1.add(tf2);
p1.add(lb3);
p1.add(tf3);
p1.add(lb4);
p1.add(tf4);
Panel p2 = new Panel();
p2.setLayout(new FlowLayout());
CheckboxGroup cbg = new CheckboxGroup();
p2.add(cb1 = new Checkbox("柱状", cbg, true));
p2.add(cb2 = new Checkbox("饼状", cbg, false));
p2.setLayout(new FlowLayout());
p2.add(bt1);
bt1.addActionListener(new B1());
p2.add(bt2);
bt2.addActionListener(new B2());
add("North", p1);
add("North", p2);
Panel p3 = new Panel();
add("Center", p3);
} public void paint(Graphics g){
float x1,x2,x3,x4;
int i;
char temp;
int wide = getSize().width/2 ;
int high = getSize().height/2 ;
x1 = Float.parseFloat(tf1.getText().trim());
x2 = Float.parseFloat(tf2.getText().trim());
x3 = Float.parseFloat(tf3.getText().trim());
x4 = Float.parseFloat(tf4.getText().trim());
/*判断是否为数字
for(i=0;i<tf1.getText().length();i++){
?????????????????
temp = tf1.getText().charAt(i);
}
*/
float p;
int p1,p2,p3,p4;
p = x1 + x2 + x3 + x4;
//画图例
g.drawRect(50,100,100,100);
g.setColor(Color.red);
g.fillRect(55,110,10,10);
g.setColor(Color.BLACK);
g.drawString("一季度"+tf1.getText().trim()+"--"+x1/p*100+"%",70,120);
g.setColor(Color.green);
g.fillRect(55,130,10,10);
g.setColor(Color.BLACK);
g.drawString("二季度"+tf2.getText().trim()+"--"+x2/p*100+"%",70,140);
g.setColor(Color.blue);
g.fillRect(55,150,10,10);
g.setColor(Color.BLACK);
g.drawString("三季度"+tf3.getText().trim()+"--"+x3/p*100+"%",70,160);
g.setColor(Color.yellow);
g.fillRect(55,170,10,10);
g.setColor(Color.BLACK);
g.drawString("四季度"+tf4.getText().trim()+"--"+x4/p*100+"%",70,180);
if(cb1.getState()== true ){
//画柱状图
p1 = (int)((x1 / p) * 460);
p2 = (int)((x2 / p) * 460);
p3 = (int)((x3 / p) * 460);
p4 = (int)((x4 / p) * 460);
if (p1>240 || p2> 240 || p3 > 240 || p4 > 240){
p1 = (int)((x1 / p) * 240);
p2 = (int)((x2 / p) * 240);
p3 = (int)((x3 / p) * 240);
p4 = (int)((x4 / p) * 240);
}
//坐标轴
g.drawLine(wide-120,high+120,wide+230,high+120);
g.drawLine(wide+230,high+120,wide+225,high+125);
g.drawLine(wide+230,high+120,wide+225,high+115);
g.drawLine(wide-120,high+120,wide-120,high-120);
g.drawLine(wide-120,high-120,wide-125,high-115);
g.drawLine(wide-120,high-120,wide-115,high-115);
for(i=wide-120;i<wide+230;i++){
if (i%20 == 0){
g.drawLine(i,high+120,i,high+122);
}
}
for(i=high+120;i>high-120;i--){
if (i%20 == 0){
g.drawLine(wide-120,i,wide-118,i);
}
}
//柱状图
g.setColor(Color.red);
g.fillRect(wide-90,high+120-p1,50,p1);
g.setColor(Color.green);
g.fillRect(wide-10,high+120-p2,50,p2);
g.setColor(Color.blue);
g.fillRect(wide+70,high+120-p3,50,p3);
g.setColor(Color.yellow);
g.fillRect(wide+150,high+120-p4,50,p4);
}
else if(cb2.getState()== true ){
//画饼状图
p1 = (int)((x1 / p) * 360);
p2 = (int)((x2 / p) * 360);
p3 = (int)((x3 / p) * 360);
p4 = (int)((x4 / p) * 360);
g.setColor(Color.red);
g.fillArc(wide-150,high-120,320,320,0,p1);
g.setColor(Color.green);
g.fillArc(wide-150,high-120,320,320,p1,p2);
g.setColor(Color.blue);
g.fillArc(wide-150,high-120,320,320,p1+p2,p3);
g.setColor(Color.yellow);
g.fillArc(wide-150,high-120,320,320,p1+p2+p3,360-p1-p2-p3);
}
}
class B1 implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
class B2 implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
}