jQuery in Action, 2nd edition*
The moose likes Applets and the fly likes Applet initialization problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet initialization problem" Watch "Applet initialization problem" New topic
Author

Applet initialization problem

Zach Miller
Greenhorn

Joined: Jun 05, 2010
Posts: 3
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)


Thanks guys.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Jun 05, 2010
Posts: 3
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Jun 05, 2010
Posts: 3
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

Joined: Aug 10, 2005
Posts: 685
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);
 
Don't get me started about those stupid light bulbs.
 
subject: Applet initialization problem
 
Similar Threads
Koch SnowFlake
Problem with java layout and panels and containers
Getting this to move.
Scrollbar not working
Intersection points not being determined accurately- java awt