-
Help: Drawing Oval Shape from objects
Hi
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);
g2.draw(goal1);
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");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con.addMouseListener(this);
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);
repaint();
}
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);
goal.drawGoal(g2);
}
}
public static void main(String[] args) {
Main go = new Main();
go.setSize(500, 400);
go.setVisible(true);
}
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);
g2.draw(goal1);
//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
-
By Michael Cole in forum Database
Replies: 2
Last Post: 04-02-2003, 03:06 PM
-
By Michael Cole in forum oracle.general
Replies: 0
Last Post: 02-20-2003, 10:25 PM
-
By Jeff Pipes in forum .NET
Replies: 11
Last Post: 05-15-2002, 10:17 AM
-
By Dave Fleischman in forum Enterprise
Replies: 3
Last Post: 08-18-2000, 01:10 PM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks