![](https://i-blog.csdnimg.cn/blog_migrate/246050728166ff0613208bb8f23eeb9e.gif)
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);
}
}
}