4
SimpleBorder
- import java.awt.event.*;
- import java.awt.*;
- public class SimpleBorder {
- 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 BorderLayout());
- add(new Label("NORTH"), BorderLayout.NORTH);
- add(new Label("WEST"), BorderLayout.WEST);
- add(new Label("SOUTH"), BorderLayout.SOUTH);
- add(new Label("EAST"), BorderLayout.EAST);
- add(new Label("CENTER"), BorderLayout.CENTER);
- pack();
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int width = getWidth();
- int height = getHeight();
- int x = (screenSize.width - width) / 2;
- int y = (screenSize.height - height) / 3;
- setBounds(x, y, width, height);
- setResizable(true);
- }
- }
- }
$ javac SimpleBorder.java
$ java SimpleBorder
Comments