• 大小: 9KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Java
  • 标签: 计算器  

资源简介

使用JAVA的图形用户界面写出来的PC版计算器,只有一个文件,代码简单,功能该有的都有

资源截图

代码片段和文件信息


package cacu;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JTextField;

public class Caulater {

static String str=““;
static int c=0flag=0;
static double b=0.0g=0.0f=0.0;

public static double suan(){
switch(c)
{
case 0:f=g;break;
case 1:f=b+g;break;
case 2:f=b-g;break;
case 3:f=b*g;break;
case 4:f=b/g;break;
}
b=f;  //可实现连加
c=0;
return f;
}

public static void main(String[] args) {


Jframe jf=new Jframe(“计算器 “);
jf.setSize(300350);
jf.setLocationRelativeTo(null);
final JTextField jtf=new JTextField(25);//显示框
JButton one=new JButton(“1“);
JButton two=new JButton(“2“);
JButton three=new JButton(“3“);
JButton four=new JButton(“4“);
JButton five=new JButton(“5“);
JButton six=new JButton(“6“);
JButton seven=new JButton(“7“);
JButton eight=new JButton(“8“);
JButton nine=new JButton(“9“);
JButton zero=new JButton(“0“);
JButton jia=new JButton(“+“);
JButton jian=new JButton(“-“);
JButton cheng=new JButton(“*“);
JButton chu=new JButton(“/“);
JButton dengyu=new JButton(“=“);
JButton tuige=new JButton(“←“);
JButton qingling=new JButton(“C“);
JButton pingfang=new JButton(“²“);
JButton kaifang=new JButton(“┌“);
JButton dian=new JButton(“.“);
JButton fu=new JButton(“±“);



one.setPreferredSize(new java.awt.Dimension(5050));//流式布局更改按钮大小
two.setPreferredSize(new java.awt.Dimension(5050));
three.setPreferredSize(new java.awt.Dimension(5050));
four.setPreferredSize(new java.awt.Dimension(5050));
five.setPreferredSize(new java.awt.Dimension(5050));
six.setPreferredSize(new java.awt.Dimension(5050));
seven.setPreferredSize(new java.awt.Dimension(5050));
eight.setPreferredSize(new java.awt.Dimension(5050));
nine.setPreferredSize(new java.awt.Dimension(5050));
zero.setPreferredSize(new java.awt.Dimension(5050));
jia.setPreferredSize(new java.awt.Dimension(4545));
jian.setPreferredSize(new java.awt.Dimension(4545));
cheng.setPreferredSize(new java.awt.Dimension(4545));
chu.setPreferredSize(new java.awt.Dimension(4545));
pingfang.setPreferredSize(new java.awt.Dimension(5050));
kaifang.setPreferredSize(new java.awt.Dimension(5050));
dian.setPreferredSize(new java.awt.Dimension(5050));
dengyu.setPreferredSize(new java.awt.Dimension(27050));
qingling.setPreferredSize(new java.awt.Dimension(5050));
tuige.setPreferredSize(new java.awt.Dimension(5050));
fu.setPreferredSize(new java.awt.Dimension(5050));


jtf.setForeground(Color.orange);

jia.setForeground(Color.green);
jian.setForeground(Color.green);
cheng.setForeground(Color.green);
chu.setForeground(Color.green);
dengyu.setBackground(Color.red);
fu.setForeground(Color.green);
dian.setForeground(Colo

评论

共有 条评论