计算圆面积:
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); } } }
极光KVM怎么样?极光KVM本月主打产品:美西CN2双向,1H1G100M,189/年!在美西CN2资源“一兆难求”的大环境下,CN2+大带宽 是很多用户的福音,也是商家实力的象征。目前,极光KVM在7月份的促销,7月促销,美国CN2 GIA大带宽vps,洛杉矶联通cuvip,14元/月起;香港CN2+BGP仅19元/月起,这次补货,机会,不要错过了。点击进入:极光KVM官方网站地址极光KVM七月...
BuyVM商家属于比较老牌的服务商,早年有提供低价年付便宜VPS主机还记得曾经半夜的时候抢购的。但是由于这个商家风控非常严格,即便是有些是正常的操作也会导致被封账户,所以后来陆续无人去理睬,估计被我们风控的抢购低价VPS主机已经手足无措。这两年商家重新调整,而且风控也比较规范,比如才入手他们新上线的流媒体优化VPS主机也没有不适的提示。目前,BuyVM商家有提供新泽西、迈阿密等四个机房的VPS主机...
ZJI是成立于2011年原Wordpress圈知名主机商—维翔主机,2018年9月更名为ZJI,主要提供香港、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册业务。本月商家针对香港阿里云线路独立服务器提供月付立减270-400元优惠码,优惠后香港独立服务器(阿里云专线)E3或者E5 CPU,SSD硬盘,最低每月仅480元起。阿里一型CPU:Intel E5-2630L...