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)
求高手帮助。