-
help with input from arrays
Down below I have X and Y. These are Going to be like coordinates on a grid. At the INput screen the User is going to input java elephant number secondnumber, I would like these number and secondnumber to add to the x and y coordinates given. I have a for loop but this isn't working can someone help that the user input with increase the X and Y Coordinates.
import java.awt.*;
import java.applet.*;
import java.awt.Color;
public class elephant extends animal {
private static int x = 20;
private static int y = 20;
private static Color c = Color.blue;
public static void main(String [] args) {
int coordinate;
int coordinate2;
int position;
elephant elephant = new elephant(x, y, c);
// I set up these for loops to attempt to add on to the x
// and y values but it's not working, Anyone help?
for (int k = 0; k < args.length; k++) {
for (int i = 1; i < args.length; i ++) {
if (args.length > 0) {
coordinate = Integer.parseInt(args[k]);
coordinate2 = Integer.parseInt(args[i]);
x = coordinate;
y = coordinate2;
}
}
}
}
public elephant (int xx,int yy, Color cc){
x = xx;
y = yy;
c = cc;
}
public void paint(Graphics g) {
drawhead(g,200 + x,150 + y,80,80);
drawneck(g,280 + x,165 + y,10,50);
drawbody(g,290 + x,165 + y,150,150,10,10);
drawoutleg(g,290 + x,315 + y,20,70);
drawoutleg(g,310 + x,315 + y,10,50);
drawoutleg(g,420 + x,315 + y,20,70);
drawoutleg(g,410 + x,315 + y,10,50);
drawtail(g,440+ x,165+ y,50,10,45,10);
drawsmile(g,170+ x,200+ y,150,140,100,20);
draweyes(g,210+ x,160+ y,20,20);
drawSpots(g,Color.BLUE);
}
public void drawSpots(Graphics g, Color c) {
int[] x = getxspot();
int[] y = getyspot();
int [] size = getsize();
g.setColor(c);
for (int k = 0; k < 5; k ++) {
g.fillOval(x[k],y[k],size[k],size[k]);
}
}
public int [] getxspot() {
int [] array = new int [4];
array [0] = 300;
array [1] = 325;
array [2] = 350;
array [3] = 365;
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;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks