Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-05-2009
Member
 
Join Date: Feb 2009
Posts: 96
I have a code inside that needs tweaking JAVA

For the most part this does what i want but i would like it to do the following:
back increment the array so that i dont have to use index at 0 to get the app to start at top. I'm trying to create a YoYo and I would like the line to go backwards as well as forward without having to index back to 0 at the end of the forward run. I would also like the circle to be a different color then the line.

Code:
import java.awt.*;
import java.applet.*;


public class YoYo2 extends Applet  //make the class
{

private int ind = 0;
private int x = 20;
private int y = 20;
int[] hor = { 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60};
int[] vert = { 40,90, 100, 110, 120, 130, 140, 150, 160, 170, 180};
int[] cHor = {  50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50};
int[] cVert = {  40,90, 100, 110, 120, 130, 140, 150, 160, 170, 180};
private int sleep = 150;

	public void start()
	{
  		ind = 0;
	}
	public void paint(Graphics gr)
		{
		
		gr.setColor(Color.WHITE);
		gr.drawLine(60, 40, hor[ind], vert[ind]);
		gr.fillOval(cHor[ind], cVert[ind],x, y);

		++ind;
		
		if(ind == hor.length)
			ind = 0;
		gr.setColor(Color.BLACK);
		gr.drawLine(60, 40, hor[ind], vert[ind]);
	
		gr.fillOval(cHor[ind], cVert[ind],x, y);

			try
			{
				Thread.sleep(sleep);
			}
			catch(InterruptedException e)
			{
			}
			repaint();
	}
			
	
}
Reply With Quote
  #2  
Old 28-05-2009
Member
 
Join Date: Aug 2008
Posts: 35
Re: I have a code inside that needs tweaking JAVA

Hi I am learning Java.
I don't have any idea about array but for Oval color why don't you initializes a color variable?
Quote:
// The colors you will use
Color redColor;

// Standard colors can be named like this
redColor = Color.red;


// a circle (int x, int y, int width, int height,int startAngle, int arcAngle);
// ovals are also possible this way.

g.fillArc(120,120,60,60,0,360);

g.setColor(Color.red);
Quote:
Graphics.setColor() :
This is the setColor() method which is the Graphics class method imported by the java.awt.*; package. This method sets the color for the object by specified color. Here is the syntax of the setColor() method :

g.setColor(Color.color_name);

Graphics.fillOval() :
This is the fillOval() method used to fill the color inside the oval by specified color. Here is the syntax of the fillColor() method :

g.fillColor(Color.color_name);
Before drawing the Oval type this.
g.setColor(Color.color_name);

I hope this Helps.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "I have a code inside that needs tweaking JAVA"
Thread Thread Starter Forum Replies Last Post
help me to understand java code (calendar java code) ? so0oma Software Development 2 10-01-2011 12:01 AM
how to put cookie inside this particular counter code? xitdude Software Development 4 21-09-2010 06:47 AM
Embedding Flex SDK .jar files inside a Java Project Tanveer Joshi Software Development 6 14-07-2010 12:07 AM
Inserting image inside the php code garfield1 Software Development 3 03-12-2009 02:00 PM
I need JAVA help code inside Daren Software Development 3 23-05-2009 06:58 PM


All times are GMT +5.5. The time now is 12:22 PM.