Hi
I could not resolve the error to do with the line of code
Goal newGoal = new Goal(String title, double x, double y, parentOval);
in the DrawOval Class
Here is the classes:
package javaapplication1;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class DrawOval extends JFrame implements MouseListener{
Container con = getContentPane();
ArrayList<Goal> allOvals;
Goal parentOval;
/** Creates a new instance of Main */
public DrawOval() {
setTitle("Drawing Goal Hierarchy");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con.addMouseListener(this);
allOvals = new ArrayList<Goal>();
parentOval = new Goal(null);
}
public void mouseClicked(MouseEvent e){
Goal newGoal = new Goal(String title, double x, double y, parentOval);
if(parentOval == null){
parentOval = newOval;
}
}
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){
}
public void paint (graphics g){
super.paint();
Graphics2D g2 = (Graphics2D)g;
for (Goal goal : allOvals){
goal.drawGoal(g2);
}
}
public static void main(String[] args) {
Goal gl = new Goal();
gl.setSize(250, 150);
g1.setVisible(true);
}
}
package javaapplication1;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class Goal extends JToolTip{
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 oval1 = new Ellipse2D.Double(x, y, width, height);
g2.draw(oval1);
//draw the title
g2.drawString(title, x, y);
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;
}
}