Switch to full style
General Java code examples
Post a reply

draw Oval in java

Tue Nov 11, 2008 6:46 pm

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
ovalIcons.gif
the output :
ovalIcons.gif (4.9 KiB) Viewed 25077 times

Post a reply
  Related Posts  to : draw Oval in java
 Draw Dashed Oval in java     -  
 Draw Oval,Arc,Polygon,string,Line,Round and 3D Rectangle     -  
 Draw An Arc in java     -  
 draw Calendar in java     -  
 Draw Flag in Java     -  
 draw text effects in java     -  
 Changing the color of a graph draw in java     -  
 Java code to draw shortest path tree     -  
 draw cube 3d java-Cube 3D     -  
 How to draw a gun     -