Results 1 to 1 of 1
-
A simple application to test the functionality of the OvalIcon class
his Java tips contains a simple application to test the functionality of
the OvalIcon class.
Java Code:import java.awt.Component; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingConstants; public class TestOval { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label1 = new JLabel(new OvalIcon(20, 50)); JLabel label2 = new JLabel(new OvalIcon(50, 20)); JLabel label3 = new JLabel("Round!", new OvalIcon(60, 60), SwingConstants.CENTER); label3.setHorizontalTextPosition(SwingConstants.CENTER); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(label1); c.add(label2); c.add(label3); f.pack(); f.setVisible(true); } } class OvalIcon implements Icon { private int width, height; public OvalIcon(int w, int h) { width = w; height = h; } public void paintIcon(Component c, Graphics g, int x, int y) { g.drawOval(x, y, width - 1, height - 1); } public int getIconWidth() { return width; } public int getIconHeight() { return height; } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
class wordprocessor with spellchecking functionality
By manuniyi in forum AWT / SwingReplies: 1Last Post: 12-25-2007, 05:32 AM -
Simple example Client Server Application
By ferosh in forum NetworkingReplies: 1Last Post: 04-01-2007, 10:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks