Simple Java Program to Draw a Rectangle on a Pane
From: Allan Horwitz (ahorwitz_at_colburn.com)
Date: 10/05/03
- Next message: CD Rasmussen: "Re: Calling a shell function"
- Previous message: Ben Wan: "what is canonical path?"
- Next in thread: Rob Ratcliff: "Re: Simple Java Program to Draw a Rectangle on a Pane"
- Reply: Rob Ratcliff: "Re: Simple Java Program to Draw a Rectangle on a Pane"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Oct 2003 10:12:25 -0700
I am trying to draw a rectangle onto a pane. My program will compile
and run but the rectangle does not seem to get drawn. When the program
is run the program frame opens up, but I cannot see a rectangle on the
pane.
Any help would be appreciated.
Sincerely,
Allan
====start class code=====
import java.awt.*;
import javax.swing.*;
class MyDrawPanel extends JPanel {
public static void main(String[] args) {
MyDrawPanel gui = new MyDrawPanel();
gui.go();
}//close main
public void go() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}//close go
public void paintComponet(Graphics g) {
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}//close paintComponent
}//close class
======end class code======
- Next message: CD Rasmussen: "Re: Calling a shell function"
- Previous message: Ben Wan: "what is canonical path?"
- Next in thread: Rob Ratcliff: "Re: Simple Java Program to Draw a Rectangle on a Pane"
- Reply: Rob Ratcliff: "Re: Simple Java Program to Draw a Rectangle on a Pane"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|