This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet initialization problem

 
Zach Miller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Zach Miller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Zach Miller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.... that seems like basically exactly what I was attempting to do haha. I'll definitely make use of that. Thanks I appreciate it.
 
Norm Radder
Ranch Hand
Posts: 733
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run the applet I get this error:
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkExit(SecurityManager.java:744)
at javax.swing.JFrame.setDefaultCloseOperation(JFrame.java:377)
at ipod_VS_ipad.init(ipod_VS_ipad.java:45)
at sun.applet.AppletPanel.run(AppletPanel.java:418)
at java.lang.Thread.run(Thread.java:619)



Applets should NOT use System.exit(). Its probably buried in:

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic