• Post Reply Bookmark Topic Watch Topic
  • New Topic

My *stupid* questions...  RSS feed

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for the previous tips, I am learning SWING ( and will probably ditch AWT). I've a few very newbie, stupid questions:
(1) Why is SWING a "light weight" container whereas AWT is "heavy weight"? What's is meant by that? Does SWING use less resource?
(2) Without exceptions, *all* the docos and sample codes that I've been reading the last 2days use "public static void main(String args[])" i.e. run at command line level with "java HelloWordSwing" and *none* are applets which can be invoked by html's code tag. But all my stuff are applets!
This beginner's code has the JAVA console throwing up more errors than there are lines of code when I tried running it in html:

Here is the simple html

ANd here is the JAVA console output
java.lang.ClassCastException
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
TIA :-)
 
Vikalp Setya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The applet class should extend javax.swing.JApplet not JFrame.
public class MyApplet extends JApplet
{
public void init()
{
//put in ur components here
JLabel label = new JLabel("swing is cool");
getContentPane().setLayout(new BorderLayout());
getContentPane().add(label,BorderLayout.CENTER);

//do some layout stuff and put in some components
}
}
Now create that HTML file to use MyApplet class.

I just typed the code and may contain a few errors.
2 )
Swing is lightweight as i goesn't create new windows for each of the components. recall the createWindow(...) function of MFC that creates a heavyweight window for each of components(label,button) etc like AWT. SWing creates a heavy weight component for the frame only(JFrame,JDialog) etc and each of components that you put in that frame is not heavyweight(label, buttons, tree etc).Please consult some good book on swing for further information like Graphic Java by David Geary.
Regards,
vikalp
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!