The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Sat Sep 22, 2018 11:02 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: shapes in java
PostPosted: Thu Jan 06, 2005 5:01 pm 
Offline
Black Belt
Black Belt

Joined: Mon Apr 12, 2004 2:32 pm
Posts: 851
Location: Chicago
i kinda know how to draw shapes in java but i have a couple questions.

Here is the code i used:
Code:
/* Import the code to draw pictures & shapes */
import java.awt.*;

/* Import the code to display as an applet */
import java.applet.Applet;

public class House extends Applet {

    public void paint (Graphics page) {
        setBackground(Color.lightGray);  //sets the applet background to lightGray
        //setForeground(Color.white);

        page.setColor(Color.red);  //set the foreground color the color object we created

         // param 1 is x distance (the "X" coordinate)
         // param 2 is y distance down (the "Y" coordinate)
         // width is the width of the rectangle
         // height is the height of the rectangle
         
        page.fill3DRect(50, 300, 150,150,true);  //draw an opaque rectangle

        page.setColor(Color.yellow); // set the color yellow

        page.fillOval(50, 150, 75, 75);    //this draws an opaque oval
    }
}


I have 2 questions. My first is how do i run this as a program and not an applet and how do i draw triangles and lines in java? Thanks


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 06, 2005 11:40 pm 
Offline
Green Belt
Green Belt

Joined: Thu Jun 27, 2002 8:11 pm
Posts: 222
http://java.sun.com/developer/onlineTra ... index.html
http://java.sun.com/developer/onlineTraining/GUI/

I'll post a bit more later when I get time.


Top
 Profile  
Reply with quote  
 Post subject: Re: shapes in java
PostPosted: Fri Jan 07, 2005 2:36 am 
Offline
Green Belt
Green Belt

Joined: Thu Jun 27, 2002 8:11 pm
Posts: 222
cwl157 wrote:
My first is how do i run this as a program and not an applet


You can use a frame. Here is an example of a Frame:

Code:
import java.awt.*;
import java.awt.event.*;

public class FrHouse extends Frame
{
   //If you embed the main method in your frame class
   //You dont need a seperate application class
   public static void main(String[] args)
   {
      FrHouse myFrame = new FrHouse(); //Create a frame object
      myFrame.setVisible(true); //Make it visible
   }

   //Constructor
    public FrHouse()
    {
        setTitle("My Frame"); //Frame title
        setSize(500, 500); //Frame size
        setLocation(100, 100); //Frame location
        setBackground(Color.lightGray); //Frame background colour
        addWindowListener(new WlsFrame());
    }

    //Terminating an application when user closes the frame
    class WlsFrame extends WindowAdapter
    {
      public void windowClosing(WindowEvent we)
      {
         System.exit(0); //Terminates the application
      }
   }
}


Top
 Profile  
Reply with quote  
 Post subject: Re: shapes in java
PostPosted: Fri Jan 07, 2005 2:43 am 
Offline
Green Belt
Green Belt

Joined: Thu Jun 27, 2002 8:11 pm
Posts: 222
cwl157 wrote:
how do i draw triangles and lines in java? Thanks


I think you can make use of the classes:

Graphics &
Graphics2D

In the java.awt package.

Check the docs:

Java 2 Platform API Specification -> java.awt -> Graphics & Graphics2D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group