Results 1 to 4 of 4

Thread: Applet help!!!

  1. #1
    noobster is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Arrow Applet help!!!

    Hi guys!! <3
    so i have to finish this or i can't go out tonight :( basically i get to draw a bullseye with user inputting the desired starting and ending radius. I'm having trouble because when i compile the code i run into this error message. Any help?

    ----jGRASP exec: javac hippo.java

    hippo.java:19: illegal start of expression
    private toggleColor = Color.RED;
    ^
    hippo.java:20: illegal start of expression
    private Circle circle;
    ^
    2 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    I tried and set this to public but get the same error code. I'm more than sure there is plenty more wrong with my program ( so if you see something let me know )
    thanks in advance
    -noob
    ------------here is my code thus far----------
    /**hippo
    *
    */

    import javax.swing.JApplet;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.Scanner;

    public class hippo extends JApplet
    {
    public void paint( Graphics g )
    {
    Scanner scan = new Scanner ( System.in );
    System.out.println( " Please enter your desired starting radius > " );
    int radius1 = scan.nextInt();
    System.out.println( " Please enter your desired ending radius > " );
    int radius2 = scan.nextInt();
    private toggleColor = Color.RED;
    private Circle circle;
    super.paint( g );
    for ( int diameter = radius1; diameter >= radius2; diameter +=2 )

    Circle = new circle ( centerX - diameter / 2,
    centerY - diameter / 2,
    diameter, toggleColor );
    circle.draw( g );
    if ( toggleColor.equals( Color.RED ))
    toggleColor = Color.PINK;
    else
    toggleColor = Color.RED;
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default

    toggleColor and circle are local variables. Local variables are by definition private to a method so skip the keyword 'private' for them; aamof the compiler forbids using those keywords for local variables as you have noticed. Also define variable toggleColor to be of type Color otherwise the compiler will whine at you again.

    kind regards,

    Jos

  3. #3
    noobster is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    so axe the whole public/private thing? wont that cause more problems for the program? As for togglecolor i want it to be red and pink ? So I have to change that too? Am a bit confused :/

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You want to change the value of toggleColor as the program runs, and so I think it would be best if this were declared as a class field not local to any method. As JosAH says, it should be a Color variable.

    Also, please read my first link on how to use code tags.

Similar Threads

  1. applet class inside java.applet.* or java.awt.*
    By Manish87 in forum Java Applets
    Replies: 1
    Last Post: 09-27-2010, 02:15 PM
  2. Applet please help
    By owenwesley in forum New To Java
    Replies: 13
    Last Post: 06-24-2010, 06:00 AM
  3. Replies: 2
    Last Post: 09-29-2009, 03:33 PM
  4. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 12:54 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •