JAVA实现计算器课程设计解读(7)

发布时间:2021-06-08

private JButton s1,s2,s3,s4,s5,s6,s7, s8, s9,s0,

p1,p2,t1,t2,t3,t4,clear;

private boolean end,add,sub,mul,div;

private String str;

private double num1,num2;

public CaculatorPanel()

{

namelabel = new JLabel(" 计算器"); resultField = new

JTextField(10);

ButtonListener listener = new ButtonListener(); clear = new

JButton("clear");

clear.addActionListener(listener);

s1 = new JButton("1"); s1.addActionListener(listener); s2 = new JButton("2"); s2.addActionListener(listener); s3 = new JButton("3");

s3.addActionListener(listener); s4 = new JButton("4");

s4.addActionListener(listener); s5 = new JButton("5");

s5.addActionListener(listener); s6 = new JButton("6");

s6.addActionListener(listener); s7 = new JButton("7");

s7.addActionListener(listener); s8 = new JButton("8");

s8.addActionListener(listener); s9 = new JButton("9");

s9.addActionListener(listener); s0 = new JButton("0");

s0.addActionListener(listener); p1 = new JButton(".");

p1.addActionListener(listener); p2 = new JButton("=");

p2.addActionListener(listener); t1 = new JButton("+");

t1.addActionListener(listener); t2 = new JButton("-");

t2.addActionListener(listener); t3 = new JButton("*");

t3.addActionListener(listener); t4 = new JButton("/");

t4.addActionListener(listener);

labelPanel = new JPanel(); labelPanel.add(namelabel);

labelPanel.add(resultField); labelPanel.add(clear);

numberPanel = new JPanel(); numberPanel.setLayout(new GridLayout(4,3));

numberPanel.add(s1); numberPanel.add(s2); numberPanel.add(s3);

numberPanel.add(s4); numberPanel.add(s5);

numberPanel.add(s6);

numberPanel.add(s7);

numberPanel.add(s8);

numberPanel.add(s9);

numberPanel.add(s0); numberPanel.add(p1); numberPanel.add(p2);

toolPanel = new JPanel(); toolPanel.setLayout(new GridLayout(4,1));

toolPanel.add(t1);

toolPanel.add(t2);

toolPanel.add(t3);

JAVA实现计算器课程设计解读(7).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219