Icon behavior in Jbuttons : Applet « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » AppletScreenshots 
Icon behavior in Jbuttons
Icon behavior in Jbuttons

// : c14:Faces.java
// Icon behavior in Jbuttons.
// <applet code=Faces width=400 height=100></applet>
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Faces extends JApplet {
  private static Icon[] faces;

  private JButton jb, jb2 = new JButton("Disable");

  private boolean mad = false;

  public void init() {
    faces = new Icon[] {
        new ImageIcon(getClass().getResource("Face0.gif")),
        new ImageIcon(getClass().getResource("Face1.gif")),
        new ImageIcon(getClass().getResource("Face2.gif")),
        new ImageIcon(getClass().getResource("Face3.gif")),
        new ImageIcon(getClass().getResource("Face4.gif"))};
    jb = new JButton("JButton", faces[3]);
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    jb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (mad) {
          jb.setIcon(faces[3]);
          mad = false;
        else {
          jb.setIcon(faces[0]);
          mad = true;
        }
        jb.setVerticalAlignment(JButton.TOP);
        jb.setHorizontalAlignment(JButton.LEFT);
      }
    });
    jb.setRolloverEnabled(true);
    jb.setRolloverIcon(faces[1]);
    jb.setPressedIcon(faces[2]);
    jb.setDisabledIcon(faces[4]);
    jb.setToolTipText("Yow!");
    cp.add(jb);
    jb2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (jb.isEnabled()) {
          jb.setEnabled(false);
          jb2.setText("Enable");
        else {
          jb.setEnabled(true);
          jb2.setText("Disable");
        }
      }
    });
    cp.add(jb2);
  }

  public static void main(String[] args) {
    run(new Faces()400200);
  }

  public static void run(JApplet applet, int width, int height) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(applet);
    frame.setSize(width, height);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }
///:~



           
       
Related examples in the same category
1. Icon Demo Applet
2. Socket Applet
3. Applet Socket Quote
4. Applet Print
5. Applet System Properties
6. Applet Sound
7. Show Document
8. Applet communication (talk to each other)
9. Get Applets
10. JDBC applet
11. An application and an appletAn application and an applet
12. Applet and Swing ComponentsApplet and Swing Components
13. Signed Applet
14. Load resouce in Applet
15. Scribble AppletScribble Applet
16. Toggle buttonToggle button
17. Bouncing CircleBouncing Circle
18. Applet Menu Bar Demo
19. Applet clock demoApplet clock demo
20. Applet event testerApplet event tester
21. Applet with parameters
22. First applet
23. AppletViewer - a simple Applet Viewer program
24. A simple loan calculator appletA simple loan calculator applet
25. URLButton -- a Button-like object that jumps to a URL
26. Get list of APPLET tags in one HTML file
27. Demonstration of Applet Methods
28. Demonstrates getParameterInfo() and getAppletInfo()
29. Walking Text Demo
30. Java Applets Can Run CGI's (on some browsers)
31. Demo Choice Applet
32. Demo Applet: Connect to Legacy System
33. ShowDocApplet: try out showDocument()
34. Bookmarks
35. Java Wave Applet Demo
36. Slide Puzzle
37. A class to allow use of the ncsa ISMAP format in java applets
38. File Read Applet
39. Applet I18N
40. Image Loader Applet
41. Thread Race Applet
42. Applet: Print from an Applet
43. Your own Applet runtime environment
ww_w__.jav___a___2__s__._c_om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.