importjava.awt.Button;importjava.awt.Menu;importjava.awt.MenuBar;importjava.awt.MenuItem;importjava.awt.Frame;importjava.awt.event.ActionEvent;importjava.awt.event.Action...
import java.awt.Button ;
import java.awt.Menu ;
import java.awt.MenuBar ;
import java.awt.MenuItem ;
import java.awt.Frame ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.WindowAdapter ;
import java.awt.event.WindowEvent ;
public class calculator extends Frame implements ActionListener
{
private Frame F = new Frame() ;
private MenuBar menubar = new MenuBar() ;
private Menu menu = new menu("菜单") ;
private MenuItem mNew = new MenuItem("新建") ;
private MenuItem mExit = new MenuItem("退出") ;
private Button m1 = new Button("1") ;
private Button m2 = new Button("2") ;
private Button m3 = new Button("3") ;
private Button m4 = new Button("4") ;
private Button m5 = new Button("5") ;
private Button m6 = new Button("6") ;
private Button m7 = new Button("7") ;
private Button m8 = new Button("8") ;
private Button m9 = new Button("9") ;
private Button m0 = new Button("0") ;
private Button mAdd = new Button("+") ;
private Button mSub = new Button("-") ;
private Button mAnd = new Button("*") ;
private Button mDiv = new Button("/") ;
private Button mEnter = new Button("Enter") ;
private Button mReset = new Button("Reset") ;
public calculator()
{
super("计算器") ;
setSize(600,800) ;
setVisible(true) ;
addWindowListener(new WindowAdapter(WindowEvent e)
{
public void WindowClosing() { System.exit(0);}
}) ;
this.setMenuBar(menubar) ;
menubar.add(menu) ;
menu.add(mNew) ;
menu.add(mExit) ;
this.add(m1) ;
this.add(m2) ;
this.add(m3) ;
this.add(m4) ;
this.add(m5) ;
this.add(m6) ;
this.add(m7) ;
this.add(m8) ;
this.add(m9) ;
this.add(m0) ;
this.add(mAdd) ;
this.add(mSub) ;
this.add(mAnd) ;
this.add(mDiv) ;
this.add(mEnter) ;
this.add(mReset) ;
mNew.addActionListener(this) ;
mExit.addActionListener(this) ;
m1.addActionListener(this) ;
m2.addActionListener(this) ;
m3.addActionListener(this) ;
m4.addActionListener(this) ;
m5.addActionListener(this) ;
m6.addActionListener(this) ;
m7.addActionListener(this) ;
m8.addActionListener(this) ;
m9.addActionListener(this) ;
m0.addActionListener(this) ;
mAdd.addActionListener(this) ;
mSub.addActionListener(this) ;
mAnd.addActionListener(this) ;
mDiv.addActionListener(this) ;
mEnter.addActionListener(this) ;
mReset.addActionListener(this) ;
}
public void ActionPerformed(ActionEvent e)
{
if(e.getSourse()=="新建")
{ new calculator() ;}
if(e.getSourse()=="退出")
{ System.exit(0) ;}
}
public static void main(String args[])
{
new calculator() ;
}
}
在调试的过程中出错为不能识别按键与菜单对象所在类..这是什么问题..高手给看看呗..谢谢了.
展开