Hi, I am making an animation for my intro to Java class, and I seem to be having some problems with it. I believe I'm on the right track, but when I run the applet (it compiles fine) it says "applet not initialized." Obviously this has something to do with the init() part of the class, but I can't figure out what. I'm not too good with making GUI's in Java. Anyway, here's the code. (by the way it's purpose is to draw an ipod on the screen originally, then when the button is pushed, it will "grow" into an ipad)
I'm no applet pro, but it appears to me that you are concentrating on building a JFrame when you should be building an applet. One major problem is that you have a paintComponent method present as if it is being overridden, but it's not. To prove this, place an @Override annotation above this method and you'll see a compiler error telling you this.
I suggest that you create your GUI in a JPanel -- that way the paintComponent method will work, and then place this JPanel into your JApplet's contentPane.
edit: also in this section here you desire to do animation (I'm guessing). If you want to see the image grow, you'll probably want to use a Swing Timer not the while loop, and you definitely don't want to have this program logic and a repaint call in the paintComponent method.
Joined: Jun 05, 2010
Ok thanks, I wasn't sure about the Swing Timer, that's what I was going to use, but I couldn't figure out how to implement it properly. I'll figure that out, and ill work on the JPanel. Thanks, I appreciate the advice.
Joined: Feb 23, 2007
Zach Miller wrote:Ok thanks, I wasn't sure about the Swing Timer, that's what I was going to use, but I couldn't figure out how to implement it properly. I'll figure that out, and ill work on the JPanel. Thanks, I appreciate the advice.
No problem. Here's a general skeleton of code that has worked for me, and may work for you, but you'd have to supply the details.
Joined: Jun 05, 2010
Yep.... that seems like basically exactly what I was attempting to do haha. I'll definitely make use of that. Thanks I appreciate it.
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
Applets should NOT use System.exit(). Its probably buried in: