ProgramWindowJava

Help With For Loop?

i figured half of it out but I can't figure out how to do a for loop to keep the array running through positions 1 - 4,can anyone help me out. Thanks


import java.awt.*;
import java.applet.*;
import java.awt.Color;

public class animal extends Canvas {

public static void main(String [] args) {
animal deer = new animal();
}
public animal() {
Frame theframe = new Frame();
theframe.setSize(500, 500);
theframe.add(this,BorderLayout.CENTER);
theframe.setVisible(true);
}
public void drawSpots(Graphics g, Color c) {
int[] x = getxspot();
int[] y = getyspot();
int [] size = getsize();
g.setColor(c);

// Anyone know of a for loop that would work
// instead his long type of text right here can't
// figure how to write it. Thanks any help appreciated.

g.fillOval(x[0], y[0], size[0], size[0]);
g.fillOval(x[1], y[1], size[1], size[1]);
g.fillOval(x[2], y[2], size[2], size[2]);
g.fillOval(x[3], y[3], size[3], size[3]);
}
public void paint(Graphics g) {
drawhead(g, 50, 75, 50, 50);
drawneck(g, 70, 125, 10, 25);
drawbody(g, 70, 150, 100, 50, 10, 10);
drawoutleg(g, 75, 200, 20, 50);
drawoutleg(g, 95, 200, 10, 40);
drawoutleg(g, 150, 200, 20, 50);
drawoutleg(g, 140,200,10,40);
drawsmile(g,25,110,150,140,100,20);
drawtail(g,170,150,15,15,10,10);
draweyes(g,55,80,20,20);
drawSpots(g,Color.BLUE);
}
public void drawhead(Graphics g, int x, int y, int w, int h) {
g.drawOval(x, y, w, h);
}
public void drawneck(Graphics g, int x, int y, int w, int h) {
g.drawRect(x, y, w, h);
}
public void drawbody(Graphics g, int x, int y, int w, int h,
int aw, int ah) {
g.drawRoundRect(x, y, w, h, aw, ah);
}
public void drawoutleg(Graphics g, int x, int y, int w, int h) {
g.drawRect(x, y, w, h);
}
public void drawsmile(Graphics g, int x, int y, int w, int h, int a, int aa) {
g.drawArc(x,y,w,h,a,aa);
}
public void draweyes(Graphics g, int x, int y, int w, int h) {
g.drawOval(x,y,w,h);
}
public void drawtail(Graphics g,int x, int y, int w, int h, int aw, int ah) {
g.drawRoundRect(x,y,w,h,aw,ah);
}
public int [] getxspot() {
int [] array = new int [4];
array[0] = 80;
array[1] = 120;
array[2] = 145;
array[3] = 152;
return array;
}
public int [] getyspot() {
int [] array2 = new int [4];
array2 [0] = 160;
array2 [1] = 160;
array2 [2] = 160;
array2[3] = 220;
return array2;
}
public int [] getsize() {
int [] array3 = new int [4];
array3 [0] = 25;
array3 [1] = 15;
array3 [2] = 25;
array3[3] = 15;
return array3;
}
}

Replay:Help With For Loop?
Hi, try this

for(int i = 0; i < 4; i++){
g.fillOval(x[i], y[i], size[i], size[i]);
}

i is initialised to 0 and is incremented by one with each loop. It will also never reach 4.

Byron

Replay:Help With For Loop?
Okay Yea i'm just Braindead today, thanks

[Previous] Please look at my code
[Next] Array program help

Google


Java

Array program help
get source code from a website
Online Game
Upload 20MB File
ObjectOutputStream writing error
JDBC problem: NullPointerException
Writing a database
Declaring an array help
CMP and database connection problem
Need help with methods
Need help with this Code, please.
Threads
My first program.
memory address?
executable java file
Bitwise comparison?
Can't figure out Static Error?
Help!! using recursion to search an array
Encrypt / Decrypt homework help
Menus