随便写了个 功能实现了
public class Trapezoidal {
private double upWeight;
private double height;
private double downWeight;
public Trapezoidal(double upWeight,double height,double downWeight){
setHeight(height);
setDownWeight(downWeight);
setUpWeight(upWeight);
}
public double getUpWeight() {
return upWeight;
}
public void setUpWeight(double upWeight) {
this.upWeight = upWeight;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getDownWeight() {
return downWeight;
}
public void setDownWeight(double downWeight) {
this.downWeight = downWeight;
}
public String count(){
return Double.toString((getDownWeight()+getUpWeight())*getHeight()/2);
}
}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.sun.xml.internal.fastinfoset.algorithm.IEEE754FloatingPointEncodingAlgorithm;
public class TestApp extends JFrame{
private JFrame jf = new JFrame();
private JPanel jp = new JPanel();
private JLabel jl1,jl2,jl3;
private JButton jb1;
private JTextField jtf1,jtf2,jtf3,jtf4;
public TestApp(){
jl1 = new JLabel("上底");
jl2 = new JLabel("下底");
jl3 = new JLabel("高");
jtf1 = new JTextField();
jtf2 = new JTextField();
jtf3 = new JTextField();
jtf4 = new JTextField("结果");
jb1 = new JButton("计算");
jp.setLayout(new GridLayout(4, 2));
jp.add(jl1);
jp.add(jtf1);
jp.add(jl2);
jp.add(jtf2);
jp.add(jl3);
jp.add(jtf3);
jp.add(jb1);
jp.add(jtf4);
jf.add(jp);
jf.setVisible(true);
jf.setSize(400, 300);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double str1 = Double.valueOf(jtf1.getText());
double str2 = Double.valueOf(jtf2.getText());
double str3 = Double.valueOf(jtf3.getText());
jtf4.setText(new Trapezoidal(str1, str3, str2).count());
System.out.println(new Trapezoidal(str1, str3, str2).count());
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestApp ta = new TestApp();
}
}