复杂计算器的设计 JAVA我收藏的计算器代码 。自己编译一下 。应该可以满足你的要求了 。
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class calculator extends JFrame implements ActionListener
{//这里我把JFrame写成Frame,这个错误找了好久
JFrame frame;
private JButton jia=new JButton("+");
private JButton jian=new JButton("-");
private JButton cheng=new JButton("*");
private JButton chu=new JButton("/");
private JButton qiuyi=new JButton("%");
private JButton deng=new JButton("=");
private JButton fu=new JButton("+/-");
private JButton dian=new JButton(".");
private JButton kai=new JButton("sqrt");
private JButton diao=new JButton("1/x");
private JButton aa=new JButton("A");
private JButton bb=new JButton("B");
private JButton cc=new JButton("C");
private JButton dd=new JButton("D");
private JButton ee=new JButton("E");
private JButton ff=new JButton("F");
private TextField k1=new TextField();
private objConversion convert = new objConversion();
JMenuItem copy,paste,s,t,help,about,me;
JRadioButton sixteen,ten,eight,two;
JButton backspace,ce,c,num0,num1,num2,num3,num4,num5,num6,num7,num8,num9;
Container cp;
JTextField text;
String copycontent="";
boolean clickable=true,clear=true;
int all=0;
double qian;
String fuhao;
int jin=10,first=1;
public calculator()
{
setTitle("计算器-杨彩制作");
setSize(400,300);
setLocation(250,200);
text=new JTextField(25);
// text.setEnabled(false);
text.setText("0.");
text.setHorizontalAlignment(JTextField.RIGHT);//从右到左
JPanel cp1=new JPanel();
JPanel cp2=new JPanel();
JPanel cp3=new JPanel();
cp=getContentPane();
cp.add(cp1,"North");
cp.add(cp2,"Center");
cp.add(cp3,"South");
cp1.setLayout(new GridLayout(1,6));
cp2.setLayout(new GridLayout(2,4));
cp3.setLayout(new GridLayout(6,6));
sixteen=new JRadioButton("十六进制");
sixteen.setVisible(false);
ten=new JRadioButton("十进制",true);
ten.setVisible(false);
eight=new JRadioButton("八进制");
eight.setVisible(false);
two=new JRadioButton("二进制");
two.setVisible(false);
sixteen.addActionListener(this);
ten.addActionListener(this);
eight.addActionListener(this);
two.addActionListener(this);
ButtonGroup btg=new ButtonGroup();
btg.add(sixteen);
btg.add(ten);
btg.add(eight);
btg.add(two);
JTextField t3=new JTextField(25);
cp1.add(text);
// text.setEnabled(false);
text.setEditable(false);
text.setBackground(new Color(255, 255, 255));
cp2.add(sixteen);
cp2.add(ten);
cp2.add(eight);
cp2.add(two);
backspace=new JButton("Backspace");
backspace.setForeground(new Color(255,0,0));
backspace.addActionListener(this);
ce=new JButton("CE");
ce.setForeground(new Color(255,0,0));
ce.addActionListener(this);
c=new JButton("C");
c.setForeground(new Color(255,0,0));
c.addActionListener(this);
k1.setVisible(false);
cp2.add(k1);
cp2.add(backspace);
cp2.add(ce);
cp2.add(c);
num0=new JButton("0");
num1=new JButton("1");
num2=new JButton("2");
num3=new JButton("3");
num4=new JButton("4");
num5=new JButton("5");
num6=new JButton("6");
num7=new JButton("7");
num8=new JButton("8");
num9=new JButton("9");
cp3.add(num7);
num7.addActionListener(this);
cp3.add(num8);
num8.addActionListener(this);
cp3.add(num9);
num9.addActionListener(this);
cp3.add(chu);
chu.setForeground(new Color(255,0,0));
推荐阅读
- 解谜汉化版游戏,解谜游戏中文网
- chatgpt服务外包,服务外包 mp4
- 怎么下载手机版兽人游戏,手机兽人游戏有哪些
- 如何成为营销平台,如何成为营销平台经理
- linux命令行没了 linux怎么调出命令
- gis小镇软件的使用感受,arcgis小程序
- asp.net动态新闻,asp动态网页设计基于sql server 2005
- 食品直播回顾文案,食品直播开场白
- mysql不运行怎么办 mysql也不停止运行但是用不了