help
Author |
Message |
WhatAmIDoing
|
Posted: Wed Nov 10, 2004 7:00 pm Post subject: help |
|
|
well i'm completely new to java and i have a question. Does any1 know a good source to learn the commands for real java and not that hsa.console crap. it makes me so mad that my school doesn't just use sumthin like Jcreator (which is what i have at home). anyway i would appreciate it if any1 knows a site.
thx |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Wed Nov 10, 2004 7:01 pm Post subject: (No subject) |
|
|
Look up the tutorial at http://java.sun.com |
|
|
|
|
|
WhatAmIDoing
|
Posted: Wed Nov 10, 2004 7:07 pm Post subject: (No subject) |
|
|
k thx for the info so far it looks like just what i wanted |
|
|
|
|
|
Hikaru79
|
Posted: Thu Nov 11, 2004 7:12 pm Post subject: (No subject) |
|
|
If you're a total newcomer to the Java world (especially if this applies to the OOP world as well), then "Your First Cup of Java" ( http://java.sun.com/docs/books/tutorial/getStarted/cupojava/ ) is an excellent beginner guide. Goes all the way from getting Java on your computer to compiling an applet with a GUI button!
Enjoy =) |
|
|
|
|
|
TheZsterBunny
|
Posted: Mon Nov 15, 2004 8:22 pm Post subject: (No subject) |
|
|
Hi,
I'ma having trouble with this one part.
I don't understand the error in the question 5 class (code block 2).
This is the FatTurtle Class
If you're not using the Holt editor, or don't have the Hsa.console package ( )
code: |
// The "FatTurtle" class.
// For drawing graphics with a variety of line widths.
// This class extends the Turtle class
import hsa.Console;
import hsa.book.*;
public class FatTurtle extends Turtle
{
//Add a new variable
protected int lineWidth;
// Only one version of constructor provided.
public FatTurtle (Console c)
{
super (c);
// Use default setting for other variables defined in Turtle class
lineWidth = 1;
} // FatTurtle constructor
// Add a new method to set LineWidth
public void setLineWidth (int newWidth)
{
lineWidth = newWidth;
} // setLineWidth method
// Draw a filled ball of radius and center at (x,y)
// in the current color
protected void drawBall (int xc, int yc, int radius)
{
int diameter = radius * 2;
int x = xc - radius;
int y = yc - radius;
c.fillOval (x, y, diameter, diameter);
} // drawBall method
// Add method drawFatLine
protected void drawFatLine (int x1, int y1, int x2, int y2)
{
// Line is drawn by moving a ball point pen whose ball
// is half line width.
// Line is drawn at x values of ball seperated by DX which
// is half the radius.
// Constants used in calculation
final double LEN = Math.sqrt (((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
final double SINA = (y2 - y1) / LEN;
final double COSA = (x2 - x1) / LEN;
final int RADIUS = (lineWidth / 2) + 1;
final double DX = RADIUS * COSA / 2;
final double DY = RADIUS * SINA / 2;
// Set position to draw first ball's center at (x1,y1)
double xpos = x1;
double ypos = y1;
// Draw a series of balls along line from (x1,y1) to (x2,y2).
do
{
drawBall ((int) Math.round (xpos), (int) Math.round (ypos), RADIUS);
xpos += DX;
ypos += DY;
}
while (Math.sqrt ((x2 - xpos) * (x2 - xpos) + (y2 - ypos) * (y2 - ypos)) >= RADIUS / 2);
} // drawFatLine method
// This method overrides
public void move (int distance)
{
double rAngle = angle * Math.PI / 180;
final int newx = (int) Math.round (x + Math.cos (rAngle) * distance);
final int newy = (int) Math.round (y + Math.sin (rAngle) * distance);
if (showing)
{
c.setColor (clr);
if (lineWidth == 1)
c.drawLine (x, y, newx, newy);
else
drawFatLine (x, y, newx, newy);
}
x = newx;
y = newy;
} // move method
} /* FatTurtle class */
|
and the problem area
code: |
// The "Question5" class.
import java.awt.*;
import hsa.Console;
import hsa.book.*;
public class Question5
{
static Console c;
public static void stripes (int number, Color clr1, Color clr2)
{
FatTurtle t1 = new FatTurtle (c);
FatTurtle t2 = new FatTurtle (c);
t1.setColor (clr1);
t2.setColor (clr2);
t1.turnLeft (90);
t2.turnLeft (90);
final int linwid = (int) c.getWidth () / number;
for (int i = 0 ; i < number ; i ++)
{
if (i % 2 == 0)
t1.drawFatLine (i * linwid, 0, (i + 1) * linwid, c.getHeight ());
else
t2.drawFatLine (i * linwid, 0, (i + 1) * linwid, c.getHeight ());
}
} // The output console
public static void main (String [] args)
{
c = new Console ();
stripes (5, Color.red, Color.blue);
// Place your program here. 'c' is the output console
} // main method
} // Question5 class
|
Error: The method "stripes" does not denote a class method. (line 32)
any help here would be hot
-Z |
|
|
|
|
|
Hikaru79
|
Posted: Fri Nov 19, 2004 7:25 am Post subject: (No subject) |
|
|
For some reason, DrawFatLine is protected. This is the error my compiler's giving (and I'm using Sun's compiler, not Holt's)
code: |
hikaru79@ubuntu:~/Java $ javac Question5.java
Question5.java:21: drawFatLine(int,int,int,int) has protected access in hsa.book.FatTurtle
t1.drawFatLine (i * linwid, 0, (i + 1) * linwid, c.getHeight ());
^
Question5.java:23: drawFatLine(int,int,int,int) has protected access in hsa.book.FatTurtle
t2.drawFatLine (i * linwid, 0, (i + 1) * linwid, c.getHeight ());
^
2 errors
|
So I looked carefully over the FatTurtle code and, Lo and behold! You're not supposed to use drawFatLine. It's a protected method that the program uses in itself. If you want to draw a fat line, then t1.setWidth(x) and then just t1.move normally. It'll take care of the rest itself.
Enjoy |
|
|
|
|
|
TheZsterBunny
|
Posted: Fri Nov 19, 2004 7:43 am Post subject: (No subject) |
|
|
I had forgotten about this post.
I had fixed the problem long ago.
code: |
/// The "Question5" class.
import java.awt.*;
import hsa.Console;
import hsa.book.*;
public class Question5
{
static Console c;
public static void stripes (int number, Color clr1, Color clr2)
{
FatTurtle t = new FatTurtle (c);
Color cclr;
t.setAngle (90);
final int linwid = (int) c.getWidth () / number;
t.setLineWidth (linwid);
for (int i = 0 ; i < number + 1 ; i++)
{
cclr = (i % 2 == 0 ? clr1:
clr2);
t.setColor (cclr);
t.setPosition (i * linwid, - linwid);
t.move (c.getHeight () + 2 * linwid);
}
} // The output console
public static void main (String [] args)
{
c = new Console ();
stripes (25, Color.red, Color.blue);
// Place your program here. 'c' is the output console
} // main method
} // Question5 class
|
i''ve also chopped out a turtle and a whole bunch of lines.
-Z |
|
|
|
|
|
|
|