View Single Post
Old Feb 3rd, 2008, 11:31 AM   #4
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Re: 2D Graphics in Java

Hopefully this helps a bit...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class JFrameExample extends JFrame{
    
    public JFrameExample()        //Constructor
    {
        super("JFrameExample");    //Set title
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400,400);    //Set size to 400 by 400
        setVisible(true);    //Make the JFrame visible
    }
    
    public void paint(Graphics g)    //This is where the painting is done
    {
        super.paintComponents(g);    //Paint components
        g.setColor(Color.GREEN);    //Change the color to green
        g.drawRect(10,50,100,100);    //Draw a rectangle
    }
    
    public static void main (String[] args){
        new JFrameExample();    //Create an instance of JFrameExample
    }
}

Also this might help you a bit: http://www.corewebprogramming.com/PDF/ch10.pdf
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote