编写java一个小程序,编译时告诉我需要.class,我应该怎么修改?求高手解答!
程序如下,图片部分为出错部分,编写的不好请多包涵importjava.awt.*;importjavax.swing.*;importjava.awt.event.e;p...
程序如下,图片部分为出错部分,编写的不好请多包涵
import java.awt.*;
import javax.swing.*;
import java.awt.event.e;
public class Triangle extends JFrame implements ActionListener{
JTextField bottom,highly;
JButton calculate;
JTextArea text;
public Triangle(){
r=new Triangle();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p1=new JPanel();
p1.add(new JLabel("底边:"));
bottom=new JTextField(5);
p1.add(bottom);
p1.add(new JTextField("高度"));
highly=new JTextField(5);
p1.add(highly);
calculate=new JButton("计算面积");
calculate.addActionListener(this);
p1.add(calculate);
this.getContentPane().add(p1,"North");
text=new JTextArea(5,20);
this.getContentPane().add(text);
this.setVisible(true);
}
public static void actionPerformed(ActionEvent r){
try{
int bottom1=Class.parseInt(bottom.getText());
int highly1=Class.parseInt(highly.getText());
r.setBottom(int);
r.setHighly(int);
if(r.isTriangle())
text.append("面积:"+area()+"\n");
}
catch(Exception ex){
text.append("出错:"+ex.toString()+"\n");
}
}
}
class triangle{
private int bottom;
private int highly;
public void setBottom(int bottom){
this.bottom=bottom;
}
public void setHighly(int highly){
this.highly=highly;
}
public boolean isTriangle(){
return bottom==highly?true:false;
}
public int area(){
return (bottom*highly)/2;
}
} 展开
import java.awt.*;
import javax.swing.*;
import java.awt.event.e;
public class Triangle extends JFrame implements ActionListener{
JTextField bottom,highly;
JButton calculate;
JTextArea text;
public Triangle(){
r=new Triangle();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p1=new JPanel();
p1.add(new JLabel("底边:"));
bottom=new JTextField(5);
p1.add(bottom);
p1.add(new JTextField("高度"));
highly=new JTextField(5);
p1.add(highly);
calculate=new JButton("计算面积");
calculate.addActionListener(this);
p1.add(calculate);
this.getContentPane().add(p1,"North");
text=new JTextArea(5,20);
this.getContentPane().add(text);
this.setVisible(true);
}
public static void actionPerformed(ActionEvent r){
try{
int bottom1=Class.parseInt(bottom.getText());
int highly1=Class.parseInt(highly.getText());
r.setBottom(int);
r.setHighly(int);
if(r.isTriangle())
text.append("面积:"+area()+"\n");
}
catch(Exception ex){
text.append("出错:"+ex.toString()+"\n");
}
}
}
class triangle{
private int bottom;
private int highly;
public void setBottom(int bottom){
this.bottom=bottom;
}
public void setHighly(int highly){
this.highly=highly;
}
public boolean isTriangle(){
return bottom==highly?true:false;
}
public int area(){
return (bottom*highly)/2;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询