Total members 11361 |It is currently Thu Oct 02, 2014 5:22 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

All times are UTC [ DST ]



  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:
File comment: the output :
ovalIcons.gif
ovalIcons.gif [ 4.9 KiB | Viewed 18688 times ]

_________________
Please recommend / share my post if you found it helpful.
Author:
Mastermind
User avatar Posts: 2694
Have thanks: 73 time
Post new topic Reply to topic  [ 1 post ] 

  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     -  

All times are UTC [ DST ]









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team