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

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