This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I'm writing an app to do draw some simple 2D graphics and text in a window (the window launches from a button in the app), but I'm having trouble with g.drawString(). It works perfectly the first time I launch the window from the app, however, it doesn't come up properly if I close my 2D my graphics window and reopen it again. Specifically, the window doesn't fully open, and if I minimize and reopen it appears all black. This doesn't happen if comment out the g.drawString command.
So when I remove the "test" string it works fine; I can close and reopen the window I am graphing 2D graphics in as many times as I like. However, as soon as I put the string in the window doesn't open properly. Any thoughts?
Right now I am running this app from Eclipse EE (ver 188.8.131.522-2012)
In future, while posting code, please UseCodeTags. I have added them for you this time. As you can see the code tags, make the code much more easier to read and understand.
Based on the code you have provided, looks like you are using AWT instead of Swing. Any particular reason for it?
It is quite easy to switch to Swing. Almost every AWT component has a Swing replacement. Typically Swing components are named Jxxxx
e.g. Button (AWT) -> JButton(Swing)
Regarding custom painting, one important point to note is, instead of invoking the paint, you need to invoke paintComponent()
Also make sure that you call super.paintComponent as the first line from inside your paintComponent
I tried your suggestion, but unfortunately I couldn't get any image to display. I looked over a bunch of examples and I can't seem to find what I'm doing wrong; why it won't display. Here is my code, and the portion that I can't get to work is the paintComponent method, lines 36-42. Thanks for any help you can provide; I am a rookie at coding.