1. 程式人生 > >計算器界面及關閉窗口

計算器界面及關閉窗口

ext awt extends apt tla event border etl you

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class hood{
public static void main(String arg[])
{
Frame f=new Frame("GridLayout");
f.setLayout(new GridLayout(4,4));
f.add(new Button("7"));
f.add(new Button("8"));
f.add(new Button("9"));
f.add(new Button("+"));
f.add(new Button("4"));
f.add(new Button("5"));
f.add(new Button("6"));
f.add(new Button("-"));
f.add(new Button("1"));
f.add(new Button("2"));
f.add(new Button("3"));
f.add(new Button("*"));
f.add(new Button("0"));
f.add(new Button("."));
f.add(new Button("="));
f.add(new Button("/"));
/*Frame f=new Frame("關閉窗口");
f.add(new Button("確定"),BorderLayout.WEST);*/
f.addWindowListener(new MyClose());
f.setSize(300,200);
f.setVisible(true);
}
}
class MyClose extends WindowAdapter{
public void windowClosing(WindowEvent arg0){
System.exit(0);
}
}

計算器界面及關閉窗口