Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2008, 12:17 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,617
Java Tip will become famous soon enoughJava Tip will become famous soon enough
How to implement the Icon interface in Java
This Java tip shows how to implement the Icon interface in Java.

Code:
import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class IconInterfaceDemo extends JPanel { public IconInterfaceDemo() { } public static void main(String[] a) { JFrame mainFrame = new JFrame(); JLabel label = new JLabel("label"); label.setIcon(new ColoredSquare(Color.green)); label.setDisabledIcon(new ColoredSquare(Color.red)); mainFrame.getContentPane().add(label); mainFrame.setSize(100, 100); mainFrame.setVisible(true); } } class ColoredSquare implements Icon { Color color; public ColoredSquare(Color color) { this.color = color; } public void paintIcon(Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); g.setColor(color); g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true); g.setColor(oldColor); } public int getIconWidth() { return 12; } public int getIconHeight() { return 12; } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to implement Priority queue with Java Java Tip java.lang 0 04-12-2008 09:49 PM
Using Java To Implement RSA Algorithm Floetic New To Java 3 04-01-2008 12:56 AM
Help about how to implement a graphical editor in java xiul Java 2D 0 11-29-2007 09:19 PM
API to Implement Server SSH in JAVA Jack Advanced Java 2 07-02-2007 02:52 AM
How can we implement IPC in java samson Networking 1 04-04-2007 07:38 AM


All times are GMT +3. The time now is 12:28 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org