| | |
drawStripes
Thread Solved |
•
•
Join Date: Sep 2006
Posts: 4
Reputation:
Solved Threads: 0
Hey whats up im pretty new here and new to java. I have no idea when it comes to methods. (this is my first java course so im completly lost)
I have a test coming up and Im just trying to review. We got a couple examples of things that will be on the test... So we are given this complex "for loop" and we have to turn it into a few simple"ler" methods. I am having trouple doing this. the first method is supposed to draw some Stripes on an HTML file. I am having trouble "calling" or "invoking" the "drawStripes" method i created so far i have
import java.applet.*; //applet stuff
import java.awt.*; //graphics stuff
// "extends Applet" tells Java this is applet code.
public class DrawingOvals extends Applet {
// Variables to store the width and height of the desired rectangle.
int width, height;
// Standard applet method to initialize the applet.
public void init() {
width = getSize().width; //Get width info from HTML file
height = getSize().height; //Get height info from HTML file
setBackground(Color.black);
}
/******* Everything above this line IS correct******/
public void drawStripes(Graphics g, int numItemsToDraw, int stripe_width)
{
int x=0;
stripe_width = width / numItemsToDraw;
//draw a solid (filled in) rectangle
g.fillRect(x, 0, (stripe_width), height);
//add the stripe_with to x so the next stripe can start drawing where the last finished
x+=stripe_width;
}
// method in Java graphics for "painting" graphics on screen
public void paint(Graphics g) {
g.drawStripes();
}
}
any one have any clue whats wrong?
is that even on the right track?
I am trying to draw a certain number of stripes depending on what i input in the drawStripes();
for example if i want to draw 5 stripes i want to just type in 5 in the () so it looks drawStripes(5);
but idk how to do that... sorry for the real noob question guys/girls
any ideas are welcome on how to aproach this.
( its a longer thing but once i figure out how to create and call this method i should be able to do the rest on my own.)
I have a test coming up and Im just trying to review. We got a couple examples of things that will be on the test... So we are given this complex "for loop" and we have to turn it into a few simple"ler" methods. I am having trouple doing this. the first method is supposed to draw some Stripes on an HTML file. I am having trouble "calling" or "invoking" the "drawStripes" method i created so far i have
import java.applet.*; //applet stuff
import java.awt.*; //graphics stuff
// "extends Applet" tells Java this is applet code.
public class DrawingOvals extends Applet {
// Variables to store the width and height of the desired rectangle.
int width, height;
// Standard applet method to initialize the applet.
public void init() {
width = getSize().width; //Get width info from HTML file
height = getSize().height; //Get height info from HTML file
setBackground(Color.black);
}
/******* Everything above this line IS correct******/
public void drawStripes(Graphics g, int numItemsToDraw, int stripe_width)
{
int x=0;
stripe_width = width / numItemsToDraw;
//draw a solid (filled in) rectangle
g.fillRect(x, 0, (stripe_width), height);
//add the stripe_with to x so the next stripe can start drawing where the last finished
x+=stripe_width;
}
// method in Java graphics for "painting" graphics on screen
public void paint(Graphics g) {
g.drawStripes();
}
}
any one have any clue whats wrong?
is that even on the right track?
I am trying to draw a certain number of stripes depending on what i input in the drawStripes();
for example if i want to draw 5 stripes i want to just type in 5 in the () so it looks drawStripes(5);
but idk how to do that... sorry for the real noob question guys/girls
any ideas are welcome on how to aproach this.
( its a longer thing but once i figure out how to create and call this method i should be able to do the rest on my own.)
![]() |
Other Threads in the Java Forum
- Previous Thread: Creating a simulation application
- Next Thread: build.xml Documentation
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loop loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





