计算圆面积:
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); } } }
OneTechCloud(易科云)是一家主打CN2等高端线路的VPS主机商家,成立于2019年,提供的产品包括VPS主机和独立服务器租用等,数据中心可选美国洛杉矶、中国香港、日本等,有CN2 GIA线路、AS9929、高防、原生IP等。目前商家针对全场VPS主机提供月付9折,季付8折优惠码,优惠后香港VPS最低季付64元起(≈21.3元/月),美国洛杉矶CN2 GIA线路+20Gbps防御型VPS...
4324云是成立于2012年的老牌商家,主要经营国内服务器资源,是目前国内实力很强的商家,从价格上就可以看出来商家实力,这次商家给大家带来了全网最便宜的物理服务器。只能说用叹为观止形容。官网地址 点击进入由于是活动套餐 本款产品需要联系QQ客服 购买 QQ 800083597 QQ 2772347271CPU内存硬盘带宽IP防御价格e5 2630 12核16GBSSD 500GB30M1个IP...
BuyVM在昨天宣布上线了第四个数据中心产品:迈阿密,基于KVM架构的VPS主机,采用AMD Ryzen 3900X CPU,DDR4内存,NVMe硬盘,1Gbps带宽,不限制流量方式,最低$2/月起,支持Linux或者Windows操作系统。这是一家成立于2010年的国外主机商,提供基于KVM架构的VPS产品,数据中心除了新上的迈阿密外还包括美国拉斯维加斯、新泽西和卢森堡等,主机均为1Gbps带...