java graphics display help
Posted
by
java
on Stack Overflow
See other posts from Stack Overflow
or by java
Published on 2011-01-15T04:49:46Z
Indexed on
2011/01/15
4:53 UTC
Read the original article
Hit count: 175
java
I know that i am not calling the graphics paint command in the mainframe in order to display it. but i'm not sure how. thanks in advance
import java.awt.*;
import javax.swing.*;
public class MainFrame extends JFrame {
private static Panel panel = new Panel();
public MainFrame() {
panel.setBackground(Color.white);
Container c = getContentPane();
c.add(panel);
}
public void paint(Graphics g) {
g.drawString("abc", 20, 20);
}
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setVisible(true);
frame.setSize(600, 400);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
© Stack Overflow or respective owner