Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
draw Oval in java
Code:
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; } }
Attachments:
File comment: the output : ovalIcons.gif [ 4.9 KiB | Viewed 13160 times ]
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )