计算圆面积:
import java.awt.*; import java.awt.event.*;
public class circleArea extends Frame implements ActionListener { public static void main(String[] sss) { new circleArea(); }
private TextField tf; // 文本框,输入半径 private TextArea ta; // 文本域,显示面积 private Button qc; // 清除按钮 private Button js; // 计算按钮 private Button tc; // 结束按钮
public circleArea() { super("圆面积的计算"); this.setLayout(new BorderLayout(2, 2));
Panel pn = new Panel(); pn.add(new Label("请输入圆的半径:")); pn.add(tf = new TextField(10)); this.add(pn, BorderLayout.NORTH); this.add(qc = new Button("清除"), BorderLayout.WEST); this.add(js = new Button("计算"), BorderLayout.EAST); this.add(ta = new TextArea(), BorderLayout.CENTER); Panel ps = new Panel(); ps.add(tc = new Button("结束")); this.add(ps, BorderLayout.SOUTH);
qc.addActionListener(this); js.addActionListener(this); tc.addActionListener(this);
this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); System.exit(0); } }); this.setBounds(200, 200, 400, 400); this.setVisible(true); }
public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (qc == obj)// 清除 { ta.setText(""); } else if (js == obj)// 计算面积 { try { double r = Double.valueOf(tf.getText()); ta.setText(String.valueOf(Math.PI * r * r)); } catch (Exception ex) { ta.setText("数字转化出错: " + ex.getMessage()); } } else if (tc == obj)// 结束程序 { setVisible(false); System.exit(0); } } }
计算圆柱体体积:
import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane;
//计算圆柱体体积 public class CylinderVolume extends Frame implements ActionListener { public static void main(String[] ass) { new CylinderVolume(); }
private Button js; // 计算按钮 private Button tc; // 退出按钮 private TextField tf1; // 半径文本框 private TextField tf2; // 高文本框
private TextField tf3; // 体积文本框
public CylinderVolume() { super("Frame"); Panel pn = new Panel(); pn.add(new Label("圆柱体积计算")); this.add(pn, BorderLayout.NORTH); Panel ps = new Panel(); ps.add(js = new Button("计算")); ps.add(tc = new Button("退出")); this.add(ps, BorderLayout.SOUTH); Panel pc = new Panel(); pc.setLayout(new GridLayout(3, 2)); pc.add(new Label("圆柱底面半径:", Label.RIGHT)); pc.add(tf1 = new TextField(10)); pc.add(new Label("圆柱高:", Label.RIGHT)); pc.add(tf2 = new TextField(10)); pc.add(new Label("圆柱体积:", Label.RIGHT)); pc.add(tf3 = new TextField(10)); this.add(pc, BorderLayout.CENTER); tf3.setEditable(false);
js.addActionListener(this); tc.addActionListener(this);
this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); System.exit(0); } }); this.setBounds(200, 200, 300, 200); this.setBackground(Color.lightGray); this.setVisible(true); }
public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (js == obj)// 计算体积 { try { double r = Double.valueOf(tf1.getText()); double h = Double.valueOf(tf2.getText()); tf3.setText(String.valueOf(Math.PI * r * r * h)); } catch (Exception ex) { // 异常提示 JOptionPane.showMessageDialog(this, "数字转换出错! " + ex.getMessage(), "错误提示", JOptionPane.ERROR_MESSAGE); } } else if (tc == obj)// 退出程序 { this.setVisible(false); System.exit(0); } } }
ucloud6.18推出全球大促活动,针对新老用户(个人/企业)提供云服务器促销产品,其中最低配快杰云服务器月付5元起,中国香港快杰型云服务器月付13元起,最高可购3年,有AMD/Intel系列。当然这都是针对新用户的优惠。注意,UCloud全球有31个数据中心,29条专线,覆盖五大洲,基本上你想要的都能找到。注意:以上ucloud 618优惠都是新用户专享,老用户就随便看看!点击进入:uclou...
spinservers怎么样?spinservers大硬盘服务器。Spinservers刚刚在美国圣何塞机房补货120台独立服务器,CPU都是双E5系列,64-512GB DDR4内存,超大SSD或NVMe存储,数量有限,机器都是预部署好的,下单即可上架,无需人工干预,有需要的朋友抓紧下单哦。Spinservers是Majestic Hosting Solutions,LLC旗下站点,主营美国独立...
收到10gbiz发来的7月份优惠方案,中国香港、美国洛杉矶机房VPS主机4折优惠码,优惠后洛杉矶VPS月付2.36美元起,香港VPS月付2.75美元起。这是一家2020年成立的主机商,提供的产品包括独立服务器租用和VPS主机等,数据中心在美国洛杉矶、圣何塞和中国香港。商家VPS主机基于KVM架构,支持使用PayPal或者支付宝付款。洛杉矶VPS架构CPU内存硬盘带宽系统价格单核512MB10GB1...