DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2005

    Help: Drawing Oval Shape from objects


    I was trying to draw a parent oval, and three other oval that are children to the parent oval.

    The class called Goal is used to declare the format of the new goal, the problem or what I don't understand it; the paint() method in the main class passes the object to the Goal class's drawOval() method, how do I represent that object in the drawOval() method so the g2.draw understand what shape it is my to draw?

    I've tried;
    Ellipse2D.Double goal1 = new Ellipse2D.Double(400, 100, 120, 80);
    I know it is not correct, because placed the values there. I need the Ellipse shape to relate to the goal added to the ArrayList()

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;

    public class Main extends JFrame implements MouseListener{
    Container con = getContentPane();
    ArrayList allOvals;
    Goal parentOval;
    String goalName ="CG1";
    int x = 500, y = 100;

    public Main() {
    super.setTitle("Drawing Goal Hierarchy");
    allOvals = new ArrayList();
    parentOval = null;
    Goal newGoal = new Goal(goalName, 500, 100, parentOval);
    allOvals.add(0, newGoal);
    parentOval = newGoal;


    public void mouseClicked(MouseEvent e){

    Goal goal1 = new Goal("Test", x + 500, y + 200); // new goal that is not a parent
    //allOvals.add(1, goal1);


    public void mouseEntered(MouseEvent e){


    public void mouseExited(MouseEvent e){


    public void mousePressed(MouseEvent e){


    public void mouseReleased(MouseEvent e){


    public String getToolTipText(MouseEvent e){
    return parentOval.getToolTipText();

    public void paint (Graphics g){
    Goal goal;
    Graphics2D g2 = (Graphics2D)g;
    for (int i = 0; i < allOvals.size(); i++)

    goal = (Goal)allOvals.get(i);


    public static void main(String[] args) {
    Main go = new Main();
    go.setSize(500, 400);

    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;

    public class Goal extends JPanel{
    private String title;
    private Point2D.Double position;
    Goal parent;
    int x, y , width = 100, height = 60;

    private String gName, gType, gLink, gDescription, gFormal, gPattern, gOwner, dCreated, dModfied;

    /** Creates a new instance of Goal */
    public Goal(String title, double x, double y) {
    this(title, x, y, null);

    public Goal(String title, double x, double y, Goal parent) {
    this.title = title;
    position = new Point2D.Double(x, y);

    this.parent = parent;
    public void setPosition(double x, double y) {
    position.x = x;
    position.y = y;

    public java.awt.geom.Point2D.Double getPosition() {
    return (java.awt.geom.Point2D.Double)position.clone();
    public void drawGoal(java.awt.Graphics2D g2) {
    //draw the oval

    Ellipse2D.Double goal1 = new Ellipse2D.Double(400, 100, 120, 80);

    //draw the title

    // g2.drawString(title, 960, 540);

    if (parent != null) {
    g2.draw(new java.awt.geom.Line2D.Double(position, parent.getPosition()));

    public void setToolTipText(String nm, String gt, String gl, String gd, String gf, String gp, String go, String dc, String dm){
    this.gName = nm;
    this.gType = gt;
    this.gLink = gl;
    this.gDescription = gd;
    this.gFormal = gf;
    this.gPattern = gp;
    this.gOwner = go;
    this.dCreated = dc;
    this.dModfied = dm;


    public String getToolTipText(){
    return gName + "\n " + gType + "\n " + gLink + "\n " + gDescription +"\n " +
    gFormal + "\n" + gPattern + "\n " + gOwner + "\n " + dCreated + "\n " + dModfied;


    P.S. It wont post like a java code, so no indents are shown
    Last edited by TSquare; 10-21-2005 at 01:42 PM. Reason: Indent

Similar Threads

  1. Bug with Creation of Objects in SQL *Plus Worksheet
    By Michael Cole in forum Database
    Replies: 2
    Last Post: 04-02-2003, 03:06 PM
  2. Bug with Creation of Objects in SQL *Plus Worksheet
    By Michael Cole in forum oracle.general
    Replies: 0
    Last Post: 02-20-2003, 10:25 PM
  3. Pooling in n-tier architecture
    By Jeff Pipes in forum .NET
    Replies: 11
    Last Post: 05-15-2002, 10:17 AM
  4. Thin Objects for Better Performance
    By Dave Fleischman in forum Enterprise
    Replies: 3
    Last Post: 08-18-2000, 01:10 PM
  5. Components vs Objects
    By Oliver Lennon in forum Enterprise
    Replies: 3
    Last Post: 04-18-2000, 12:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.