SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My First Swing Program

    I am investigating Java Swing at [URL=http://java.sun.com/docs/books/tutorial/uiswing/mini/firstexample.html]
    Trying to use the appletviewer to run the HTML but get message of:
    start:applet not initialized (in the appletviewer)
    and

    C:\JavaPrograms> appletviewer SwingApplication.html
    java.lang.ClassCastException: SwingApplication
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:579)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:515)
    at sun.applet.AppletPanel.run(AppletPanel.java:293)
    at java.lang.Thread.run(Thread.java:484)

    in the MSDOS window.

    Went to the jdk1.3.1\demo\jfc\SwingApplet file to see if there is something missing and tried to run the swingapplet.html file. It opened a browser window with a grey rectangle of the right size but nothing else. This is the same thing that occurs when I try to run the SwingApplication without using the appletviewer. Both say that the applet is started and the browser indicates that the download is done but nothing else. I am using Windows '98/IE5 and N6.
    Do I need another component to the java environment. The article says that if I am using Java2 all the swing componenets are in the core. I am able to run other applets such has the clock.

  2. #2
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did some swing stuff in my final year at uni, we had to design and implement our own look and feel. Unfortunatly i've only done java for applications, never done appletts in it

    To get the code to run as an application, copy the code below into a file called HelloWorldSwing.java compile it with javac.exe which will create HelloWorldSwing.class which can then be run with java.exe

    Note: if the file name is not the same as the name of the public class inside then you will get a compile time error.

    Code:
    import javax.swing.*;        
    
    public class HelloWorldSwing {
        public static void main(String[] args) {
            JFrame frame = new JFrame("HelloWorldSwing");
            final JLabel label = new JLabel("Hello World");
            frame.getContentPane().add(label);
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    }
    Drinky


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •