资源简介
java Swing实现计算器源码
代码片段和文件信息
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends WindowAdapter implements ActionListener KeyListener
{
double dResult=0;
double dNowInput=0;
double dMemory;
int n=0;
int nOperation=1;
int nBitsNum=0;
char ch;
boolean alreadyHaveDot=false;
boolean keyAvailable=true;
boolean alreadyClickedEqueal=false;
boolean isTempNowInput=false;
Jframe f;
Panel p1p2p3p4p5p6;
TextField tf1tf2;
Button b1b2b3b4b5b6b7b8b9b0;
Button bDivbSqrtbMultibMinusbPercentbPlusbReciprocalbEqualbDotbNegative;
Button bBackspacebCEbCbMRbMSbMCbM;
public void display()
{
f=new Jframe(“Calculator“);
f.setForeground(Color.BLUE);
f.setSize(290223);
f.setLocation(220220);
f.setBackground(Color.PINK);
f.setResizable(false);
f.setLayout(new BorderLayout(44));
p1=new Panel(new GridLayout(1355));
p2=new Panel(new GridLayout(4555));
p3=new Panel(new GridLayout(5155));
p4=new Panel(new FlowLayout());
p5=new Panel(new FlowLayout());
p6=new Panel(new FlowLayout());
p4.add(p1);
p4.add(p2);
tf1=new TextField(35);
tf1.setText(“0.“);
tf1.setEditable(false);
p5.add(tf1);
f.add(p5BorderLayout.NORTH);
f.add(p4BorderLayout.CENTER);
f.add(p3BorderLayout.WEST);
tf1.addKeyListener(this);
b1=new Button(“1“);
b2=new Button(“2“);
b3=new Button(“3“);
b4=new Button(“4“);
b5=new Button(“5“);
b6=new Button(“6“);
b7=new Button(“7“);
b8=new Button(“8“);
b9=new Button(“9“);
b0=new Button(“0“);
b1.setForeground(Color.BLUE);
b2.setForeground(Color.BLUE);
b3.setForeground(Color.BLUE);
b4.setForeground(Color.BLUE);
b5.setForeground(Color.BLUE);
b6.setForeground(Color.BLUE);
b7.setForeground(Color.BLUE);
b8.setForeground(Color.BLUE);
b9.setForeground(Color.BLUE);
b0.setForeground(Color.BLUE);
/*add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b0);*/
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
b1.addKeyListener(this);
b2.addKeyListener(this);
b3.addKeyListener(this);
b4.addKeyListener(th
评论
共有 条评论