This is the specific code that is apparently needed to make it work:
import java.awt.*;
import javax.swing.*;
public class ImageDrawing {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(300, 350);
Container contentPane = window.getContentPane();
JOptionPane.showMessageDialog(window, "Apparently this needs to show up before anything is drawn");
Graphics g = contentPane.getGraphics();
g.drawRect(100, 100, 100, 100);
}
}
Is there any particular reason I have to call a JOptionPane before Graphics like this and, more importantly, are there any EASY workarounds that don't involve me making the driver class an extension of a JFrame?
This post has been edited by TheCodeNoob: 12 May 2012 - 05:25 PM

New Topic/Question
Reply


MultiQuote







|