java做一个计算器窗口详解教程_怎么用JAVA编写一个计算器窗口,并实现他的功能,求给出代码,对的话一定高分回报,谢谢了。。。...

展开全部

JAVA 计算器程序62616964757a686964616fe78988e69d8331333264643161

Cadev.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.LinkedList;

import java.text.NumberFormat;

import javax.swing.border.*;

public class Cadev extends JFrame implements ActionListener

{

Nbtn nbtn[];

Obtn obtn[];

Button dotbtn,PlusOrMinusbtn,Backspacebtn,

recbtn,equbtn,clbtn;

JPanel panel;

JTextField resultShow;

String Oper[]={"+","-","*","/"};

LinkedList link;

boolean sfcequ=false;

public Cadev()

{

super("计算器");

link=new LinkedList();

nbtn=new Nbtn[10];

for(int i=0;i<=9;i++)

{

nbtn[i]=new Nbtn(i);

nbtn[i].addActionListener(this);

}

obtn=new Obtn[4];

for(int i=0;i<4;i++)

{

obtn[i]=new Obtn(Oper[i]);

obtn[i].addActionListener(this);

}

dotbtn=new Button(".");

PlusOrMinusbtn=new Button("+/-");

equbtn=new Button("=");

recbtn=new Button("1/x");

Backspacebtn=new Button("退格");

clbtn=new Button("C");

recbtn.setForeground(Color.blue);

dotbtn.setForeground(Color.blue);

PlusOrMinusbtn.setForeground(Color.blue);

equbtn.setForeground(Color.red);

Backspacebtn.setForeground(Color.red);

clbtn.setForeground(Color.red);

dotbtn.addActionListener(this);

PlusOrMinusbtn.addActionListener(this);

equbtn.addActionListener(this);

recbtn.addActionListener(this);

Backspacebtn.addActionListener(this);

clbtn.addActionListener(this);

resultShow=new JTextField(10);

resultShow.setHorizontalAlignment(JTextField.RIGHT);

resultShow.setFont(new Font("TimesRoman",Font.PLAIN,14));

resultShow.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

resultShow.setBackground(Color.white);

resultShow.setEditable(false);

panel=new JPanel();

panel.setLayout(new GridLayout(4,5));

panel.add(nbtn[1]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值