GUI加减乘除计算
来源:互联网 发布:排刀数控车床编程实例 编辑:程序博客网 时间:2024/06/11 08:59
packagea;
//importjava.awt.*;
importjava.awt.Button;
importjava.awt.Choice;
importjava.awt.Component;
importjava.awt.Frame;
importjava.awt.GridLayout;
importjava.awt.Label;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.Vector;
importjavax.swing.ComboBoxModel;
importjavax.swing.JComboBox;
importorg.omg.CORBA.PUBLIC_MEMBER;
importcom.sun.org.apache.bcel.internal.generic.NEW;
importcom.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
publicclass AddFrame extends Frame
{
public static void main(String args[])
{
AddFrame b=new AddFrame ();
}
TextField num1=new TextField();
TextField num2=new TextField();
TextField num3=new TextField();
Choice osChoice=new Choice();
public AddFrame(){
setName("addFrame");
setSize(500,500);
setVisible(true);
initView();
}
void initView()
{
Button okButton=newButton("计算");
Button exitButton=newButton("退出");
this.setLayout(newGridLayout(5,2));
add(newLabel("第一个数:"));
add(num1);
add(newLabel("符号:"));
osChoice.add("+");
osChoice.add("-");
osChoice.add("*");
osChoice.add("/");
osChoice.add("%");
add(osChoice);
add(newLabel("第二个数:"));
add(num2);
add(newLabel("结果:"));
add(num3);
add(okButton);
add(exitButton);
AddListener addListener=newAddListener();
okButton.addActionListener(addListener);
ExitListener listener=newExitListener();
exitButton.addActionListener(listener);
}
class AddListener implements ActionListener
{
private static final boolean String = false;
public void actionPerformed(ActionEvent e)
{
String str1=num1.getText();
String str2=num2.getText();
if("+"==osChoice.getSelectedItem())
{
intresult=Integer.parseInt(str1)+Integer.parseInt(str2);
num3.setText(Integer.toString(result));
}
if("-"==osChoice.getSelectedItem())
{
intresult=Integer.parseInt(str1)-Integer.parseInt(str2);
num3.setText(Integer.toString(result));
}
if("*"==osChoice.getSelectedItem())
{
intresult=Integer.parseInt(str1)*Integer.parseInt(str2);
num3.setText(Integer.toString(result));
}
if("/"==osChoice.getSelectedItem())
{
doubleresult=(Integer.parseInt(str1)/Integer.parseInt(str2));
num3.setText(Double.toString(result));
}
if("%"==osChoice.getSelectedItem())
{
intresult=Integer.parseInt(str1)%Integer.parseInt(str2);
num3.setText(Integer.toString(result));
}
}
}
class ExitListener implements ActionListener
{
public voidactionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
- GUI加减乘除计算
- 加减乘除计算
- 计算分数的加减乘除
- 【JAVA】加减乘除计算
- 计算加减乘除switch
- js加减乘除精确计算
- 通过Jquery计算加减乘除
- 精确计算加减乘除--BigDecimal
- shell数值计算(加减乘除)
- 【javaScript】加减乘除的精确计算
- shell数值计算(加减乘除)
- 不使用加减乘除符号计算加法
- 使用位运算计算加减乘除四则运算
- java 浮点型加减乘除精确计算
- java 矩阵计算 加减乘除 反转 分解
- JS浮点数(小数)计算加减乘除
- java_浮点型加减乘除精确计算
- 0007 如何编写程序实现加减乘除计算
- C#的协变和逆变
- 深度解析ViewPager 页面 滑动效果PageTransformer
- CMake之交叉编译
- 高级php研发笔试题
- 南阳oj-An problem about date
- GUI加减乘除计算
- mvn常用命令
- 通过Tag标签回退版本修复bug
- jenkins,maven--创建自由风格的软件项目任务
- 0720Link
- MATLAB LINUX C相关资料收集
- hdu
- Ubuntu14配置tftp服务器
- 2017.7.20html5 output