Results 1 to 2 of 2

Thread: I have a code inside that needs tweaking JAVA

  1. #1
    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();
    	}
    			
    	
    }

  2. #2
    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?
    // 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);
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,728,033,832.17773 seconds with 17 queries