计算圆面积:
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); } } }
最近我们是不是在讨论较多的是关于K12教育的问题,培训机构由于资本的介入确实让家长更为焦虑,对于这样的整改我们还是很支持的。实际上,在云服务器市场中,我们也看到内卷和资本的力量,各大云服务商竞争也是相当激烈,更不用说个人和小公司服务商日子确实不好过。今天有看到UCloud发布的夏季促销活动,直接提前和双十一保价挂钩。这就是说,人家直接在暑假的时候就上线双十一的活动。早年的双十一活动会提前一周到十天...
hostodo从2014年年底运作至今一直都是走低价促销侧率运作VPS,在市场上一直都是那种不温不火的品牌知名度,好在坚持了7年都还运作得好好的,站长觉得hostodo还是值得大家在买VPS的时候作为一个候选考虑项的。当前,hostodo有拉斯维加斯和迈阿密两个数据中心的VPS在促销,专门列出了2款VPS给8T流量/月,基于KVM虚拟+NVMe整列,年付送DirectAdmin授权(发ticket...
传统农历新年将至,国人主机商DogYun(狗云)发来了虎年春节优惠活动,1月31日-2月6日活动期间使用优惠码新开动态云7折,经典云8折,新开独立服务器可立减100元/月;使用优惠码新开香港独立服务器优惠100元,并次月免费;活动期间单笔充值每满100元赠送10元,还可以参与幸运大转盘每日抽取5折码,流量,余额等奖品;商家限量推出一款年付特价套餐,共100台,每个用户限1台,香港VPS年付199元...