Java help...

Discussion in 'Software' started by cApNhOwDy, May 21, 2005.

  1. cApNhOwDy

    cApNhOwDy Private E-2

    Okay, I'm in a real beef here. Just so you're keen on the lingo, I'm not very computer literate, so if you can, try to keep it as simple as possible. Now, the problem. I'm in a Java programming class. We have a project over graphics in Java that we're doing for 100 points. The problem? The teacher hasnt been here for 2 weeks, so so far all of our knowledge of graphics has come from typing code already given to us that she copied off, doesnt explain it at all. I think I've figured out a good majority of it, but that's why I'm here, to get more help. My project is a dancing stick figure. Everytime you click a button (which I'm still having trouble doing), the figure will change positions (which I'm still working on). Here is my stick figure class, which basically makes the stick figure.



    import java.awt.*;

    public class StickFigure
    {
    private int baseX;
    private int baseY;
    private Color color;
    private int height;

    public StickFigure (int center, int bottom, Color shade, int size)
    {
    baseX = center;
    baseY = bottom;
    color = shade;
    height = size;
    }

    public void draw (Graphics page)
    {
    int top = baseY - height;

    page.setColor (color);

    page.drawOval (baseX-10, top, 20, 20);

    page.drawLine (baseX, top+20, baseX, baseY-30);

    page.drawLine (baseX, baseY-30, baseX-15, baseY);
    page.drawLine (baseX, baseY-30, baseX+15, baseY);

    page.drawLine (baseX, baseY-70, baseX-25, baseY-70);
    page.drawLine (baseX, baseY-70, baseX+20, baseY-85);

    page.setColor (Color.green);
    page.fillRect (125, 100, 50, 25);

    page.setColor (Color.white);
    page.drawString ("Dance", 130, 115);
    }
    }


    That's that, and this is a completely different class that takes what I had from the StickFigure class and puts it in an applet. I'm trying to get a button in there, but I have no clue as how to go about doing that. This isnt completed yet.


    import java.util.Random;
    import java.applet.Applet;
    import java.awt.*;

    public class Project extends Applet
    {
    private final int APPLET_WIDTH = 400;
    private final int APPLET_HEIGHT = 150;
    private final int HEIGHT_MIN = 100;
    private final int VARIANCE = 40;

    private StickFigure figure1;

    public void init (){
    int h1;
    Random generator = new Random();

    h1 = HEIGHT_MIN + generator.nextInt(VARIANCE);

    figure1 = new StickFigure (100, 150, Color.red, h1);

    setBackground (Color.white);
    setSize (APPLET_WIDTH, APPLET_HEIGHT);
    }
    public void paint (Graphics page)
    {
    figure1.draw (page);
    }
    }


    If there's anything at all you think you can help me out on, then please let me know. I hate to be begging for help, but I'm sure that someone can help me, and it's impossible for me to get a good grade on this under the circumstances surrounding me learning about graphics.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds