Example of an icon that changes form : Icon « 2D Graphics GUI « 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 » 2D Graphics GUI » IconScreenshots 
Example of an icon that changes form
Example of an icon that changes form

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class DynamicIconExample {
  public static void main(String[] args) {
    final JSlider width = new JSlider(JSlider.HORIZONTAL, 115075);
    final JSlider height = new JSlider(JSlider.VERTICAL, 115075);

    class DynamicIcon implements Icon {
      public int getIconWidth() {
        return width.getValue();
      }

      public int getIconHeight() {
        return height.getValue();
      }

      public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fill3DRect(x, y, getIconWidth(), getIconHeight()true);
      }
    }
    
    Icon icon = new DynamicIcon();
    final JLabel dynamicLabel = new JLabel(icon);

    class Updater implements ChangeListener {
      public void stateChanged(ChangeEvent ev) {
        dynamicLabel.repaint();
      }
    }
    Updater updater = new Updater();

    width.addChangeListener(updater);
    height.addChangeListener(updater);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(width, BorderLayout.NORTH);
    c.add(height, BorderLayout.WEST);
    c.add(dynamicLabel, BorderLayout.CENTER);
    f.setSize(210210);
    f.setVisible(true);
  }
  
}

           
       
Related examples in the same category
1. A simple application to test the functionality of the OvalIcon classA simple application to test the functionality of the OvalIcon class
2. Icon DisplayerIcon Displayer
3. Implement the Icon interfaceImplement the Icon interface
4. Calendar Page icons with Weekday, Day and MonthCalendar Page icons with Weekday, Day and Month
5. MemImage is an in-memory icon showing a Color gradientMemImage is an in-memory icon showing a Color gradient
6. Custom Icon DemoCustom Icon Demo
7. Create Image Icon from PNG file
w_ww__.j_a__v___a__2s._c_o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.