A simple application to test the functionality of the OvalIcon class : Icon « 2D Graphics GUI « Java






A simple application to test the functionality of the OvalIcon class

A simple application to test the functionality of the OvalIcon class
     
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;
  }
}

           
         
    
    
    
    
  








Related examples in the same category

1.Create a dynamic icon
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.Example of an icon that changes formExample of an icon that changes form
7.Custom Icon DemoCustom Icon Demo
8.Create Image Icon from PNG file
9.Reading an Image or Icon from a File
10.Draw an Icon object
11.Plain Color Icon
12.Color Icon
13.Arrow Icon
14.Icon Line
15.Return a filled oval as an Icon
16.Layered Icon
17.An icon for painting a square swatch of a specified Color.
18.An empty icon with arbitrary width and height.
19.Transparent icon with no content
20.Creates a transparent icon.
21.Icon Codec