home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / javafile / ch08 / BorderLayout1.java < prev    next >
Encoding:
Java Source  |  1998-12-14  |  1.8 KB  |  75 lines

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class BorderLayout1 extends JPanel
  6. {
  7.  
  8. //The constructor initializes the application
  9.  
  10.     public BorderLayout1()
  11.     {
  12.         JButton btnNorth;
  13.         JButton btnSouth;
  14.         JButton btnEast;
  15.         JButton btnWest;
  16.         JButton btnCenter;
  17.  
  18.         Font font1;
  19.  
  20.         font1 = new Font("Times-Roman",Font.BOLD,18);
  21.  
  22.         this.setLayout(new BorderLayout());
  23.  
  24.         btnNorth = new JButton("North");
  25.         btnNorth.setFont(font1);
  26.         add(btnNorth, "North");
  27.  
  28.         btnSouth = new JButton("South");
  29.         btnSouth.setFont(font1);
  30.         add(btnSouth, "South");
  31.  
  32.         btnEast = new JButton("East");
  33.         btnEast.setFont(font1);
  34.         add(btnEast, "East");
  35.  
  36.         btnWest = new JButton("West");
  37.         btnWest.setFont(font1);
  38.         add( btnWest, "West");
  39.  
  40.         btnCenter = new JButton("Center");
  41.         btnCenter.setFont(font1);
  42.         add(btnCenter, "Center");
  43.  
  44.     }//constructor
  45.  
  46. //main entry point for the application
  47. public static void main(String s[])
  48.    {
  49.         JFrame f = new JFrame("Border Layout");
  50.         BorderLayout1 panel = new BorderLayout1();
  51.  
  52.         f.setForeground(Color.black); 
  53.         f.setBackground(Color.lightGray);
  54.         f.getContentPane().add(panel,"Center");
  55.  
  56.         f.setSize(400, 150);
  57.         f.setVisible(true);
  58.         f.addWindowListener(new WindowCloser());
  59.  
  60.     }//main
  61. }//class
  62.  
  63.  
  64. //This class handles the closing of the application
  65. class WindowCloser extends WindowAdapter
  66. {
  67.     public void windowClosing(WindowEvent e)
  68.     {
  69.         Window win = e.getWindow();
  70.         win.setVisible(false);
  71.         win.dispose();
  72.         System.exit(0);
  73.     }//windowClosing
  74. }//class WindowCloser
  75.