Tue Nov 11, 2008 6:46 pm
import java.awt.*;
import javax.swing.*;
public class OvalIconExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Oval Icons");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 150);
JLabel label1 = new JLabel(new Oval(10, 50));
JLabel label2 = new JLabel(new Oval(20, 40));
JLabel label3 = new JLabel(new Oval(30, 30));
JLabel label4 = new JLabel(new Oval(40, 20));
JLabel label5 = new JLabel(new Oval(50, 80),
SwingConstants.CENTER);
label5.setHorizontalTextPosition(SwingConstants.CENTER);
Container container = frame.getContentPane();
container.setLayout(new FlowLayout());
container.add(label1);
container.add(label2);
container.add(label3);
container.add(label4);
container.add(label5);
frame.setVisible(true);
}
}
class Oval implements Icon {
private int width, height;
public Oval(int wid, int ht) {
width = wid;
height = ht;
}
public void paintIcon(Component container, Graphics g,
int p, int q) {
g.drawOval(p, q, width - 1, height - 1);
}
public int getIconWidth() {
return width;
}
public int getIconHeight() {
return height;
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.