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

  1.  
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.awt.*;
  5.  
  6. public class IconButtons extends JPanel
  7. {
  8.     public IconButtons()
  9.     {
  10.         ImageIcon buttonImage = new ImageIcon("images/T1.gif");
  11.         ImageIcon pressImage = new ImageIcon("images/T2.gif");
  12.         ImageIcon selImage = new ImageIcon("images/T3.gif");
  13.         ImageIcon disabledImage = new ImageIcon("images/T4.gif");
  14.         ImageIcon rolloverImage = new ImageIcon("images/T4.gif");
  15.         ImageIcon selrolloverImage = new ImageIcon("images/T3.gif");
  16.         ImageIcon DOJImage = new ImageIcon("images/T2.gif");
  17.         ImageIcon shapeImage = new ImageIcon("images/T1.gif");
  18.         AbstractButton button1;
  19.         AbstractButton button2;
  20.         AbstractButton button3;
  21.         Font font1;
  22.  
  23.         font1 = new Font("Serif", Font.PLAIN,16);
  24.         setFont(font1);
  25.         setDoubleBuffered(true);
  26.  
  27.         setLayout(new GridLayout(1,3,5,5));
  28.  
  29.         button1 = new JButton();
  30.         button1.setIcon(buttonImage);
  31.         button1.setPressedIcon(pressImage);
  32.         button1.setRolloverIcon(rolloverImage);
  33.         add(button1); 
  34.  
  35.         button2 = new JButton();
  36.         button2.setIcon(buttonImage);
  37.         button2.setDisabledIcon(disabledImage);
  38.         button2.setEnabled(false);
  39.         add(button2);
  40.  
  41.         button3 = new JToggleButton();
  42.         button3.setIcon(DOJImage);
  43.         button3.setSelectedIcon(shapeImage);
  44.         button3.setRolloverIcon(shapeImage);
  45.         button3.setRolloverSelectedIcon(selrolloverImage);
  46.         add(button3);
  47.  
  48.     }//constructor
  49.  
  50.    public static void main(String s[])
  51.     {
  52.         JFrame f = new JFrame("Icon Buttons ");
  53.         IconButtons panel = new IconButtons();
  54.  
  55.         f.setForeground(Color.black);
  56.         f.setBackground(Color.lightGray);
  57.         f.getContentPane().add(panel, "Center");
  58.  
  59.         f.setSize(200,70);
  60.         f.setVisible(true);
  61.         f.addWindowListener(new WindowCloser());
  62.  
  63.  
  64.     }//main
  65. }//IconButtons
  66.  
  67.  
  68. class WindowCloser extends WindowAdapter
  69. {
  70.     public void windowClosing(WindowEvent e)
  71.     {
  72.         Window win = e.getWindow();
  73.         win.setVisible(false);
  74.         win.dispose();
  75.         System.exit(0);
  76.     }//windowClosing
  77. }//class WindowCloser
  78.  
  79.  
  80.  
  81.  
  82.