java简单计算器源代码

合集下载

JAVA简易计算器程序源代码

JAVA简易计算器程序源代码

JAVA简易计算器程序源代码

package myText;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import javax.swing.border.*;

public class Calculator extends JFrame implements ActionListener{ private JPanel Panel1=new JPanel();

private JPanel Panel2=new JPanel();

private JTextField tfResult=new JTextField(25);

private JLabel label=new JLabel("计算结果:");

private String recentOperation=null;

private String recentNum=null;

private boolean isNew=true;

public void addButton(Container c,String s){

JButton b=new JButton(s);

b.setFont(new java.awt.Font("SansSerif",0,12));

b.setForeground(Color.red);

b.setBorder(BorderFactory.createRaisedBevelBorder());

c.add(b);

b.addActionListener(this);

计算器的Java源代码

计算器的Java源代码

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class Calculator extends JFrame implements ActionListener{JPanel panel1=new JPanel();JPanel panel2=new JPanel();JTextField tfMemory=new JTextField();JTextField tfResult=new JTextField();//定义数字按键JButton button_0=new JButton();JButton button_1=new JButton();JButton button_2=new JButton();JButton button_3=new JButton();JButton button_4=new JButton();JButton button_5=new JButton();JButton button_6=new JButton();JButton button_7=new JButton();JButton button_8=new JButton();JButton button_9=new JButton();//定义四则运算按键JButton button_add=new JButton();JButton button_sub=new JButton();JButton button_mul=new JButton();JButton button_div=new JButton();JButton button_dot=new JButton();JButton button_equal=new JButton();//定义三角函数按键JButton button_sin=new JButton();JButton button_cos=new JButton();JButton button_tan=new JButton();//定义其他运算按键JButton button_sqrt=new JButton();JButton button_daoshu=new JButton();JButton button_pow=new JButton();//定义域存储器相关的按键JButton button_MC=new JButton();JButton button_MR=new JButton();JButton button_MS=new JButton();JButton button_MPlus=new JButton();JButton button_MMinus=new JButton();//定义两个常数按键JButton button_PI=new JButton();JButton button_E=new JButton();//定义符号键和清零键JButton button_sign=new JButton();JButton button_CE=new JButton();//定义布局方式GridLayout grid1=new GridLayout();GridBagLayout gridbag1=new GridBagLayout();GridBagLayout gridbag2=new GridBagLayout();//保存最近一次运算符String recentOperation=null;//保存最近一次的运算数据String recentNum=null;//描述当前输入状态,是重新输入还是接在后面,重新输入时为trueboolean isNew=true;public Calculator(){//为按键注册监听器button_0.addActionListener(this);button_1.addActionListener(this);button_2.addActionListener(this);button_3.addActionListener(this);button_4.addActionListener(this);button_5.addActionListener(this);button_6.addActionListener(this);button_7.addActionListener(this);button_8.addActionListener(this);button_9.addActionListener(this);button_add.addActionListener(this);button_sub.addActionListener(this);button_mul.addActionListener(this);button_div.addActionListener(this);button_dot.addActionListener(this);button_equal.addActionListener(this);button_sin.addActionListener(this);button_cos.addActionListener(this);button_tan.addActionListener(this);button_sqrt.addActionListener(this);button_daoshu.addActionListener(this);button_pow.addActionListener(this);button_MC.addActionListener(this);

java简易计算器代码

java简易计算器代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ComputerJFrame extends JFrame implements ActionListener {

Panel panel = new Panel(new GridLayout(5,4,5,5));//面板采用网格布局 JTextField text=new JTextField("0");

double result=0;

char ch='#';

boolean can=false;

public class WindowCloser extends WindowAdapter{

p ublic void windowClosing(WindowEvent we)

{System.exit(0);}

}

public ComputerJFrame(){

super("计算器");

this.setSize(280,210);

this.setLocation(300,240);

this.setDefaultCloseOperation(EXIT_ON_CLOSE); //单击窗口关闭按钮时,结束程序运行

setLayout(new BorderLayout());//将text和panel进行边布局

add("North",text);

text.setHorizontalAlignment(JTextField.RIGHT);

text.setEditable(false);

java简单计算器--代码

java简单计算器--代码

//中南民大08网工二班mzimport java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.JOptionPane;public class Calculator extends Applet implements ActionListener{Button backButton=new Button("退格");Button clearButton=new Button("清除");Panel p1 = new Panel(new FlowLayout());Panel p2 = new Panel(new GridLayout(2,1));Panel p3 = new Panel(new GridLayout(4,5,5,5));TextField t=new TextField("0");float num1=0;char ch='#';boolean can=false;public void init(){t.setFont(new Font("宋体",Font.BOLD,25));backButton.setFont(new Font("黑体",Font.BOLD,15));backButton.setForeground(Color.red);clearButton.setFont(new Font("黑体",Font.BOLD,15));clearButton.setForeground(Color.red);p1.add(backButton);p1.add(clearButton);backButton.addActionListener(this);clearButton.addActionListener(this);p2.add(t);p2.add(p1);p2.setBackground(Color.black);p3.setBackground(Color.black);this.setLayout(new BorderLayout());this.add(p2,"North");this.add(p3,"Center");String buttonStr = "789/A456*B123-C0.D+=";for (int i = 0; i < buttonStr.length(); i++)this.addButton(p3,buttonStr.substring(i, i + 1));}private void addButton(Container c, String s){Button b = new Button(s);if (s.equals("A"))b.setLabel("sqrt");else if (s.equals("B"))b.setLabel("1/x");else if (s.equals("C"))b.setLabel("%");else if (s.equals("D"))b.setLabel("+/-");b.setForeground(Color.blue);b.setFont(new Font("黑体",Font.BOLD,15));c.add(b);b.addActionListener(this);}public void actionPerformed(ActionEvent e){String act=e.getActionCommand();if(e.getSource()==backButton){if(t.getText().length()>1)t.setText(t.getText().substring(0, t.getText().length()-1));else t.setText("0");return;}if(e.getSource()==clearButton){t.setText("0");ch='#';return;}if(act.equals("+/-")){if(t.getText().charAt(0)!='-')t.setText("-"+t.getText());else t.setText(t.getText().substring(1));return;}if(act.equals(".")){t.setText(t.getText()+act);return;}if(act!="1/x"&&act.charAt(0)>='0'&&act.charAt(0)<='9'){if(can){t.setText(act);can=false;}else{try{if(Float.parseFloat(t.getText())==0){if(t.getText().equals("0."))t.setText(t.getText()+act);else t.setText(act);return;}else {t.setText(t.getText()+act);return;}}catch(NumberFormatException e1){JOptionPane.showMessageDialog(null, "输入格式错误!", "警告!",JOptionPane.ERROR_MESSAGE);return;}}}if(act.equals("+")||act.equals("-")||act.equals("*")||act.equals("/")||act.equals("%")){if(ch!='#'){try{num1=cacu(num1,ch,Float.parseFloat(t.getText()));t.setText(String.valueOf(num1));ch=act.charAt(0);can=true;return;}catch(NumberFormatException e1){JOptionPane.showMessageDialog(null, "输入格式错误!", "警告!",JOptionPane.ERROR_MESSAGE);return;}}else{try{num1=Float.parseFloat(t.getText());ch=act

JAVA编写的计算器源代码

JAVA编写的计算器源代码

JAVA编写的计算器源代码// Calculator.java

import javax.swing.*; // 引入swing库

import java.awt.*; // 引入awt库

import java.awt.event.*; // 引入awt.event库

public class Calculator extends JFrame implements ActionListener

//定义按钮

private JButton zero;

private JButton one;

private JButton two;

private JButton three;

private JButton four;

private JButton five;

private JButton six;

private JButton seven;

private JButton eight;

private JButton nine;

private JButton point;

private JButton equal; private JButton plus; private JButton minus; private JButton multiply; private JButton divide; private JButton backspace; private JButton ac;

private JButton ce;

private JButton sqrt; private JButton sqr;

java编写计算器源代码

java编写计算器源代码

计算器的制作

import java.awt.*;

import java.awt.event.*;

class ComputerExe extends Frame implements ActionListener {

Button b1,b2,b3,b4;

TextField t1,t2,t3;

Label l1,l2;

public static void main(String[] args)//程序入口

{

new ComputerExe();//创建本窗体对象

}

ComputerExe()//构造方法

{

super("四则运算");

setBounds(100,100,300,200);

setVisible(true);

b1=new Button("加");

b2=new Button("减");

b3=new Button("乘");

b4=new Button("除");

t1=new TextField(15);

t2=new TextField(15);

t3=new TextField(15);

l1=new Label("");

l2=new Label("=");

l1.setBackground(Color.yellow);

l1.setForeground(Color.red);

l2.setBackground(Color.yellow);

l2.setForeground(Color.red);

t3.setEditable(false);

setLayout(new FlowLayout());//更改窗体框架的布局

java语言写的计算器源代码附解析

java语言写的计算器源代码附解析

//把代码改成Calc.java编译运行,完整版计算器,最下面是计算器界面

import java.awt.*;

import java.awt.event.*;

public class Calc extends WindowAdapter implements ActionListener, MouseListener

{

Color cMoveOut=new Color(240 ,240 ,240);

Color cMoveIn =new Color( 255,255,55);

//状态变量

boolean clicked=true;//判断是否单击了小数点

boolean clear=true;//判断是否单击了符号位

double previous;//记录第一个操作数

double next;//记录第二个操作数

String fuhao;//记录符号位

int first=1;//标记是否开始一次新的运算过程

Frame f;

Panel p1,p2;

TextField tf;

Font fnt;

Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0;

Button bDiv,bSqrt,bMulti,bMinus,bPercent,bPlus,bReciprocal,bEqual,bDot,bNegative,bBack;

Button bPingFang , bDaoShu , bSin, bCos ,bTan;

Button bC;

GridLayout p2Layout;

public void display()

简易计算器源代码--java

简易计算器源代码--java

package calculator;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.math.BigDecimal;

import javax.swing.*;

public class Operation extends JFrame implements ActionListener{

/**

*

*/

private static final long serialVersionUID = 1L;

private final String str[] = {"7","8","9","/","4","5","6","*","1","2", "3","-",".","0","=","+"};

private final JButton[] JB = new JButton[str.length];

private final JButton reset = new JButton("CE");

private final JTextField display = new JTextField("");

Operation(){

super("计算器");

JPanel panel1 = new JPanel(new BorderLayout());

JPanel panel2 = new JPanel(new GridLayout(4,4));

panel1.add(BorderLayout.CENTER, display);

Java实现计算器

Java实现计算器

Java实现简易计算器,可以计算算术表达式:

Java源码如下:

//GridFrame.java文件

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

//计算机框架布局

public class GridFrame extends JFrame{

//定义面板,并设置为网格布局,4行4列,组件水平、垂直间距均为3

JPanel p=new JPanel(new GridLayout(5,4,3,3));

JTextArea out=new JTextArea();//定义文本框

String temp="";

//定义字符串数组,为按钮的显示文本赋值

//注意字符元素的顺序与循环添加按钮保持一致

String

str[]={"C","(",")","BS","7","8","9","/","4","5","6"," *","1","2","3","-","0",".","=","+"};

JButton btn[]=new JButton[str.length]; //声明按钮数组

public GridFrame(String s){

super(s);//为窗体名称赋值

setLayout(new BorderLayout());//定义窗体布局为边界布局

//循环定义按钮,并添加到面板中

for(int i=0;i

btn[i]=new JButton(str[i]);

计算器源码java版

计算器源码java版

package package6;

import java.awt.*;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.text.DecimalFormat;

import javax.swing.*;

public class counter implements MouseListener, WindowListener {

private JFrame f;

private JButton btn0;

private JButton btn1;

private JButton btn2;

private JButton btn3;

private JButton btn4;

private JButton btn5;

private JButton btn6;

private JButton btn7;

private JButton btn8;

private JButton btn9;

JAVA计算器源代码

JAVA计算器源代码

计算器源代码

一、计算器源代码文件名:computer1.java

import java.awt.*;

import java.awt.event.*;

public class computer1 extends Frame implements ActionListener{

//声明窗口类并实现动作事件接口。Button n0,n1,n2,n3,n4,n5,n6,n7,n8,n9;//声明数字按钮

Button op,os,om,od,oe,oc;//声明操作按钮

TextField tfd;//声明文本框

String flg,rslt;//声明标志串、结果串

Panel p1,p2,p3;//声明面板

int i1,i2;

float flt;

computer1(){

super("加减乘除计算器");

n0 = new Button("0");//实现各按钮

n1 = new Button("1");

n2 = new Button("2");

n3 = new Button("3");

n4 = new Button("4");

n5 = new Button("5");

n6 = new Button("6");

n7 = new Button("7");

n8 = new Button("8");

n9 = new Button("9");

op = new Button("加");

os = new Button("减");

om = new Button("乘");

od = new Button("除");

简单的计算器源代码

简单的计算器源代码

//计算器,已经编译通过

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class testZ extends JFrame implements ActionListener{

private JPanel jPanel1,jPanel2;

private JTextField resultField;

private JButton s1,s2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,f1,f2; private boolean end,add,sub,mul,div;

private String str;

private double num1,num2;

public testZ(){

super("计算器");

setSize(300,240);

Container con=getContentPane();

con.setLayout(new BorderLayout());

jPanel1=new JPanel();

jPanel1.setLayout(new GridLayout(1,1));

jPanel2=new JPanel();

jPanel2.setLayout(new GridLayout(4,4));

resultField=new JTextField("0");

jPanel1.add(resultField);

con.add(jPanel1,BorderLayout.NORTH);

Java计算器源码

Java计算器源码

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

import java.awt.*;

import java.awt.event.*;

/**

*

* @author cjwxxq10000

*/

class CalcAppDemo extends Frame{

private TextField t_result;

private Panel p_main;//主面板

private Panel p_num;//数字面板

private Panel p_oper;//操作符面板

private Panel p_show;//显示面板

private Button b_num[];//数字按钮

private Button b_oper[];//操作符按钮

public CalcAppDemo(String title){

setTitle(title);

t_result=new TextField("0.0",21);//定义TextField的初始值为String类"0.0",占用21列

p_main=new Panel();

p_num=new Panel();

p_oper=new Panel();

p_show=new Panel();

p_main.setLayout(new BorderLayout());

p_num.setLayout(new GridLayout(4,3,1,1));

java简单计算器代码

java简单计算器代码

java简单计算器代码

Java简单计算器代码:

```java

import java.util.Scanner;

public class Calculator {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

double num1, num2, result = 0;

char operator;

System.out.print("请输入第一个数:");

num1 = input.nextDouble();

System.out.print("请输入运算符号(+、-、*、/):"); operator = input.next().charAt(0);

System.out.print("请输入第二个数:");

num2 = input.nextDouble();

switch(operator) {

case '+':

result = num1 + num2;

break;

case '-':

result = num1 - num2;

break;

case '*':

result = num1 * num2;

break;

case '/':

result = num1 / num2;

break;

default:

System.out.println("运算符输入错误,请重新输入!");

return;

}

System.out.println("运算结果:" + num1 + operator + num2 + "=" + result);

简单的计算器java代码

简单的计算器java代码

import javax.swing.*; import javax.swing.border.Border; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.HashMap; /** * 我的计算器。MyCalculator 继承于 JFrame,是计算器的界面 */ public class MyCalculator extends JFrame { private Border border = BorderFactory.createEmptyBorder(5, 5, 5, 5); private JTextField textbox = new JTextField("0"); private CalculatorCore core = new CalculatorCore(); private ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); String label = b.getText(); String result = core.process(label); textbox.setText(result); } }; public MyCalculator(String title) throws HeadlessException { super(title); // 调用父类构造方法 setupFrame(); // 调整窗体属性 setupControls(); // 创建控件 } private void setupControls() { setupDisplayPanel(); // 创建文本面板 setupButtonsPanel(); // 创建按钮面板 } // 创建按钮面板并添加按钮 private void setupButtonsPanel() { JPanel panel = new JPanel(); panel.setBorder(border); panel.setLayout(new GridLayout(4, 5, 3, 3)); createButtons(panel, new String[]{ "7", "8", "9", "+", "C", "4", "5", "6", "-", "CE", "1", "2", "3", "*", "", // 空字符串表示这个位置没有按钮 "0", ".", "=", "/", "" }); this.add(panel, BorderLayout.CENTER); } /** * 在指定的面板上创建按钮 * * @param panel 要创建按钮的面板 * @param labels 按钮文字 */ private void createButtons(JPanel panel, String[] labels) { for (String label : labels) { // 如果 label 为空,则表示创建一个空面板。否则创建一个按钮。 if (label.equals("")) { panel.add(new JPanel()); } else { JButton b = new JButton(label); b.addActionListener(listener); // 为按钮添加侦听器 panel.add(b); } } } // 设置显示面板,用一个文本框来作为计算器的显示部分。 private void setupDisplayPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(border); setupTextbox(); panel.add(t

java版计算器源代码

java版计算器源代码

import javax.script.ScriptEngine;import javax.script.ScriptEngineManager;import javax.script.ScriptException;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Calculator extends JFrame {/*** */private static final long serialVersionUID = 1L;private JLabel jl;private JButton ok, cancel, C;private JTextField jt;private JPanel jp1, jp2;private JButton[] jb;private static String str = "";public Calculator() {jl = new JLabel("算式:");C = new JButton("清零");C.addActionListener(new Lis());jb = new JButton[25];jb[0] = new JButton("+");jb[1] = new JButton("-");jb[2] = new JButton("*");jb[3] = new JButton("/");jb[4] = new JButton(".");jb[5] = new JButton("sin");jb[6] = new JButton("cos");jb[7] = new JButton("tan");jb[8] = new JButton("aqrt");jb[9] = new JButton("x^2");jb[10] = new JButton("1/x");jb[11] = new JButton("ln");jb[12] = new JButton("log");jb[13] = new JButton("(");jb[14] = new JButton(")");ok = new JButton("确认");cancel = new JButton("删除 ");jt = new JTextField(15);jp1 = new JPanel();jp2 = new JPanel();for (int i = 0; i < 15; i++) {jb[i].addActionListener(new Lis());}for (int i = 15; i < 25; i++) {jb[i] = new JButton(new Integer(i - 15).toString());jb[i].addActionListener(new Lis());}ok.addActionListener(new Lis());cancel.addActionListener(new Lis());}public void launchFrame() {Container c = getContentPane();GridLayout gl = new GridLayout(7, 4, 2, 2);jp1.add(jl);jp1.add(jt);jp2.setLayout(gl);jp2.add(jb[5]);jp2.add(jb[6]);jp2.add(jb[7]);jp2.add(jb[8]);jp2.add(jb[22]);jp2.add(jb[23]);jp2.add(jb[24]);jp2.add(jb[0]);jp2.add(jb[19]);jp2.add(jb[20]);jp2.add(jb[21]);jp2.add(jb[1]);jp2.add(jb[16]);jp2.add(jb[17]);jp2.add(jb[18]);jp2.add(jb[2]);jp2.add(jb[15]);jp2.add(jb[4]);jp2.add(jb[10]);jp2.add(jb[3]);jp2.add(jb[13]);jp2.add(jb[14]);jp2.add(jb[11]);jp2.add(jb[12]);jp2.add(jb[9]);jp2.add(ok);jp2.add(cancel);jp2.add(C);jp2.add(ok);jp2.add(cancel);c.add(jp1, "North");c.add(jp2, "Center");setTitle("简单计算器");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(300, 300);setVisible(true);}class Lis implements ActionListener {public void actionPerformed(ActionEvent e) {Object source = e.getSource();double d = 0.0;if (source == ok) {ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript");try {d = (Double) se.eval(str);} catch (ScriptException j) {JOptionPane.showMessageDialog(null, "您输入不规范!", "错误提示!",JOptionPane.ERROR_MESSAGE);}jt.setText(str = Double.toString(d));} else if (source == jb[5]) {d = (Double) Math.si

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
buttonsin,buttontozero;//新建按钮“+”“-”“*”“/”“sin”和归零按钮
JButton buttonone,buttontwo,buttonthree,buttonfour,buttonfive,buttonsix,
buttonseven,buttoneight,buttonnine;//新建数字按钮“0”“1”“2”“3”“4”“5”“6”“7”“8”“9”
package calcultorthree;
import java.awt.BorderLayout;//导入边界布局管理器类
import java.awt.GridLayout;//导入网格布局管理器类
import java.awt.TextField;//导入文本区域类
import java.awt.event.ActionEvent;//导入事件类
//将数字按钮添加到中间面板
panelcenter.add(buttonone);
panelcenter.add(buttontwo);
panelcenter.add(buttonthree);
panelcenter.add(buttonfour);
panelcenter.add(buttonfive);
* @author Fjsh
*/
public class CalcultorThree {
//新建对象,在构造函数中进行初始化
JFrame frame;//新建窗体对象
JButton buttonzero,buttondot,buttonequal;//新建按钮“0”“.”“=”
JButton buttonplus,buttonminus,buttonmultiple,buttondevision,
import java.awt.event.ActionListener;//导入事件监听者类
import javax.swing.JButton;//导入按钮类
import javax.swing.JFrame;//导入窗体
import javax.swing.JPanel;//导入面板
/**
*本例实现了简单计算器代码,具备加减乘除和正弦功能,旨在抱砖引玉。熟悉java的同学,可以在此基础上实现更复杂的功能。
panelwest.setLayout(new GridLayout(3,1));
panelwest.add(buttonzero);
panelwest.add(buttondot);
panelwest.add(buttonequal);
//构造操作按钮“+”“-”“*”“/”“sin”“>0”,其中“>0”为归零按钮
buttondot=new JButton(".");
buttonequal=new JButton("=");
buttonzero.addActionListener(h);
buttondot.addActionListener(h);
buttonequal.addActionListener(h);
buttonsix=new JButton("6");
buttonseven=new JButton("7");
buttoneight=new JButton("8");
buttonnine=new JButton("9");
panelcenter.setLayout(new GridLayout(3,3));//设置面板布局为网格布局,3行3列
JPanel panelwest,panelcenter,paneleast;//新建三个面板
TextField tf;//新建文本区域对象
public CalcultorThree(){
//初始化对象
tf=new TextField(30);//构造空文本字段,字符宽度为30
frame =new JFrame("CalculatorThree");//构造窗体对象,名称为“CalculatorThree”
buttontwo.addActionListener(h);
buttonthree.addActionListener(h);
buttonfour.addActionListener(h);
buttonfive.addActionListener(h);
buttonsix.addActionListener(h);
panelcenter.add(buttonsix);
panelcenter.add(buttonseven);
panelcenter.add(buttoneight);
panelcenter.add(buttonnine);
//为10个按钮注册事件监听器
buttonone.addActionListener(h);
buttonseven.addActionListener(h);
buttoneight.addActionListener(h);
buttonnine.addActionListener(h);
//构造按钮“0”“.”“=”,注册事件监听器,设置1行3列的布局,添加到到西边的面板
buttonzero=new JButton("0");
panelcenter=new JPanel();//构造面板,放到窗体中央
panelwest=new JPanel();//构造面板Leabharlann Baidu放到窗体西边
paneleast=new JPanel();//构造面板,放到窗体东边
Handle h=new Handle();//新建Handle类对象,Handle类为事件监听类
buttonplus=new JButton("+");
buttonminus=new JButton("-");
buttonmultiple=new JButton("*");
//创建数字按钮对象,1、2、3、4、5、6、7、8、9
buttonone=new JButton("1");
buttontwo=new JButton("2");
buttonthree=new JButton("3");
buttonfour=new JButton("4");
buttonfive=new JButton("5");
相关文档
最新文档