Results 1 to 7 of 7
  1. #1
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default [SOLVED] How do I make a triangle?

    Hey I am really new to applets, we are making them in class and we are suppose to create a house in the night with blinking stars. I know how to do everything, but make a triangle for my roof. I know how to make a triangle in regular java, but not one for an applet.

    So how do you you make an triangle in an applet?
    I am a Java n00b.

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    I think there is one in the java 2d package
    My IP address is 127.0.0.1

  3. #3
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Quote Originally Posted by Zosden View Post
    I think there is one in the java 2d package
    Sorry, but what is that/ and where can I find it.

    Is there just a code on how to make one?

    like here is how to make a rectangle in a Java Applet:
    Java Code:
    setBackground(Color.black);
    page.fillRect(0, 175, 300, 50);
    I am a Java n00b.

  4. #4
    damounh is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    why dont you create two classes, one will be the applet, the other will be JPanel, and in the applet create an instance of the JPanel class and add it to the applet. then in the JPanel use the paint functions to draw just like drawing normally in java.

    Damoun.H.

  5. #5
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Sorry, I don't understand how to do that. But is there a code on how to make a triangle like there is to make a rectangle? If so can you give me it. Thanks, sorry I don't understand, but I am only in programming I.
    Java Code:
    setBackground(Color.black);
    page.fillRect(0, 175, 300, 50);
    I am a Java n00b.

  6. #6
    damounh is offline Member
    Join Date
    May 2008
    Posts
    5
    Rep Power
    0

    Default

    there are no functions that would draw a triangle for you, however you can use the polygon method in graphics to make any shape you like

    heres how it works

    Java Code:
    int[] xPoints = {100,50,150};
    int[] yPoints = {100,200,200};
    g.drawPolygon(xPoints, yPoints, 3);
    theres also fillPolygon in case you wish to color it in. You can find all the drawing methods here

    i notice ur setting the background color to black, make sure you set the draw color to something else cuz by defaults its black.

    Damoun.H.

  7. #7
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Thanks everybody. I just drew lines to make a triangle roof. Here is the code:

    Java Code:
    //Roof
            page.setColor (Color.white);
            page.drawLine (MID+1, TOP+1, MID-70, TOP+50);
            page.setColor (Color.white);
            page.drawLine (MID+1, TOP+1, MID+70, TOP+50);
    I am a Java n00b.

Similar Threads

  1. change the square to triangle java
    By anotsu in forum New To Java
    Replies: 3
    Last Post: 07-09-2009, 12:17 PM
  2. Triangle
    By jkswebsite in forum New To Java
    Replies: 8
    Last Post: 01-10-2009, 03:08 PM
  3. Pascal Triangle help
    By Magic101 in forum New To Java
    Replies: 4
    Last Post: 05-01-2008, 08:51 PM
  4. Replies: 0
    Last Post: 04-12-2008, 09:39 PM
  5. Making triangle
    By banie in forum New To Java
    Replies: 4
    Last Post: 02-02-2008, 12:23 PM

Posting Permissions

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