JAVA期末作业``高手来帮忙啊!
用JAVA编写一个简单计算器要求:1.组件定义:0~9,+-*/,C=按钮;显示屏文本行;菜单;2.布局管理:使用布局管理类对控件的位置布局进行管理;3.事件处理:能关闭...
用JAVA编写一个简单计算器
要求:
1. 组件定义:0~9,+-*/,C=按钮;显示屏文本行;菜单;
2. 布局管理:使用布局管理类对控件的位置布局进行管理;
3. 事件处理:能关闭窗口;点击按钮,会在显示屏上输出结果。
更重要的是要让我能在上面添加上我的名字和学号`` 展开
要求:
1. 组件定义:0~9,+-*/,C=按钮;显示屏文本行;菜单;
2. 布局管理:使用布局管理类对控件的位置布局进行管理;
3. 事件处理:能关闭窗口;点击按钮,会在显示屏上输出结果。
更重要的是要让我能在上面添加上我的名字和学号`` 展开
展开全部
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Calculator {
public static void main(String[] args) {
MainFrame objMainFrame=new MainFrame();
objMainFrame.setVisible(true);
}
}
class MainFrame extends JFrame {
public boolean flag;
public String str1;
public String str2;
public String action;
public MainFrame() {
Dimension dim1 = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim2 = this.getSize();
int x = (dim1.width - dim2.width) / 2;
int y = (dim1.height - dim2.height) / 2;
this.setLocation(x, y);
this.setSize(400, 400);
this.setTitle("计算器:007/邦德");
JPanel contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JTextField txtResult = new JTextField();
txtResult.setBounds(2, 0, 208, 30);
txtResult.setText("");
txtResult.setFocusable(true);
JButton btn1 = new JButton();
btn1.setBounds(2, 116, 50, 40);
btn1.setText("1");
btn1.addMouseListener(new MouseAction(txtResult, btn1));
JButton btn2 = new JButton();
btn2.setBounds(54, 116, 50, 40);
btn2.setText("2");
btn2.addMouseListener(new MouseAction(txtResult, btn2));
JButton btn3 = new JButton();
btn3.setBounds(106, 116, 50, 40);
btn3.setText("3");
btn3.addMouseListener(new MouseAction(txtResult, btn3));
JButton btn4 = new JButton();
btn4.setBounds(2, 74, 50, 40);
btn4.setText("4");
btn4.addMouseListener(new MouseAction(txtResult, btn4));
JButton btn5 = new JButton();
btn5.setBounds(54, 74, 50, 40);
btn5.setText("5");
btn5.addMouseListener(new MouseAction(txtResult, btn5));
JButton btn6 = new JButton();
btn6.setBounds(106, 74, 50, 40);
btn6.setText("6");
btn6.addMouseListener(new MouseAction(txtResult, btn6));
JButton btn7 = new JButton();
btn7.setBounds(2, 32, 50, 40);
btn7.setText("7");
btn7.addMouseListener(new MouseAction(txtResult, btn7));
JButton btn8 = new JButton();
btn8.setBounds(54, 32, 50, 40);
btn8.setText("8");
btn8.addMouseListener(new MouseAction(txtResult, btn8));
JButton btn9 = new JButton();
btn9.setBounds(106, 32, 50, 40);
btn9.setText("9");
btn9.addMouseListener(new MouseAction(txtResult, btn9));
JButton btnPlus = new JButton();
btnPlus.setBounds(158, 32, 50, 40);
btnPlus.setText("+");
btnPlus.addMouseListener(new MouseOperate(txtResult, "plus"));
JButton btnSub = new JButton();
btnSub.setBounds(158, 74, 50, 40);
btnSub.setText("-");
btnSub.addMouseListener(new MouseOperate(txtResult, "sub"));
JButton btnDiv = new JButton();
btnDiv.setBounds(158, 116, 50, 40);
btnDiv.setText("/");
btnDiv.addMouseListener(new MouseOperate(txtResult, "div"));
JButton btnPro = new JButton();
btnPro.setBounds(158, 158, 50, 40);
btnPro.setText("*");
btnPro.addMouseListener(new MouseOperate(txtResult, "pro"));
JButton btn0 = new JButton();
btn0.setBounds(2, 158, 50, 40);
btn0.setText("0");
btn0.addMouseListener(new MouseAction(txtResult, btn0));
JButton btnClear = new JButton();
btnClear.setBounds(54, 158, 50, 40);
btnClear.setText("C");
btnClear.addMouseListener(new MouseDelete(txtResult));
JButton btnAnswer = new JButton();
btnAnswer.setBounds(106, 158, 50, 40);
btnAnswer.setText("=");
btnAnswer.addMouseListener(new MouseResult(txtResult));
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("信息");
menuBar.add(menu);
JMenuItem openItem1 = new JMenuItem("学号:007");
menu.add(openItem1);
JMenuItem openItem2 = new JMenuItem("姓名:邦德");
menu.add(openItem2);
contentPane.add(txtResult);
contentPane.add(btn0);
contentPane.add(btn1);
contentPane.add(btn2);
contentPane.add(btn3);
contentPane.add(btn4);
contentPane.add(btn5);
contentPane.add(btn6);
contentPane.add(btn7);
contentPane.add(btn8);
contentPane.add(btn9);
contentPane.add(btnDiv);
contentPane.add(btnPro);
contentPane.add(btnPlus);
contentPane.add(btnSub);
contentPane.add(btnClear);
contentPane.add(btnAnswer);
}
class MouseAction extends MouseAdapter {
JTextField txtResult = new JTextField();
JButton btnResult = new JButton();
public MouseAction(JTextField txtResult, JButton btnResult) {
this.txtResult = txtResult;
this.btnResult = btnResult;
}
public void mouseClicked(MouseEvent e) {
if (flag) {
txtResult.setText(btnResult.getText());
flag = false;
} else {
txtResult.setText(txtResult.getText() + btnResult.getText());
}
}
}
class MouseDelete extends MouseAdapter {
JTextField txtResult = new JTextField();
public MouseDelete(JTextField txtResult) {
this.txtResult = txtResult;
}
public void mouseClicked(MouseEvent e) {
txtResult.setText("");
}
}
class MouseOperate extends MouseAdapter {
JTextField txtResult = new JTextField();
String lable;
public MouseOperate(JTextField txtResult, String lable) {
this.txtResult = txtResult;
this.lable = lable;
}
public void mouseClicked(MouseEvent e) {
action = lable;
str1 = txtResult.getText();
txtResult.setText("");
}
}
class MouseResult extends MouseAdapter {
int num1;
int num2;
int result;
JTextField txtResult = new JTextField();
public MouseResult(JTextField txtResult) {
this.txtResult = txtResult;
}
public void mouseClicked(MouseEvent e) {
str2 = txtResult.getText();
num1 = Integer.parseInt(str1);
num2 = Integer.parseInt(str2);
if (action.equals("plus")) {
result = num1 + num2;
} else if (action.equals("div")) {
result = num1 / num2;
} else
if (action.equals("sub")) {
result = num1 - num2;
} else {
result = num1 * num2;
}
txtResult.setText("" + result);
flag = true;
}
}
}
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Calculator {
public static void main(String[] args) {
MainFrame objMainFrame=new MainFrame();
objMainFrame.setVisible(true);
}
}
class MainFrame extends JFrame {
public boolean flag;
public String str1;
public String str2;
public String action;
public MainFrame() {
Dimension dim1 = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim2 = this.getSize();
int x = (dim1.width - dim2.width) / 2;
int y = (dim1.height - dim2.height) / 2;
this.setLocation(x, y);
this.setSize(400, 400);
this.setTitle("计算器:007/邦德");
JPanel contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JTextField txtResult = new JTextField();
txtResult.setBounds(2, 0, 208, 30);
txtResult.setText("");
txtResult.setFocusable(true);
JButton btn1 = new JButton();
btn1.setBounds(2, 116, 50, 40);
btn1.setText("1");
btn1.addMouseListener(new MouseAction(txtResult, btn1));
JButton btn2 = new JButton();
btn2.setBounds(54, 116, 50, 40);
btn2.setText("2");
btn2.addMouseListener(new MouseAction(txtResult, btn2));
JButton btn3 = new JButton();
btn3.setBounds(106, 116, 50, 40);
btn3.setText("3");
btn3.addMouseListener(new MouseAction(txtResult, btn3));
JButton btn4 = new JButton();
btn4.setBounds(2, 74, 50, 40);
btn4.setText("4");
btn4.addMouseListener(new MouseAction(txtResult, btn4));
JButton btn5 = new JButton();
btn5.setBounds(54, 74, 50, 40);
btn5.setText("5");
btn5.addMouseListener(new MouseAction(txtResult, btn5));
JButton btn6 = new JButton();
btn6.setBounds(106, 74, 50, 40);
btn6.setText("6");
btn6.addMouseListener(new MouseAction(txtResult, btn6));
JButton btn7 = new JButton();
btn7.setBounds(2, 32, 50, 40);
btn7.setText("7");
btn7.addMouseListener(new MouseAction(txtResult, btn7));
JButton btn8 = new JButton();
btn8.setBounds(54, 32, 50, 40);
btn8.setText("8");
btn8.addMouseListener(new MouseAction(txtResult, btn8));
JButton btn9 = new JButton();
btn9.setBounds(106, 32, 50, 40);
btn9.setText("9");
btn9.addMouseListener(new MouseAction(txtResult, btn9));
JButton btnPlus = new JButton();
btnPlus.setBounds(158, 32, 50, 40);
btnPlus.setText("+");
btnPlus.addMouseListener(new MouseOperate(txtResult, "plus"));
JButton btnSub = new JButton();
btnSub.setBounds(158, 74, 50, 40);
btnSub.setText("-");
btnSub.addMouseListener(new MouseOperate(txtResult, "sub"));
JButton btnDiv = new JButton();
btnDiv.setBounds(158, 116, 50, 40);
btnDiv.setText("/");
btnDiv.addMouseListener(new MouseOperate(txtResult, "div"));
JButton btnPro = new JButton();
btnPro.setBounds(158, 158, 50, 40);
btnPro.setText("*");
btnPro.addMouseListener(new MouseOperate(txtResult, "pro"));
JButton btn0 = new JButton();
btn0.setBounds(2, 158, 50, 40);
btn0.setText("0");
btn0.addMouseListener(new MouseAction(txtResult, btn0));
JButton btnClear = new JButton();
btnClear.setBounds(54, 158, 50, 40);
btnClear.setText("C");
btnClear.addMouseListener(new MouseDelete(txtResult));
JButton btnAnswer = new JButton();
btnAnswer.setBounds(106, 158, 50, 40);
btnAnswer.setText("=");
btnAnswer.addMouseListener(new MouseResult(txtResult));
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("信息");
menuBar.add(menu);
JMenuItem openItem1 = new JMenuItem("学号:007");
menu.add(openItem1);
JMenuItem openItem2 = new JMenuItem("姓名:邦德");
menu.add(openItem2);
contentPane.add(txtResult);
contentPane.add(btn0);
contentPane.add(btn1);
contentPane.add(btn2);
contentPane.add(btn3);
contentPane.add(btn4);
contentPane.add(btn5);
contentPane.add(btn6);
contentPane.add(btn7);
contentPane.add(btn8);
contentPane.add(btn9);
contentPane.add(btnDiv);
contentPane.add(btnPro);
contentPane.add(btnPlus);
contentPane.add(btnSub);
contentPane.add(btnClear);
contentPane.add(btnAnswer);
}
class MouseAction extends MouseAdapter {
JTextField txtResult = new JTextField();
JButton btnResult = new JButton();
public MouseAction(JTextField txtResult, JButton btnResult) {
this.txtResult = txtResult;
this.btnResult = btnResult;
}
public void mouseClicked(MouseEvent e) {
if (flag) {
txtResult.setText(btnResult.getText());
flag = false;
} else {
txtResult.setText(txtResult.getText() + btnResult.getText());
}
}
}
class MouseDelete extends MouseAdapter {
JTextField txtResult = new JTextField();
public MouseDelete(JTextField txtResult) {
this.txtResult = txtResult;
}
public void mouseClicked(MouseEvent e) {
txtResult.setText("");
}
}
class MouseOperate extends MouseAdapter {
JTextField txtResult = new JTextField();
String lable;
public MouseOperate(JTextField txtResult, String lable) {
this.txtResult = txtResult;
this.lable = lable;
}
public void mouseClicked(MouseEvent e) {
action = lable;
str1 = txtResult.getText();
txtResult.setText("");
}
}
class MouseResult extends MouseAdapter {
int num1;
int num2;
int result;
JTextField txtResult = new JTextField();
public MouseResult(JTextField txtResult) {
this.txtResult = txtResult;
}
public void mouseClicked(MouseEvent e) {
str2 = txtResult.getText();
num1 = Integer.parseInt(str1);
num2 = Integer.parseInt(str2);
if (action.equals("plus")) {
result = num1 + num2;
} else if (action.equals("div")) {
result = num1 / num2;
} else
if (action.equals("sub")) {
result = num1 - num2;
} else {
result = num1 * num2;
}
txtResult.setText("" + result);
flag = true;
}
}
}
展开全部
写姓名和学号的地方已经标注出来了,你自己可以在源码中自己修改!
import java.util.*;
public class Caculator extends JFrame{
private JTextField display;
private JPanel panel;
private JPanel panel1;
String k="";
String x="";
String y="";
public Caculator(){
super("写姓名和学号的地方");//修改姓名和学号的地方
Container container=getContentPane();
container.setLayout(new BorderLayout());
//计算器的显示窗口
panel1=new JPanel();
panel1.setLayout(new BorderLayout());
display=new JTextField();
display.setEditable(true);
display.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
display.getText();
}
});
panel1.add(display);
container.add(panel1,BorderLayout.NORTH);
panel=new JPanel();
panel.setLayout(new GridLayout(4,5,3,3));
container.add(panel,BorderLayout.SOUTH);
CreatNum("7",panel);
CreatNum("8",panel);
CreatNum("9",panel);
BackSpace("C",panel);
SingleOperator("sqrt",panel);
CreatNum("4",panel);
CreatNum("5",panel);
CreatNum("6",panel);
CreateOperator("*",panel);
CreateOperator("/",panel);
CreatNum("1",panel);
CreatNum("2",panel);
CreatNum("3",panel);
CreateOperator("-",panel);
SingleOperator("1/x",panel);
CreatNum("0",panel);
SingleOperator("+/-",panel);
DecimalOperator(".",panel);
CreateOperator("+",panel);
EqualOperator("=",panel);
setVisible(true);
pack();
//setSize(400,200);
}
//isTwo方法
public boolean isTwo(){
int num=0;
double outcome=0;
double num1,num2;
String array[]=new String[2];
String operator="";
//将数字字符转换成整型数
if(y!=""){
StringTokenizer token1=new StringTokenizer(x," ");
while(token1.hasMoreTokens()){
array[num]=token1.nextToken();
++num;
}
num1=Double.parseDouble(array[0]);
num2=Double.parseDouble(array[1]);
//转换符号
StringTokenizer token2=new StringTokenizer(y);
while(token2.hasMoreTokens())
operator=token2.nextToken();
//判断语句
if(operator.equals(new String("+")))
outcome=num1+num2;
else if (operator.equals(new String("-")))
outcome=num1-num2;
else if (operator.equals(new String("*")))
outcome=num1*num2;
else if (operator.equals(new String("/"))){
outcome=num1/num2;
}
//更改字符串
y="f";
k=""+outcome;
x=""+outcome;
return true;
}
else
return false;
}
//数字按钮创建
public void CreatNum(final String cn,JPanel panel){
JButton button=new JButton(cn);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k!=""&&y=="f")
{
y="";
k="";
x="";
k+=cn;
}
else
k+=cn;
x=x+cn;
display.setText(k);
}
});
panel.add(button);
}
//操作符按钮创建
public void CreateOperator(final String co,JPanel panel){
JButton button=new JButton(co);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
//isTwo();
if(y.equals(new String(""))&&(isTwo()==false)){
y=y+co+" ";
display.setText(k);
k="";
}
else if((y!="")&&(isTwo())){
isTwo();
y=y+co+" ";
display.setText(k);
k="";
}
else
{
y="";
y=y+co+"";
display.setText(k);
}
x+=" ";
}
});
panel.add(button);
}
//等于号按钮的创建
public void EqualOperator(final String eo,JPanel panel){
JButton button=new JButton(eo);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(isTwo()==true)
display.setText(k);
else
x="";
}
});
panel.add(button);
}
//单目操作符('+/-'.'Sqrt','1/x')
public void SingleOperator(final String so,JPanel panel){
JButton button=new JButton(so);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(so.equals(new String("+/-"))){
double i;
i=Double.parseDouble(k);
if(i>0){
k="-"+k;
x="-"+x;
}
else
{
k=""+(-i);
x=""+(-i);
}
display.setText(k);
}
else if(so.equals(new String("Sqrt"))){
double i;
i=Double.parseDouble(k);
if(i>0){
i=Math.sqrt(i);
k=""+i;
x=""+i;
display.setText(k);
}
else{
k="函数输入无效";
display.setText(k);
k="";
x="";
y="";
}
}
else if(so.equals(new String("1/x"))){
double i;
i=Double.parseDouble(k);
i=1/i;
k=""+i;
x=""+i;
display.setText(k);
}
}
});
panel.add(button);
}
//小数点符号的创建
public void DecimalOperator(final String dso,JPanel panel){
JButton button=new JButton(dso);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k==""||k.contains("."))
;
else
{
k=k+".";
x=x+".";
display.setText(k);
}
}
});
panel.add(button);
}
//BackSpace键的创建
public void BackSpace(final String bs,JPanel panel){
JButton button=new JButton(bs);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k=="")
;
else
{
k="";
x="";
y="";
display.setText(k);
}
}
});
panel.add(button);
}
public static void main(String args[]){
Caculator out=new Caculator();
out.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.util.*;
public class Caculator extends JFrame{
private JTextField display;
private JPanel panel;
private JPanel panel1;
String k="";
String x="";
String y="";
public Caculator(){
super("写姓名和学号的地方");//修改姓名和学号的地方
Container container=getContentPane();
container.setLayout(new BorderLayout());
//计算器的显示窗口
panel1=new JPanel();
panel1.setLayout(new BorderLayout());
display=new JTextField();
display.setEditable(true);
display.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
display.getText();
}
});
panel1.add(display);
container.add(panel1,BorderLayout.NORTH);
panel=new JPanel();
panel.setLayout(new GridLayout(4,5,3,3));
container.add(panel,BorderLayout.SOUTH);
CreatNum("7",panel);
CreatNum("8",panel);
CreatNum("9",panel);
BackSpace("C",panel);
SingleOperator("sqrt",panel);
CreatNum("4",panel);
CreatNum("5",panel);
CreatNum("6",panel);
CreateOperator("*",panel);
CreateOperator("/",panel);
CreatNum("1",panel);
CreatNum("2",panel);
CreatNum("3",panel);
CreateOperator("-",panel);
SingleOperator("1/x",panel);
CreatNum("0",panel);
SingleOperator("+/-",panel);
DecimalOperator(".",panel);
CreateOperator("+",panel);
EqualOperator("=",panel);
setVisible(true);
pack();
//setSize(400,200);
}
//isTwo方法
public boolean isTwo(){
int num=0;
double outcome=0;
double num1,num2;
String array[]=new String[2];
String operator="";
//将数字字符转换成整型数
if(y!=""){
StringTokenizer token1=new StringTokenizer(x," ");
while(token1.hasMoreTokens()){
array[num]=token1.nextToken();
++num;
}
num1=Double.parseDouble(array[0]);
num2=Double.parseDouble(array[1]);
//转换符号
StringTokenizer token2=new StringTokenizer(y);
while(token2.hasMoreTokens())
operator=token2.nextToken();
//判断语句
if(operator.equals(new String("+")))
outcome=num1+num2;
else if (operator.equals(new String("-")))
outcome=num1-num2;
else if (operator.equals(new String("*")))
outcome=num1*num2;
else if (operator.equals(new String("/"))){
outcome=num1/num2;
}
//更改字符串
y="f";
k=""+outcome;
x=""+outcome;
return true;
}
else
return false;
}
//数字按钮创建
public void CreatNum(final String cn,JPanel panel){
JButton button=new JButton(cn);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k!=""&&y=="f")
{
y="";
k="";
x="";
k+=cn;
}
else
k+=cn;
x=x+cn;
display.setText(k);
}
});
panel.add(button);
}
//操作符按钮创建
public void CreateOperator(final String co,JPanel panel){
JButton button=new JButton(co);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
//isTwo();
if(y.equals(new String(""))&&(isTwo()==false)){
y=y+co+" ";
display.setText(k);
k="";
}
else if((y!="")&&(isTwo())){
isTwo();
y=y+co+" ";
display.setText(k);
k="";
}
else
{
y="";
y=y+co+"";
display.setText(k);
}
x+=" ";
}
});
panel.add(button);
}
//等于号按钮的创建
public void EqualOperator(final String eo,JPanel panel){
JButton button=new JButton(eo);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(isTwo()==true)
display.setText(k);
else
x="";
}
});
panel.add(button);
}
//单目操作符('+/-'.'Sqrt','1/x')
public void SingleOperator(final String so,JPanel panel){
JButton button=new JButton(so);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(so.equals(new String("+/-"))){
double i;
i=Double.parseDouble(k);
if(i>0){
k="-"+k;
x="-"+x;
}
else
{
k=""+(-i);
x=""+(-i);
}
display.setText(k);
}
else if(so.equals(new String("Sqrt"))){
double i;
i=Double.parseDouble(k);
if(i>0){
i=Math.sqrt(i);
k=""+i;
x=""+i;
display.setText(k);
}
else{
k="函数输入无效";
display.setText(k);
k="";
x="";
y="";
}
}
else if(so.equals(new String("1/x"))){
double i;
i=Double.parseDouble(k);
i=1/i;
k=""+i;
x=""+i;
display.setText(k);
}
}
});
panel.add(button);
}
//小数点符号的创建
public void DecimalOperator(final String dso,JPanel panel){
JButton button=new JButton(dso);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k==""||k.contains("."))
;
else
{
k=k+".";
x=x+".";
display.setText(k);
}
}
});
panel.add(button);
}
//BackSpace键的创建
public void BackSpace(final String bs,JPanel panel){
JButton button=new JButton(bs);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
if(k=="")
;
else
{
k="";
x="";
y="";
display.setText(k);
}
}
});
panel.add(button);
}
public static void main(String args[]){
Caculator out=new Caculator();
out.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询