2

SimpleBorder

  1. import java.awt.event.*;
  2. import java.awt.*;
  3.  
  4. public class SimpleBorder {
  5.  
  6.     public static void main(String[] args) {
  7.         ApplicationWindow appwin = new ApplicationWindow("Application");
  8.         appwin.setVisible(true);
  9.     }
  10.  
  11.     static class ApplicationWindow extends Frame {
  12.         ApplicationWindow(String name) {
  13.             super(name);
  14.  
  15.             addWindowListener(new WindowAdapter() {
  16.                 public void windowClosing(WindowEvent e) {
  17.                     System.exit(0);
  18.                 }
  19.             });
  20.  
  21.             Menu filemenu = new Menu("File", true);
  22.             MenuItem quit = new MenuItem("Quit");
  23.             quit.addActionListener(new ActionListener() {
  24.                 public void actionPerformed(ActionEvent e) {
  25.                     System.exit(0);
  26.                 }
  27.             });
  28.             filemenu.add(quit);
  29.  
  30.             MenuBar menubar = new MenuBar();
  31.             menubar.add(filemenu);
  32.  
  33.             setMenuBar(menubar);
  34.  
  35.             setLayout(new BorderLayout());
  36.             add(new Label("NORTH"), BorderLayout.NORTH);
  37.             add(new Label("WEST"), BorderLayout.WEST); 
  38.             add(new Label("SOUTH"), BorderLayout.SOUTH);
  39.             add(new Label("EAST"), BorderLayout.EAST);
  40.             add(new Label("CENTER"), BorderLayout.CENTER);
  41.            
  42.             pack();
  43.            
  44.             Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  45.  
  46.             int width = getWidth();
  47.             int height = getHeight();
  48.             int x = (screenSize.width - width) / 2;
  49.             int y = (screenSize.height - height) / 3;
  50.  
  51.             setBounds(x, y, width, height);
  52.             setResizable(true);
  53.         }
  54.     }
  55. }
$ javac SimpleBorder.java
$ java SimpleBorder

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].