当前位置:编程学习 > JAVA >>

Exception in thread "main" java.lang.Error: 无法解析的编译问题:

我的程序这样的:
package com.yzx.txyhjm;
import java.awt.*;
import java.awt.event.*;
import com.yzx.txyhjm.Rectangle;
import com.yzx.txyhjm.Ellipse;
import javax.swing.*;
public class Pingmianyj extends JFrame implements ActionListener{
    private JRadioButton r1,r2;
    private JTextField f[];
    private JButton b;
    private Huabu huab;
public Pingmianyj(){
     super("绘制平面图形并计算周长和面积");
     this.setBounds(100,100,500,400);
     this.setDefaultCloseOperation(3);
     JPanel p=new JPanel();
     JPanel p0=new JPanel();
     this.add(p,"North"); 
     r1=new JRadioButton("矩形",true);
     r2=new JRadioButton("椭圆");
     ButtonGroup d=new ButtonGroup();
     d.add(r1);d.add(r2);
     p.add(r1);p.add(r2);
     r1.addActionListener(this);
     r2.addActionListener(this);
     p.add(new JLabel("长度"));
     f=new JTextField[4];
     for(int i=0;i<4;i++)
        f[i]=new JTextField(10);
    
     p.add(f[0]);
     p.add(new JLabel("宽度"));
     p.add(f[1]);
     b=new JButton("绘图");
     p.add(b);
     b.addActionListener(this);
    
     huab=new Huabu(0,0);
     this.add(huab);
    
     this.add(p0,"South");
     p0.add(new JLabel("周长"));
     p0.add(f[2]);
     p0.add(new JLabel("面积"));
     p0.add(f[3]);
     this.setVisible(true);
    }
public void actionPerformed(ActionEvent e){
if(e.getSource()==b){
try{
huab.setwh(Integer.parseInt(f[0].getText()),Integer.parseInt(f[1].getText()));
}
catch(NumberFormatException eg){
JOptionPane.showMessageDialog(this, "不能转换成整数,请重新输入!");
}
finally {}
huab.repaint();
if(r1.isSelected()){
f[2].setText(""+new Rectangle(Double.parseDouble(f[0].getText()),Double.parseDouble(f[1].getText())).perimeter());
f[3].setText(""+new Rectangle(Double.parseDouble(f[0].getText()),Double.parseDouble(f[1].getText())).area());
}
if(r2.isSelected()){
f[2].setText(""+new Ellipse(Double.parseDouble(f[0].getText()),Double.parseDouble(f[1].getText())).perimeter());
f[3].setText(""+new Ellipse(Double.parseDouble(f[0].getText()),Double.parseDouble(f[1].getText())).area());
}
}
}
class Huabu extends Canvas implements ComponentListener{
private int w,h;
public Huabu(int w,int h){
this.setwh(w, h);
this.addComponentListener(this);
}
public void setwh(int w,int h){
this.w=w;this.h=h;
}
public void paint(Graphics g){
if(r1.isSelected())
g.fillRect(50, 50, w, h);
if(r2.isSelected())
            g.fillOval(50, 50, w, h);
}
public void componentResized(ComponentEvent e){
this.repaint();
}
public void componentMoved(ComponentEvent e){}
public void componentHidden(ComponentEvent e){}
public void componentShown(ComponentEvent e){}
}
public static void main(String[] args) {
new Pingmianyj();
}
}




运行后:
Exception in thread "main" java.lang.Error: 无法解析的编译问题:

at com.yzx.txyhjm.Pingmianyj.main(Pingmianyj.java:95)



求高手帮助。 无法解析的编译问题 异常 --------------------编程问答-------------------- 缺少包?变量? --------------------编程问答-------------------- 请问缺少什么包?什么变量? --------------------编程问答-------------------- 我的 Ellipse类、Rectangle类都有:
package com.yzx.txyhjm;



interface Area{
public abstract double area();
}
public class Ellipse implements Area {
    protected double a;
    protected double b;
    public Ellipse(double a,double b){
     this.a=a;
     this.b=b;
    }
    public Ellipse(double a){
     this(a,a);
    }
    public Ellipse(){
     this(0,0);
    }
    public double area(){
     return Math.PI*a*b;
    }
public double perimeter(){
return Math.PI*(a+b);
}
public String toString(){
return "一个椭圆的a半轴:"+a+", b半轴:"+b+", 椭圆的面积:"+area()+", 椭圆的周长:"+perimeter();
}
public static void main(String[] args) {

System.out.println(new Ellipse(4.0,3.0).toString());
}

}













package com.yzx.txyhjm;



public class Rectangle implements Area{
    protected double length;
    protected double width;
public Rectangle(double length,double width){
this.length=length;
this.width=width;
}
public Rectangle(double width){
this(width,width);
}
public Rectangle(){
this(0,0);
}
public double area(){
return this.width*this.length;
}
public double perimeter(){
return (this.width+this.length)*2;
}
public String toString(){
return "一个矩形,长度"+length+",宽度"+width+",面积为"+area()+",周长为"+perimeter();
}
public static void main(String[] args) {
System.out.println(new Rectangle(10,20).toString());

}

}

补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,