CAn someone help me fix this i keep getting errors! PLEASE HELP
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class DrawCurves extends Frame
{
CurvCanvas cBoard = new CurvCanvas();// Create area/Canvas for drawings
private ArrayList<Coordinate> drawPts;
private boolean closedCurve;
private int numSides;
private String numSidesInput;
public DrawCurves( ) // Default constructor
{
setTitle("Curve Drawing");
setSize(1600,1200);
addWindowListener(new MyLocalWindowAdapter());
cBoard.setSize(400,300); // Note: size SHOULD fit in window
cBoard.setBackground(Color.GREEN);
add("Center",cBoard);
getInput();
setVisible(true);
} // DrawCurves()
private void getInput()
{
numSidesInput = JOptionPane.showInputDialog(null, "Please input the number of sides that you would like to use for your polygon");
numSides = Integer.parseInt(numSidesInput);
}
private class MyLocalWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
dispose();
System.exit(0);
}
} //inner class MyLocalWindowAdapter
private class CurvCanvas extends Canvas
{
// paint is the inherited method we should override in order to draw our own image in an AWT window
public void paint(Graphics g)
{
Point startPt, fromPt, toPt;
Iterator <Coordinate> iter = drawPts.iterator();
fromPt = iter.next();
while(iter.hasNext())
{
xCor = new <Coordinate>;
xCor = iter.next();
xCor =xCor.getX;
yCor = iter.next();
yCor = yCor.getY;
g.drawLine(xCor, yCor);
}
g.setColor(Color.RED);//sets color of line to be drawn
g.drawLine(100, 200, 600, 700);//draws line between two sets of coordinates.
}//paint()
} // class CurvCanvas
public static void main(String[] args)
{
new DrawCurves( );
}
}//Drawcurves
This gives me multiple errors
You need the following two classes to even run it:
/*
NAME:Christopher Benson
DATE:
*/
import java.awt.*;
public class Coordinate extends Point// implements Comparable<Coordinate>
{
public Coordinate()
{
super();
}
public Coordinate(int diffX, int diffY)
{
super(diffX, diffY);
}
public Coordinate(double diffX, double diffY)
{
super.setLocation(diffX, diffY);
}
public Coordinate(Coordinate temp)
{
super(temp);
}
public String toString()
{
return "(" + this.x + ", " + this.y + ")";
}
}
and:
/*
NAME: Christopher Benson
DATE:November 3 2006
PURPOSE:
*/
import java.util.*;
public class Polygons extends Coordinate
{
private static final double DEG_TO_RAD = Math.PI/180;
private int numSides, sides, sideLeng;
private double rad;
private Coordinate cntrCoor;
private double radius;
private double cntrlAngl, angle;
ArrayList <Coordinate> Cords;
public Polygons()
{
int sides = 0;
double sideLength = 0;
double radius = 0;
int centerAngl = 0;
}
public Polygons(int numSides)
{
int sides = numSides;
double radius = 10;
int centerAngl = 360/sides;
}
public Polygons(int numSides, double radius)
{
sides = numSides;
radius = rad;
cntrlAngl = 360/sides;
Cords = new ArrayList <Coordinate> (sides);
setCoordinates(cntrlAngl);
}
public Polygons(int numSides, int sideLength)
{
sides = numSides;
sideLength = sideLeng;
radius = 10;
cntrlAngl = 360/sides;
Cords = new ArrayList <Coordinate> (sides);
setCoordinates(cntrlAngl);
}
private void setCoordinates(double angle)
{
double tempAng = angle;
double xCor, yCor;
for(int I = 1; I == sides; I++)
{
xCor = radius * Math.cos(tempAng * DEG_TO_RAD);
yCor = radius * Math.sin(tempAng * DEG_TO_RAD);
Cords.add(new Coordinate(xCor, yCor));
tempAng += cntrlAngl;
}
}
public ArrayList <Coordinate> getCoordinates()
{
ArrayList <Coordinate> temp = new ArrayList <Coordinate> (sides);
Iterator <Coordinate> iter = temp.iterator();
while(iter.hasNext())
{
temp.add(new Coordinate(iter.next()));
}
return temp;
}
public void radius(double rad)
{
radius = rad;
setCoordinates(angle);
}
public void setCenter(Coordinate center, int x1, int y1)
{
ArrayList <Coordinate> temp = new ArrayList <Coordinate> (sides);
Iterator <Coordinate> iter = temp.iterator();
while(iter.hasNext())
{
iter.next().translate(x1,y1);
}
}
public void rotate(double degree)
{
setCoordinates(degree);
}
public double area(double rad, double cntrlAngl)
{
double area;
double apothem = rad * Math.cos(cntrlAngl/2 * DEG_TO_RAD);
return apothem;
}
}
Im just trying to get it to work its got many problems and isnt totally complete...SORRY
also the last thing needed once those work is to run the whole thing with this:
import java.util.*;
import java.awt.*;
public class Dragon
{
public static final double DEG_TO_RAD = (Math.PI / 180);
public static final double INV_SQRT2 = (1.0/Math.sqrt(2.0));
ArrayList<Coordinate> dragonPts;
double startLength, startAngle, lastX, lastY;
Coordinate start;
Dragon()
{
//Initialize all instance variables to default values
}
Dragon(Coordinate first, int recurse, double length, double angle)
{
//Initialize all instance variables to input values.
}
public ArrayList<Coordinate> getCoordinates()
{
//returns copy of dragonPts
}
private void dragonCurve (int depth, int flip, double length, double angle)
{
if(depth > 0)
if (flip == 1)
{
dragonCurve(depth -1, 1, length * INV_SQRT2, angle - 45);
dragonCurve(depth -1, 0, length * INV_SQRT2, angle + 45);
}
else
{
dragonCurve(depth -1, 1, length * INV_SQRT2, angle + 45);
dragonCurve(depth -1, 0, length * INV_SQRT2, angle - 45);
}
else
{
lastX += length * Math.cos(angle * DEG_TO_RAD);
lastY += length * Math.sin(angle * DEG_TO_RAD);
dragonPts.add(new Coordinate(lastX, lastY));
}
}
}
Thanks for any help I owe you my life!!!!!!!!!
# 1
Hmm. You keep getting errors you say?
Hmmm. If only the compiler actually told you what the errors were, so you wouldn't have to resort to having someone over here copy/paste the code and compile it for themselves, and see the errors.... WAIT... It DOES show the error messages for us, but not for you?
# 2
it gives me :F:\DrawCurves.java:58: <identifier> expectedxCor = new <Coordinate>;but fixing that brings up more and its realy screwed up so it will take a good bit to get it going
# 3
> Hmm. You keep getting errors you say?
Well, as far as I can tell:
1) one bonus point to the OP for not having his unformatted code end up
in italic gibberish.
2) according to the OP himself you can kill, fry and eat him now.
Enjoy your meal ;-)
kind regards,
Jos
# 4
what is that supposed to mean?
# 5
> it gives me :
> F:\DrawCurves.java:58: <identifier> expected
> xCor = new <Coordinate>;
Well of course that is erroneous.
1) You never even defined a variable named xCor
2) new <Coordinate> makes no sense.
> but fixing that brings up more
Obviously then you didn't "fix" it but rather typed in some more random stuff hoping it would just magically compile.
> and its realy screwed
> up so it will take a good bit to get it going
Well, programming is kinda like that. It takes skill, effort, time, etc.
Suggestion: Do the tutorials and get stuff to compile on your own. We're not your on-line "do my homework for me, fix my compiler errors" shop.
http://java.sun.com/docs/books/tutorial/
# 6
> it gives me :
> F:\DrawCurves.java:58: <identifier> expected
> xCor = new <Coordinate>;
> but fixing that brings up more and its realy screwed
> up so it will take a good bit to get it going
new <Coordiante>
wtf is that?
shouldnt that be new Coordinate();
?
i think you are screwed.
paste one class at a time, use code tags if you wish people to help you
# 7
ok well yah im not wuite sure hwat im doing so could you tell me where to start...Yah i was typing in random stuff hoping for it to magically work. xCor is suposed to be of type coordinate but not quite sure how to make it that way...I just want to get the set of coordinate out of the ArrayList and then iterate through so that it makes a dragon curve...I guess my biggest problem comes from not knowing entirely what im trying to do so yah thats where i am now. Any help is always apreciated.
# 8
> ok well yah im not wuite sure hwat im doing so could
> you tell me where to start...
You were told where to start already :
>Suggestion: Do the tutorials and get stuff to compile on your own. We're not your on-line >"do my homework for me, fix my compiler errors" shop.
>http://java.sun.com/docs/books/tutorial/
# 9
yah im new to this so i had no idea what that was ... hold on and i'll fix it
/*
NAME:Christopher Benson
DATE:
*/
import java.awt.*;
public class Coordinate extends Point// implements Comparable<Coordinate>
{
public Coordinate()
{
super();
}
public Coordinate(int diffX, int diffY)
{
super(diffX, diffY);
}
public Coordinate(double diffX, double diffY)
{
super.setLocation(diffX, diffY);
}
public Coordinate(Coordinate temp)
{
super(temp);
}
public String toString()
{
return "(" + this.x + ", " + this.y + ")";
}
}
then you need
/*
NAME: Christopher Benson
DATE:November 3 2006
PURPOSE:
*/
import java.util.*;
public class Polygons extends Coordinate
{
private static final double DEG_TO_RAD = Math.PI/180;
private int numSides, sides, sideLeng;
private double rad;
private Coordinate cntrCoor;
private double radius;
private double cntrlAngl, angle;
ArrayList <Coordinate> Cords;
public Polygons()
{
int sides = 0;
double sideLength = 0;
double radius = 0;
int centerAngl = 0;
}
public Polygons(int numSides)
{
int sides = numSides;
double radius = 10;
int centerAngl = 360/sides;
}
public Polygons(int numSides, double radius)
{
sides = numSides;
radius = rad;
cntrlAngl = 360/sides;
Cords = new ArrayList <Coordinate> (sides);
setCoordinates(cntrlAngl);
}
public Polygons(int numSides, int sideLength)
{
sides = numSides;
sideLength = sideLeng;
radius = 10;
cntrlAngl = 360/sides;
Cords = new ArrayList <Coordinate> (sides);
setCoordinates(cntrlAngl);
}
private void setCoordinates(double angle)
{
double tempAng = angle;
double xCor, yCor;
for(int I = 1; I == sides; I++)
{
xCor = radius * Math.cos(tempAng * DEG_TO_RAD);
yCor = radius * Math.sin(tempAng * DEG_TO_RAD);
Cords.add(new Coordinate(xCor, yCor));
tempAng += cntrlAngl;
}
}
public ArrayList <Coordinate> getCoordinates()
{
ArrayList <Coordinate> temp = new ArrayList <Coordinate> (sides);
Iterator <Coordinate> iter = temp.iterator();
while(iter.hasNext())
{
temp.add(new Coordinate(iter.next()));
}
return temp;
}
public void radius(double rad)
{
radius = rad;
setCoordinates(angle);
}
public void setCenter(Coordinate center, int x1, int y1)
{
ArrayList <Coordinate> temp = new ArrayList <Coordinate> (sides);
Iterator <Coordinate> iter = temp.iterator();
while(iter.hasNext())
{
iter.next().translate(x1,y1);
}
}
public void rotate(double degree)
{
setCoordinates(degree);
}
public double area(double rad, double cntrlAngl)
{
double area;
double apothem = rad * Math.cos(cntrlAngl/2 * DEG_TO_RAD);
return apothem;
}
}
then
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class DrawCurves extends Frame
{
CurvCanvas cBoard = new CurvCanvas();// Create area/Canvas for drawings
private ArrayList<Coordinate> drawPts;
private boolean closedCurve;
private int numSides;
private String numSidesInput;
public DrawCurves( ) // Default constructor
{
setTitle("Curve Drawing");
setSize(1600,1200);
addWindowListener(new MyLocalWindowAdapter());
cBoard.setSize(400,300); // Note: size SHOULD fit in window
cBoard.setBackground(Color.GREEN);
add("Center",cBoard);
getInput();
setVisible(true);
} // DrawCurves()
private void getInput()
{
numSidesInput = JOptionPane.showInputDialog(null, "Please input the number of sides that you would like to use for your polygon");
numSides = Integer.parseInt(numSidesInput);
}
private class MyLocalWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
dispose();
System.exit(0);
}
} //inner class MyLocalWindowAdapter
private class CurvCanvas extends Canvas
{
// paint is the inherited method we should override in order to draw our own image in an AWT window
public void paint(Graphics g)
{
Point startPt, fromPt, toPt;
Iterator <Coordinate> iter = drawPts.iterator();
fromPt = iter.next();
while(iter.hasNext())
{
xCor = new <Coordinate>;
xCor = iter.next();
xCor =xCor.getX;
yCor = iter.next();
yCor = yCor.getY;
g.drawLine(xCor, yCor);
}
g.setColor(Color.RED);//sets color of line to be drawn
g.drawLine(100, 200, 600, 700);//draws line between two sets of coordinates.
}//paint()
} // class CurvCanvas
public static void main(String[] args)
{
new DrawCurves( );
}
}//Drawcurves
once thats done the last part which i havent even tried cuz we were given it was this:
import java.util.*;
import java.awt.*;
public class Dragon
{
public static final double DEG_TO_RAD = (Math.PI / 180);
public static final double INV_SQRT2 = (1.0/Math.sqrt(2.0));
ArrayList<Coordinate> dragonPts;
double startLength, startAngle, lastX, lastY;
Coordinate start;
Dragon()
{
//Initialize all instance variables to default values
}
Dragon(Coordinate first, int recurse, double length, double angle)
{
//Initialize all instance variables to input values.
}
public ArrayList<Coordinate> getCoordinates()
{
//returns copy of dragonPts
}
private void dragonCurve (int depth, int flip, double length, double angle)
{
if(depth > 0)
if (flip == 1)
{
dragonCurve(depth -1, 1, length * INV_SQRT2, angle - 45);
dragonCurve(depth -1, 0, length * INV_SQRT2, angle + 45);
}
else
{
dragonCurve(depth -1, 1, length * INV_SQRT2, angle + 45);
dragonCurve(depth -1, 0, length * INV_SQRT2, angle - 45);
}
else
{
lastX += length * Math.cos(angle * DEG_TO_RAD);
lastY += length * Math.sin(angle * DEG_TO_RAD);
dragonPts.add(new Coordinate(lastX, lastY));
}
}
}
# 10
Coordinate coord1 = new Coordinate();Coordinate coord2 = new Coordinate(2,5);