计算圆面积:
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); } } }
特网云为您提供高速、稳定、安全、弹性的云计算服务计算、存储、监控、安全,完善的云产品满足您的一切所需,深耕云计算领域10余年;我们拥有前沿的核心技术,始终致力于为政府机构、企业组织和个人开发者提供稳定、安全、可靠、高性价比的云计算产品与服务。公司名:珠海市特网科技有限公司官方网站:https://www.56dr.com特网云为您提供高速、稳定、安全、弹性的云计算服务 计算、存储、监控、安全,完善...
今天CloudCone发布了最新的消息,推送了几款特价独立服务器/杜甫产品,美国洛杉矶MC机房,分配100Mbps带宽不限流量,可以选择G口限制流量计划方案,存储分配的比较大,选择HDD硬盘的话2TB起,MC机房到大陆地区线路还不错,有需要美国特价独立服务器的朋友可以关注一下。CloudCone怎么样?CloudCone服务器好不好?CloudCone值不值得购买?CloudCone是一家成立于2...
速云怎么样?速云是一家国人商家。速云商家主要提供广州移动、深圳移动、广州茂名联通、香港HKT等VDS和独立服务器。目前,速云推出深圳独服优惠活动,机房为深圳移动机房,购买深圳服务器可享受5折优惠,目前独立服务器还支持申请免费试用,需要提交工单开通免费体验试用,次月可享受永久8折优惠,也是需工单申请哦!点击进入:速云官方网站地址活动期限至 2021年7月22日速云云服务器优惠活动:活动1:新购首月可...