码迷,mamicode.com
首页 > 其他好文 > 详细

构建之法——现代软件工程

时间:2015-04-13 20:46:31      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:


 import java.awt.*;
import java.awt.event.ActionListener;
 
import javax.swing.*;
 
 public class F {
 JFrame frame = new JFrame("计算机");
 
 JPanel pl = new JPanel();
 
 JPanel p2 = new JPanel();
 
 static JTextField show = new JTextField();
 
 static JButton b0 = new JButton("0");
 
 static JButton b1 = new JButton("1");
 
 static JButton b2 = new JButton("2");
 
 static JButton b3 = new JButton("3");
 
 static JButton b4 = new JButton("4");
 
 static JButton b5 = new JButton("5");
 
 static JButton b6 = new JButton("6");
 
 static JButton b7 = new JButton("7");
 
 static JButton b8 = new JButton("8");
 
 static JButton b9 = new JButton("9");
 
 JButton bjia = new JButton("+");
 
 JButton bjian = new JButton("-");
 
 JButton bcheng = new JButton("*");
 
 JButton bchu = new JButton("/");
 
 JButton bdian = new JButton(".");
 
 JButton bdeng = new JButton("=");
 
 JButton bqingchu = new JButton("清除");
 
 public void y() {
 pl.setLayout(new GridLayout(1, 1));
 pl.add(show);
 }
 
 public void p() {
 b1.addActionListener(new U());
 b2.addActionListener(new U());
 b3.addActionListener(new U());
 b4.addActionListener(new U());
 b5.addActionListener(new U());
 b6.addActionListener(new U());
 b7.addActionListener(new U());
 b8.addActionListener(new U());
 b9.addActionListener(new U());
 b0.addActionListener(new U());
 
 bjia.addActionListener(new Fu());
 bjian.addActionListener(new Fu());
 bcheng.addActionListener(new Fu());
 bchu.addActionListener(new Fu());
 
 bdeng.addActionListener(new Deng());
 bqingchu.addActionListener(new Qing());
 
 p2.setLayout(new GridLayout(6, 3));
 p2.add(b1);
 p2.add(b2);
 p2.add(b3);
 p2.add(b4);
 p2.add(b5);
 p2.add(b6);
 p2.add(b7);
 p2.add(b8);
 p2.add(b9);
 p2.add(b0);
 p2.add(bjia);
 p2.add(bjian);
 p2.add(bcheng);
 p2.add(bchu);
 p2.add(bdian);
 p2.add(bqingchu);
 p2.add(bdeng);
 }
 
 public void o() {
 frame.setLayout(new BorderLayout());
 frame.add(pl, BorderLayout.NORTH);
 frame.add(p2, BorderLayout.CENTER);
 frame.setSize(400, 300);
 frame.setVisible(true);
 
 }
 
 public static void main(String[] args) {
 F f = new F();
 f.y();
 f.p();
 f.o();
 
 }
 
 }
 ////

 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 public class ya implements ActionListener {
 public static String str = "";
 
 public static String a = "";
 
 public static String b = "";
 
 public static String k = "";
 
 public void actionPerformed(ActionEvent e) {
 String w = e.getActionCommand();//字
 
 if (k.equals("")) {
 a += w;
 F.show.setText(a);
 
 } else {
 b += w;
 F.show.setText(b);
 }
 
 }
 
 }
////
import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 public class Deng implements ActionListener {
 
 public void actionPerformed(ActionEvent e) {
 int a = Integer.parseInt(U.a);
 int b = Integer.parseInt(U.b);
 int c = 0;
 if (U.k.equals("+")) {
 c = a + b;
 
 } else
 
 if (U.k.equals("-")) {
 c = a - b;
 
 } else
 
 if (U.k.equals("*")) {
 c = a * b;
 
 } else
 
 if (U.k.equals("/")) {
 c = a / b;
 
 } else {
 
 }
 
 String d = String.valueOf(c);
 F.show.setText(d);
 U.a = d;
 U.b = "";
 U.k = "";
 }
 }
///

 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 public class Qing implements ActionListener {
 
 public void actionPerformed(ActionEvent e) {
 U.a = "";
 U.b = "";
 U.k = "";
 F.show.setText("");
 
 }
 
 }
///

 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 public class Qing implements ActionListener {
 
 public void actionPerformed(ActionEvent e) {
 U.a = "";
 U.b = "";
 U.k = "";
 F.show.setText("");
 
 }
 
 }
///
2
  编程太难,无法搞定。写出来一点,但无法运行。

构建之法——现代软件工程

标签:

原文地址:http://www.cnblogs.com/yuanai/p/4422989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!