急需这段java程序的注释!!!答的好补分(一) 100
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassCalculatorexte...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;//计算结果显示区
private String lastCommand;//保存+,-,*,/,=命令
private double result;//保存计算结果
private boolean start;//判断是否为数字的开始
public Calculator() {
super("Calculator");
container=getContentPane();
layout=new GridBagLayout();
container.setLayout(layout);
constraints=new GridBagConstraints();
start=true;
result=0;
lastCommand = "=";
displayField=new JTextField(20);
displayField.setHorizontalAlignment(JTextField.RIGHT);
constraints.gridx=0;
constraints.gridy=0;
constraints.gridwidth=4;
constraints.gridheight=1;
constraints.fill=GridBagConstraints.BOTH;
constraints.weightx=100;
constraints.weighty=100;
layout.setConstraints(displayField,constraints);
container.add(displayField);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
addButton("Backspace",0,1,2,1,insert);
addButton("CE",2,1,1,1,insert);
addButton("C",3,1,1,1,insert);
addButton("7",0,2,1,1,insert);
addButton("8",1,2,1,1,insert);
addButton("9",2,2,1,1,insert);
addButton("/",3,2,1,1,command);
addButton("4",0,3,1,1,insert);
addButton("5",1,3,1,1,insert);
addButton("6",2,3,1,1,insert);
addButton("*",3,3,1,1,command);
addButton("1",0,4,1,1,insert);
addButton("2",1,4,1,1,insert);
addButton("3",2,4,1,1,insert);
addButton("-",3,4,1,1,command);
addButton("0",0,5,1,1,insert);
addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值
addButton(".",2,5,1,1,insert);
addButton("+",3,5,1,1,command);
addButton("=",0,6,4,1,command);
setSize(300,300);
setVisible(true);
} 展开
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;//计算结果显示区
private String lastCommand;//保存+,-,*,/,=命令
private double result;//保存计算结果
private boolean start;//判断是否为数字的开始
public Calculator() {
super("Calculator");
container=getContentPane();
layout=new GridBagLayout();
container.setLayout(layout);
constraints=new GridBagConstraints();
start=true;
result=0;
lastCommand = "=";
displayField=new JTextField(20);
displayField.setHorizontalAlignment(JTextField.RIGHT);
constraints.gridx=0;
constraints.gridy=0;
constraints.gridwidth=4;
constraints.gridheight=1;
constraints.fill=GridBagConstraints.BOTH;
constraints.weightx=100;
constraints.weighty=100;
layout.setConstraints(displayField,constraints);
container.add(displayField);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
addButton("Backspace",0,1,2,1,insert);
addButton("CE",2,1,1,1,insert);
addButton("C",3,1,1,1,insert);
addButton("7",0,2,1,1,insert);
addButton("8",1,2,1,1,insert);
addButton("9",2,2,1,1,insert);
addButton("/",3,2,1,1,command);
addButton("4",0,3,1,1,insert);
addButton("5",1,3,1,1,insert);
addButton("6",2,3,1,1,insert);
addButton("*",3,3,1,1,command);
addButton("1",0,4,1,1,insert);
addButton("2",1,4,1,1,insert);
addButton("3",2,4,1,1,insert);
addButton("-",3,4,1,1,command);
addButton("0",0,5,1,1,insert);
addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值
addButton(".",2,5,1,1,insert);
addButton("+",3,5,1,1,command);
addButton("=",0,6,4,1,command);
setSize(300,300);
setVisible(true);
} 展开
1个回答
展开全部
累啊,好久没看AWT,swingl了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;// 计算结果显示区
private String lastCommand;// 保存+,-,*,/,=命令
private double result;// 保存计算结果
private boolean start;// 判断是否为数字的开始
public Calculator() {
super("Calculator");
// 建容器
container = getContentPane();
// 建立划分方法
layout = new GridBagLayout();
// 设置划分方法
container.setLayout(layout);
constraints = new GridBagConstraints();
start = true;//假设输入的为数字
result = 0;//结果预设
lastCommand = "=";//命令预设
displayField = new JTextField(20);//结果显示框
// 结果显示水平右对齐
displayField.setHorizontalAlignment(JTextField.RIGHT);
//设置所包含的组建的单元格
// 从左上角0,0个开始
constraints.gridx = 0;
constraints.gridy = 0;
// 就是横的显示几格的意思
constraints.gridwidth = 4;
constraints.gridheight = 1;
//当组件的显示区域大于它所请求的显示区域的大小时在水平方向和垂直方向上同时调整组件大小。
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 100;
constraints.weighty = 100;
// 设置容器放置
//这样就放进去结果显示框和按键区
layout.setConstraints(displayField, constraints);
container.add(displayField);// 假如结果框
//新建动作监听,
// 输入数字的监听
ActionListener insert = new InsertAction();
// 计算的监听
ActionListener command = new CommandAction();
// 加入按钮
addButton("Backspace", 0, 1, 2, 1, insert);
addButton("CE", 2, 1, 1, 1, insert);
addButton("C", 3, 1, 1, 1, insert);
addButton("7", 0, 2, 1, 1, insert);
addButton("8", 1, 2, 1, 1, insert);
addButton("9", 2, 2, 1, 1, insert);
addButton("/", 3, 2, 1, 1, command);
addButton("4", 0, 3, 1, 1, insert);
addButton("5", 1, 3, 1, 1, insert);
addButton("6", 2, 3, 1, 1, insert);
addButton("*", 3, 3, 1, 1, command);
addButton("1", 0, 4, 1, 1, insert);
addButton("2", 1, 4, 1, 1, insert);
addButton("3", 2, 4, 1, 1, insert);
addButton("-", 3, 4, 1, 1, command);
addButton("0", 0, 5, 1, 1, insert);
addButton("+/-", 1, 5, 1, 1, insert);// 只显示"-"号,"+"没有实用价值
addButton(".", 2, 5, 1, 1, insert);
addButton("+", 3, 5, 1, 1, command);
addButton("=", 0, 6, 4, 1, command);
setSize(300, 300);
setVisible(true);
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;// 计算结果显示区
private String lastCommand;// 保存+,-,*,/,=命令
private double result;// 保存计算结果
private boolean start;// 判断是否为数字的开始
public Calculator() {
super("Calculator");
// 建容器
container = getContentPane();
// 建立划分方法
layout = new GridBagLayout();
// 设置划分方法
container.setLayout(layout);
constraints = new GridBagConstraints();
start = true;//假设输入的为数字
result = 0;//结果预设
lastCommand = "=";//命令预设
displayField = new JTextField(20);//结果显示框
// 结果显示水平右对齐
displayField.setHorizontalAlignment(JTextField.RIGHT);
//设置所包含的组建的单元格
// 从左上角0,0个开始
constraints.gridx = 0;
constraints.gridy = 0;
// 就是横的显示几格的意思
constraints.gridwidth = 4;
constraints.gridheight = 1;
//当组件的显示区域大于它所请求的显示区域的大小时在水平方向和垂直方向上同时调整组件大小。
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 100;
constraints.weighty = 100;
// 设置容器放置
//这样就放进去结果显示框和按键区
layout.setConstraints(displayField, constraints);
container.add(displayField);// 假如结果框
//新建动作监听,
// 输入数字的监听
ActionListener insert = new InsertAction();
// 计算的监听
ActionListener command = new CommandAction();
// 加入按钮
addButton("Backspace", 0, 1, 2, 1, insert);
addButton("CE", 2, 1, 1, 1, insert);
addButton("C", 3, 1, 1, 1, insert);
addButton("7", 0, 2, 1, 1, insert);
addButton("8", 1, 2, 1, 1, insert);
addButton("9", 2, 2, 1, 1, insert);
addButton("/", 3, 2, 1, 1, command);
addButton("4", 0, 3, 1, 1, insert);
addButton("5", 1, 3, 1, 1, insert);
addButton("6", 2, 3, 1, 1, insert);
addButton("*", 3, 3, 1, 1, command);
addButton("1", 0, 4, 1, 1, insert);
addButton("2", 1, 4, 1, 1, insert);
addButton("3", 2, 4, 1, 1, insert);
addButton("-", 3, 4, 1, 1, command);
addButton("0", 0, 5, 1, 1, insert);
addButton("+/-", 1, 5, 1, 1, insert);// 只显示"-"号,"+"没有实用价值
addButton(".", 2, 5, 1, 1, insert);
addButton("+", 3, 5, 1, 1, command);
addButton("=", 0, 6, 4, 1, command);
setSize(300, 300);
setVisible(true);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询