java小数计算器代码,计算器 小数

java 计算器代码

import java.util.Scanner;

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都网站设计、新市网络推广、成都微信小程序、新市网络营销、新市企业策划、新市品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供新市建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

public class JiSuan {

public static void main(String[] args) {

String zhanghao="765800331";//注意账号密码均为字符串类型

String mima="123456";

int isgoing=0;//当账号或密码输入错误时提示是否继续输入

String select="";//六种运算中你的选择

int result=0;//运算结果

int a=0;

int b=0;

Scanner sa = new Scanner(System.in);

do{

System.out.println("请输入你的账号:");

String zhanghao1= sa.next();

System.out.println("请输入你的密码:");

String mima1= sa.next();

if(zhanghao.equals(zhanghao1)mima.equals(mima1)){

while(zhanghao.equals(zhanghao1)mima.equals(mima1)){

System.out.println("*******************欢迎使用Java小计算器**************");

System.out.println("本计算器提供以下功能");

System.out.println("A.加法");

System.out.println("B.减法");

System.out.println("C.乘法");

System.out.println("D.除法");

System.out.println("E.a的b次幂");

System.out.println("F.退出计算器");

System.out.println("请选择:");

select= sa.next();

char c=select.charAt(0);//申明一个变量c来接收select转换成char类型的变量

switch(c){

case 'A':

System.out.println("请输入第一个数");

a = sa.nextInt();

System.out.println("请输入第二个数");

b = sa.nextInt();

result = a+b;

System.out.println("运算结果如下:"+result);

break;

case 'B':

System.out.println("请输入第一个数");

a = sa.nextInt();

System.out.println("请输入第二个数");

b = sa.nextInt();

result = a-b;

System.out.println("运算结果如下:"+result);

break;

case 'C':

System.out.println("请输入第一个数");

a = sa.nextInt();

System.out.println("请输入第二个数");

b = sa.nextInt();

result = a*b;

System.out.println("运算结果如下:"+result);

break;

case 'D':

System.out.println("请输入第一个数");

a = sa.nextInt();

System.out.println("请输入第二个数");

b = sa.nextInt();

result = a/b;

if(a%b!=0){

int m=a%b;

System.out.println("运算结果如下:"+result+" 余数:"+m);

}else{

System.out.println("运算结果如下:"+result);

}

break;

case 'E':

System.out.println("请输入第一个数");

a = sa.nextInt();

System.out.println("请输入第二个数");

b = sa.nextInt();

int i=0;//指数的底数

int sum=1;//用来接收a的b次幂的结果

for(i=0;ib;i++){

sum=sum*a;

result=sum;

}

System.out.println("运算结果如下:"+result);

break;

case 'F':

System.out.println("退出计算器");

break;

default:

System.out.println("无效输入");

break;

}

if(c=='F'){

break;

}

}

}else{

System.out.println("账号或密码输入错误!");

System.out.println("是否继续输入?(1.是0.否)");

isgoing = sa.nextInt();

}

}while(isgoing==1);

}

}

java编一个计算器的代码

界面漂亮堪比系统自带计算器,功能完美加减乘除开平方等等全部具备,还有清零按钮,小数点的使用,连加连乘功能完全参考系统官方计算器经过长期调试改进而成,马上拷贝代码拿去试试看吧,绝不后悔!

代码如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

JMenuBar menuBar = new JMenuBar();

JMenu menuFile = new JMenu();

JMenu menuFile1 = new JMenu();

JMenu menuFile2 = new JMenu();

JMenu menuFile3 = new JMenu();

JMenuItem menuFileExit = new JMenuItem();

menuFile.setText("文件");

menuFile1.setText("编辑");

menuFile2.setText("查看");

menuFile3.setText("帮助");

menuFileExit.setText("退出");

menuFileExit.addActionListener

(

new ActionListener() {

public void actionPerformed(ActionEvent e) {

CounterFrame.this.windowClosed();

}

}

);

menuFile.add(menuFileExit);

menuBar.add(menuFile);

menuBar.add(menuFile1);

menuBar.add(menuFile2);

menuBar.add(menuFile3);

setTitle("计算器");

setJMenuBar(menuBar);

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};

for(int i=0;i20;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==5||i==6||i==7||i==10||i==11||i==12||i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==17)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==18)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==4)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

text.setText(String.valueOf(Math.sqrt(cq)));

}

});

}

if(i==8)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==19)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

JButton jb1=new JButton("Backspace");

JButton jb2=new JButton(" CE ");

JButton jb3=new JButton(" C ");

this.add(jb1);

this.add(jb2);

this.add(jb3);

jb1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

String back=Tool.getinstance().getfield().getText();

text.setText(backmethod(back));

Centercenter.Vec.remove(Centercenter.Vec.size()-1);

}

});

jb3.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

text.setText("0.");

Centercenter.Vec.clear();

Centercenter.Vec.add(".");

Centercenter.vc.add("a");

Centercenter.begin="yes";

Centercenter.vc1.clear();

Centercenter.what=null;

Centercenter.tool=0;

}

});

}

public String backmethod(String str)

{

return str.substring(0,str.length()-1);

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

this.setLayout(new GridLayout(4,1,3,3));

this.add(new JButton("MC"));

this.add(new JButton("MR"));

this.add(new JButton("MS"));

this.add(new JButton("M+"));

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

---------------------------------------------------------------------------

=============《按你要求特意后改过的最简单功能的代码如下》========================

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter2 {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

setTitle("计算器");

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","4","5","6","*","1","2","3","-","0","=",".","+"};

for(int i=0;i16;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==4||i==5||i==6||i==8||i==9||i==10||i==12)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==14)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==11)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==7)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

------------------------------------------------------------

才子_辉祝您愉快!

求一份JAVA计算器源代码,要有()+-*/和清除键及小数点的,不用科学计算器

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

class CalculatorPanel extends JPanel {

private JPanel jp; // 中间的面板

private double result; // 计算结果

private boolean start; // 用于判断是否是首次输入,true首次,false不是首次

private boolean flag; // 用于判断是否清空显示区域的值,true需要,false不需要

private String lastCommand; // 用于保存运算符

JButton display; // 显示区域

public CalculatorPanel() {

// 初始化各项值

result = 0;

start = true;

flag = false;

lastCommand = "=";

// 设置CalculatorPanel这个面板的布局为框架布局

setLayout(new BorderLayout());

// 这个按钮用来显示值的区域

display = new JButton("0.0");

display.setEnabled(false);// 按钮样式设置为禁用样式

// 用来初始化,清除用的

JButton clear = new JButton("clear");

clear.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// 作初始化的操作

result = 0;

start = true;

flag = false;

lastCommand = "=";

display.setText("0.0");

}

});

jp = new JPanel();

// 将此面板布局设置为网格布局,4行4列

jp.setLayout(new GridLayout(4, 4));

// 实例化监听器对象

NumberAction na = new NumberAction();

CommandAction ca = new CommandAction();

makeButton("7", na);

makeButton("8", na);

makeButton("9", na);

makeButton("/", ca);

makeButton("4", na);

makeButton("5", na);

makeButton("6", na);

makeButton("*", ca);

makeButton("1", na);

makeButton("2", na);

makeButton("3", na);

makeButton("-", ca);

makeButton("0", na);

makeButton(".", na);

makeButton("+", ca);

makeButton("=", ca);

// 将面板,两个按键加入到我的面板,实现计算器的界面

add(display, BorderLayout.NORTH);

add(jp, BorderLayout.CENTER);

add(clear, BorderLayout.SOUTH);

}

private void makeButton(String buttonName, ActionListener al) {

JButton jb = new JButton(buttonName);

jp.add(jb);

jb.addActionListener(al);

}

// 数字监听器

private class NumberAction implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

JButton jb = (JButton) e.getSource(); // 获取事件源对象

String input = jb.getText(); // 获取事件源对象上的标签

if (start) { // 首次输入

// 一上就".",就什么也不做

if (input.equals(".")) {

return;

}

// 如果是"0.0"的话,就清空

if (display.getText().equals("0.0")) {

display.setText("");

}

start = false;// 改变是否首次输入的标记值

} else {

// 判断显示区域的值里面是否已经有".",如果有,输入的又是".",就什么都不做

if (display.getText().indexOf(".") != -1) {

if (input.equals(".")) {

return;

}

}

// 判断显示区域的值里面只有"-",输入的又是".",就什么都不做

if (display.getText().equals("-")) {

if (input.equals(".")) {

return;

}

}

// 判断显示区域的值如果是"0",输入的不是".",就什么也不做

if (display.getText().equals("0")) {

if (!input.equals(".")) {

return;

}

}

}

// 如果我点击了运算符以后,再输入数字的话,就要清空显示区域的值

if (flag) {

display.setText("");

flag = false;// 还原初始值,不需要清空

}

display.setText(display.getText() + input);// 设置显示区域的值

}

}

// 运算符监听器

private class CommandAction implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

JButton jb = (JButton) e.getSource(); // 获取事件源对象

String inputCommand = jb.getText(); // 获取事件源对象上的标签

if (start) {// 首次输入

// 一上就是"-"

if (inputCommand.equals("-")) {

display.setText("-");// 显示区域的内容设置为"-"

start = false;// 改变首次输入的标记

}

} else {

if (!flag) {// 如果flag=false不需要清空显示区的值,就调用方法计算

calculate(Double.parseDouble(display.getText()));// 保存显示区域的值,并计算

}

// 保存你点击的运算符

lastCommand = inputCommand;

flag = true;// 因为我这里已经输入过运算符,

}

}

}

// 计算用的方法

private void calculate(double x) {

if (lastCommand.equals("+")) {

result += x;

} else if (lastCommand.equals("-")) {

result -= x;

} else if (lastCommand.equals("*")) {

result *= x;

} else if (lastCommand.equals("/")) {

result /= x;

} else if (lastCommand.equals("=")) {

result = x;

}

display.setText("" + result);

}

}

class MyFrameUitl {

public static void init(JFrame jFrame, Dimension frameSize, String title,

String iconFileName, boolean resizable) {

Toolkit tk = Toolkit.getDefaultToolkit(); // 系统工具包,可以读取系统信息

Dimension screenSize = tk.getScreenSize();// 获取屏幕大小

// 获取宽高

int screenWidth = screenSize.width;

int screenHeight = screenSize.height;

// 找中心点

int centerX = screenWidth / 2;

int centerY = screenHeight / 2;

// 解析窗体大小

int frameWidth = frameSize.width;

int frameHeight = frameSize.height;

// 设置窗体位置

jFrame.setBounds(centerX - frameWidth / 2, centerY - frameHeight / 2,

frameWidth, frameHeight);

jFrame.setTitle(title);// 设置标题

if (iconFileName != null) {

jFrame.setIconImage(tk.getImage(iconFileName));// 设置图标

}

// 设置皮肤com.sun.java.swing.plaf.windows.WindowsLookAndFeel

/**/

try {

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

SwingUtilities.updateComponentTreeUI(jFrame);

} catch (Exception e1) {

e1.printStackTrace();

}

jFrame.setResizable(resizable);// 设置窗体是否可以改变大小

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置程序关闭动作

jFrame.setVisible(true);// 显示窗体

}

}

class CalculatorFrame extends JFrame {

public CalculatorFrame() {

add(new CalculatorPanel());

MyFrameUitl.init(this, new Dimension(400, 300), "简易计算器", null,

false);

this.pack();// 让组件按原始大小显示,并且窗体的大小刚好能够容纳所有的组件

}

}

public class CalculatorTest {

public static void main(String[] args) {

new CalculatorFrame();

}

}

运行结果:


分享文章:java小数计算器代码,计算器 小数
网页路径:http://csdahua.cn/article/hdpcde.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流