10
SimpleGrid
- import java.awt.event.*;
- import java.awt.*;
- public class SimpleGrid {
- public static void main(String[] args) {
- ApplicationWindow appwin = new ApplicationWindow("Application");
- appwin.setVisible(true);
- }
- static class ApplicationWindow extends Frame {
- ApplicationWindow(String name) {
- super(name);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- Menu filemenu = new Menu("File", true);
- MenuItem quit = new MenuItem("Quit");
- quit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- filemenu.add(quit);
- MenuBar menubar = new MenuBar();
- menubar.add(filemenu);
- setMenuBar(menubar);
- setLayout(new GridLayout(3, 3, 2, 2));
- for( int i = 1; i < 10; i++ )
- add(new Button(Integer.toString(i)));
- pack();
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int width = getSize().width;
- int height = getSize().height;
- int x = (screenSize.width - width) / 2;
- int y = (screenSize.height - height) / 3;
- setLocation(x, y);
- setResizable(true);
- }
- }
- }
$ javac SimpleGrid.java
$ java SimpleGrid
Comments