急求大神帮忙续写一些以下的java代码,谢谢了!!!!!

以下是详细代码,接着写就好,加入三角形面积计算和平行四边形面积计算。最好具备清空和退出按钮,没有也好。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class WinFrame extends JFrame implements ActionListener{//主窗口
JMenuBar bar;
JMenu menu;
JMenuItem item1,item2;
Circle circle;
Trangile trangile;

public WinFrame(){
super("主窗口");
bar = new JMenuBar();
menu = new JMenu("选择");
item1 = new JMenuItem("圆面积计算");
item2 = new JMenuItem("三角形面积计算");

menu.add(item1);
menu.add(item2);
bar.add(menu);
setJMenuBar(bar);
circle = new Circle();
trangile = new Trangile();
item1.addActionListener(this);
item2.addActionListener(this);

setLocation(200,200);
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(3);

}

public void actionPerformed(ActionEvent e){
if(e.getSource() == item1){
circle.setVisible(true);
}
if(e.getSource() == item2){
trangile.setVisible(true);
}
}
}

class Circle extends JFrame implements ActionListener{//计算圆面积
JLabel lab1,lab2;
JTextField rt,at;
JButton but;
double r,area;
Container con;
JPanel jp;
// WinFrame wf;
public Circle(){
super("圆面积计算");
con = getContentPane();
jp = new JPanel();
lab1 = new JLabel("请输入半径:");
lab2 = new JLabel("圆面积为:");
rt = new JTextField(10);
at = new JTextField(15);
but = new JButton("确定");
but.addActionListener(this);

jp.add(lab1);
jp.add(rt);
jp.add(but);
jp.add(lab2);
jp.add(at);

con.add(jp);
setLocation(200,200);
setSize(300,300);
//setVisible(true);
setDefaultCloseOperation(2);
}
public void actionPerformed(ActionEvent e){
r = Double.parseDouble(rt.getText());
area = Math.PI*r*r;
at.setText(""+area);
}
}

class Trangile extends JFrame implements ActionListener{//计算三角形面积

public Trangile(){

}
public void actionPerformed(ActionEvent e){

}
}

public class Test{
public static void main(String[] args) {
new WinFrame();

}
}

import java.awt.Container;
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.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

class Trangile extends JFrame implements ActionListener {// 计算三角形面积
JLabel lab1, lab2;
JTextField rt, at;
JButton but;
double  area;
Container con;
JPanel jp;
private JTextField textField;

// WinFrame wf;
public Trangile() {
super("三角形面积计算");
con = getContentPane();
jp = new JPanel();
lab1 = new JLabel("\u8BF7\u8F93\u5165\u4E09\u89D2\u5F62\u7684\u5E95: ");
lab1.setBounds(16, 8, 161, 14);
lab2 = new JLabel("三角形的面积为:");
lab2.setBounds(16, 72, 88, 14);
rt = new JTextField(10);
rt.setBounds(182, 5, 86, 20);
at = new JTextField(15);
at.setBounds(182, 38, 86, 20);
jp.setLayout(null);

jp.add(lab1);
jp.add(rt);
jp.add(lab2);
but = new JButton("\u786E\u5B9A");
but.setBounds(16, 115, 73, 23);
but.addActionListener(this);
jp.add(but);
jp.add(at);

con.add(jp);

JLabel label = new JLabel("\u8BF7\u8F93\u5165\u4E09\u89D2\u5F62\u7684\u9AD8");
label.setBounds(16, 41, 161, 14);
jp.add(label);

textField = new JTextField(15);
textField.setBounds(182, 69, 86, 20);
jp.add(textField);

JButton button = new JButton("\u6E05\u7A7A");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
rt.setText("");
at.setText("");
textField.setText("");

}
});
button.setBounds(104, 115, 73, 23);
jp.add(button);

JButton button_1 = new JButton("\u9000\u51FA");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

System.exit(0);
}
});
button_1.setBounds(195, 115, 73, 23);
jp.add(button_1);
setLocation(200, 200);
setSize(300, 300);
// setVisible(true);
setDefaultCloseOperation(2);
}

public void actionPerformed(ActionEvent e) {
 String  base = rt.getText();
 String  tall =at.getText();  
area = Double.parseDouble(base)* Double.parseDouble(tall)*0.5;
textField.setText("" + area);
}
}

追问

哥,还有个来,还能帮小弟一下吗

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-06-25
不用客气了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网