Total members 11894 |It is currently Fri Nov 22, 2024 6:38 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 25078 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 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     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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