Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Please Help me with this

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help me with this



    Im trying to make a program about a stop sign where if you move the mouse in the stop sign it will turn red and when you move the mouse in ready it will turn orange and when you move the mouse at GO it will turn green

    this is my code
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Color.*;
    public class JStopSign extends JFrame
    {
    public void paint(Graphics g)
    {
    super.paint(g);
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(red portion)
    int[] xOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] yOuter = {40, 40, 76, 127, 163, 163, 127, 76};
    int[] xInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] yInner = {45, 45, 77, 126, 158, 158, 126, 77};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(xOuter, yOuter, xOuter.length);
     
    //Fill inerior if sign with red
    g.setColor(Color.red);
    g.fillPolygon(xInner, yInner, xInner.length);
     
    //Display "STOP"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 36));
    g.drawString("STOP", 33, 116);
     
     
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(orange portion)
    int[] aOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] bOuter = {240, 240, 276, 327, 363, 363, 327, 276};
    int[] aInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] bInner = {245, 245, 277, 326, 358, 358, 326, 277};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(aOuter, bOuter, aOuter.length);
     
    //Fill inerior if sign with orange
    g.setColor(Color.orange);
    g.fillPolygon(aInner, bInner, aInner.length);
     
    //Display "READY"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 29));
    g.drawString("READY", 33, 316);
     
     
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(green portion)
    int[] cOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] dOuter = {440, 440, 476, 527, 563, 563, 527, 476};
    int[] cInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] dInner = {445, 445, 477, 526, 558, 558, 526, 477};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(cOuter, dOuter, cOuter.length);
     
    //Fill inerior if sign with green
    g.setColor(Color.green);
    g.fillPolygon(cInner, dInner, cInner.length);
     
    //Display "GO"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 50));
    g.drawString("GO", 45, 516);
     
     
    }
    public static void main(String[] args)
    {
    JStopSign frame = new JStopSign();
    frame.setSize(200, 600);
    frame.setVisible(true);
    }
     
    }

    Please help mee

    I only Know how to put the color but I dont know what to do if I move the mouse and it will change its color
    Im new here so please help me
    If possible please solve this
    give me the code on how to solve this
    I need this tomorrow
    thank you so much
    Last edited by adrin1; October 9th, 2012 at 09:07 AM.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    Im new In java Programming
    Please teach me how
    my stupid instructor wont teach us
    ive been searching for some codes since yesterday and found some but I still dont know how to use them

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Please Help me with this

    I've posted a link to a great tutorial containing everything you need to know.

    Please don't waste time insulting your instructor- many people here have taught themselves without the aid of an instructor, fellow classmates, or any of the other resources you get while attending school- using the same tutorial I already gave you.

    I suggest you read the tutorial, throw together an SSCCE that demonstrates what you've tried, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Request :)

    Can you guys please give me an example program that when you enter a mouse in a circle or Polygon it will change the color to Blue?
    please post your codes here

    thanks

  6. #6
    Member
    Join Date
    Oct 2012
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    Java's Swing is NOT easy to learn by yourself, and it's definitely not in the scope of being explained on a forum if you're not at least somewhat familiar with it. I'd say keep bugging your instructor, explain what you don't understand and work from there. Pick up a more general tutorial like basic Swing components or, as was suggested to you, general event listener tutorials. Read through those, get the code samples, run them, look through them and try to get a grasp of the basic structure.

    Basically, though, a MouseListener is an Interface class that you need to extend. You need to implement it with your own code and write actions to happen when those events take place (that's your colour change) and then register it as a listener for the object you're trying to mouse-over. Instances of listener classes are automatically notified when events they're listening for take place over a class they're interested in, and this is done by the class itself which reacts to all such events. All you need to do is override methods responsible for the events you're listening for (in your case that's mouseEntere() and mouseExited()) and write your colour-changing code in them.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Request :)

    That isn't really how this works. This isn't a codemill or a homework service. You're going to have to do some research, post your findings, and ask specific questions.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Please Help me with this

    I've merged your two threads, since they are asking for the same information. Again, you're going to have to read the link I gave you and ask specific questions about anything that confuses you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    im not looking for homework service im looking for some examples of these kinds of programs
    and looking for solutions of these problems
    I already know the public void mouse moved and public void mouse exited but still i dont know how to change the color of the stop sign, ready and go sign when the mouse entered any solutions? please help me im begging you guys

  10. #10
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    PLEASE I need this on monday

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Please Help me with this

    Quote Originally Posted by adrin1 View Post
    PLEASE I need this on monday
    You've been provided several links and pieces of advice- what happened when you tried them? Where is your updated SSCCE? What exactly are you confused by?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    This is my code now
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Color.*;
    public class JStopSign extends JFrame implements MouseListener
    {
    public void paint(Graphics g)
    {
    super.paint(g);
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(red portion)
    int[] xOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] yOuter = {40, 40, 76, 127, 163, 163, 127, 76};
    int[] xInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] yInner = {45, 45, 77, 126, 158, 158, 126, 77};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(xOuter, yOuter, xOuter.length);
     
    //Fill inerior if sign with red
    public void mouseEntered(MouseEvent me)
    {
    g.setColor(Color.red);
    g.fillPolygon(xInner, yInner, xInner.length);
    }
    public void mouseExited(MouseEvent me)
    {
     
    }
     
    //Display "STOP"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 36));
    g.drawString("STOP", 33, 116);
     
     
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(orange portion)
    int[] aOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] bOuter = {240, 240, 276, 327, 363, 363, 327, 276};
    int[] aInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] bInner = {245, 245, 277, 326, 358, 358, 326, 277};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(aOuter, bOuter, aOuter.length);
     
    //Fill inerior if sign with orange
    public void mouseEntered(MouseEvent me)
    {
    g.setColor(Color.orange);
    g.fillPolygon(aInner, bInner, aInner.length);
    }
    public void mouseExited(MouseEvent me)
    {
     
    }
    //Display "READY"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 29));
    g.drawString("READY", 33, 316);
     
     
    //Define coordinates of outer polygon (edge of sign) and
    //inner polygon(green portion)
    int[] cOuter = {56, 107, 143, 143, 107, 56, 20, 20};
    int[] dOuter = {440, 440, 476, 527, 563, 563, 527, 476};
    int[] cInner = {57, 106, 138, 138, 106, 57, 25, 25};
    int[] dInner = {445, 445, 477, 526, 558, 558, 526, 477};
    // Draw edge of sign in black
    g.setColor(Color.black);
    g.drawPolygon(cOuter, dOuter, cOuter.length);
     
    //Fill inerior if sign with green
    public void mouseEntered(MouseEvent me)
    {
    g.setColor(Color.green);
    g.fillPolygon(cInner, dInner, cInner.length);
    }
    public void mouseExited(MouseEvent me)
    {
     
    }
    //Display "GO"in white
    g.setColor(Color.white);
    g.setFont(new Font("SansSerif", Font.BOLD, 50));
    g.drawString("GO", 45, 516);
     
     
    }
    public static void main(String[] args)
    {
    JStopSign frame = new JStopSign();
    frame.setSize(200, 600);
    frame.setVisible(true);
    addMouseListener(this);
    addMouseMotionListener(this);
    }
     
    }

    I dont know how to fix the prob

  13. #13
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Please Help me with this

    I dont know how to fix the prob
    What seems to be the problem?

  14. #14
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    the mouse hover effect
    how am i gonna apply mouseEntered and mouseExited?
    in my jStopsign program

  15. #15
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    please help me oh please oh please oh please

  16. #16
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Please Help me with this

    how am i gonna apply mouseEntered and mouseExited?
    in my jStopsign program
    I am waiting to see the answer to that myself.



    please help me oh please oh please oh please
    Sure. What is your question?

  17. #17
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help me with this

    help me in my program, the objective is when i enter the mouse in stop it will fill the color to red same in ready and go. i dont know how

  18. #18
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Please Help me with this

    Quote Originally Posted by adrin1 View Post
    help me in my program, the objective is when i enter the mouse in stop it will fill the color to red same in ready and go. i dont know how
    Your code contains several syntax errors that fundamentally break your code. You should fix them first. Then follow the tutorials you were given, adding small pieces to your program and testing them one at a time instead of trying to cram everything in at one time.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!