zev_steinhardt
05-06-2004, 05:46 PM
I've been trying to get my feet wet with Java lately. However, I'm following an example from a book but having trouble getting it to work. Can someone please tell me what I'm doing wrong?
I'm trying to get an orange rectangle to be painted on a window. The code I have is as follows:
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(600,600);
frame.setVisible(true);
}//close go
public void paintComponet(Graphics g) {
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}//close paintComponent
}//close class
From what I understand, the program is supposed to call paintComponent on it's own; I don't have to call it. So, why can't I get an orange rectangle?
Any help would be greatly appreciated.
Zev Steinhardt
I'm trying to get an orange rectangle to be painted on a window. The code I have is as follows:
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(600,600);
frame.setVisible(true);
}//close go
public void paintComponet(Graphics g) {
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}//close paintComponent
}//close class
From what I understand, the program is supposed to call paintComponent on it's own; I don't have to call it. So, why can't I get an orange rectangle?
Any help would be greatly appreciated.
Zev Steinhardt