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

  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6.  
  7. public class FlowLayout1 extends JPanel
  8. {
  9.     public FlowLayout1()
  10.     {
  11.         JButton btnOne;
  12.         JButton btnTwo;
  13.         JButton btnThree;
  14.         JButton btnFour;
  15.  
  16.         this.setLayout(new FlowLayout(FlowLayout.LEFT));
  17.  
  18.         btnOne = new JButton("One");
  19.         add(btnOne);
  20.  
  21.         btnTwo = new JButton("Two");
  22.         add(btnTwo);
  23.  
  24.         btnThree = new JButton("Three");
  25.         add(btnThree);
  26.  
  27.         btnFour = new JButton("Four");
  28.         add(btnFour);
  29.  
  30.     }//constructor
  31.  
  32.  
  33.  
  34.     public static void main(String s[])
  35.     {
  36.         JFrame f = new JFrame("Flow Layout");
  37.         FlowLayout1 panel = new FlowLayout1();
  38.  
  39.         f.setForeground(Color.black);
  40.         f.setBackground(Color.lightGray);
  41.         f.getContentPane().add(panel, "Center");
  42.  
  43.         f.setSize(400,100);
  44.         f.setVisible(true);
  45.         f.addWindowListener(new WindowCloser());
  46.  
  47.  
  48.     }//main
  49. }//class
  50.  
  51.  
  52. class WindowCloser extends WindowAdapter
  53. {
  54.     public void windowClosing(WindowEvent e)
  55.     {
  56.         Window win = e.getWindow();
  57.         win.setVisible(false);
  58.         win.dispose();
  59.         System.exit(0);
  60.     }//windowClosing
  61. }//class WindowCloser
  62.