This is probably very simple, but I'm just not understanding it. I'm trying to draw a rectangle, but when I come to it nothing shows.
I'm not sure if and how I should call the paint() method. After reading another post I got the impression it should be called whenever the program decides to repaint, so without me doing anything.
public class UserInterface {
public static void main(String[] args){
UserInterface GUI = new UserInterface();
GUI.run(args);
}
void run(String[] args){
JFrame window = new JFrame("Main");
window.setLayout(new BorderLayout());
window.setVisible(true);
window.setSize(800, 750);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = new JPanel(new GridLayout(2,2,10,10));
window.add(content, BorderLayout.NORTH );
content.repaint();
}
public void paint (Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.draw(new Rectangle2D.Double(10,10,100,500));
}
}
Thanks

New Topic/Question
Reply



MultiQuote



|