Results 1 to 3 of 3
  1. #1
    Manojx is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Exclamation Can anyone say how i fix this error as i'm a beginner

    Hi to all,

    i'm a beginner to Java and trying to execute the following code snippet. i actually downlaoded this code from How to Use Split Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) and the code was compiled and executed but i didn't get any output as it is shown and i kept getting this error message :

    Error Message :-

    C:\tt>Appletviewer SplitPaneDemo.java

    java.lang.NoClassDefFoundError: SplitPaneDemo (wrong name: components/SplitPaneD
    emo)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:12
    4)
    at sun.applet.AppletClassLoader.findClass(AppletClass Loader.java:178)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.applet.AppletClassLoader.loadClass(AppletClass Loader.java:127)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at sun.applet.AppletClassLoader.loadCode(AppletClassL oader.java:618)
    at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:778)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java: 707)
    at sun.applet.AppletPanel.run(AppletPanel.java:361)
    at java.lang.Thread.run(Thread.java:619)


    Code for the program as follows :

    package components;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;

    /* <applet code = "SplitPaneDemo.class" height =200 width = 400>
    </applet> */

    //SplitPaneDemo itself is not a visible component.
    public class SplitPaneDemo extends JPanel
    implements ListSelectionListener {
    private JLabel picture;
    private JList list;
    private JSplitPane splitPane;
    private String[] imageNames = { "Bird", "Cat", "Dog", "Rabbit", "Pig", "dukeWaveRed",
    "kathyCosmo", "lainesTongue", "left", "middle", "right", "stickerface"};
    public SplitPaneDemo() {

    //Create the list of images and put it in a scroll pane.

    list = new JList(imageNames);
    list.setSelectionMode(ListSelectionModel.SINGLE_SE LECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);


    JScrollPane listScrollPane = new JScrollPane(list);
    picture = new JLabel();
    picture.setFont(picture.getFont().deriveFont(Font. ITALIC));
    picture.setHorizontalAlignment(JLabel.CENTER);

    JScrollPane pictureScrollPane = new JScrollPane(picture);

    //Create a split pane with the two scroll panes in it.
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
    listScrollPane, pictureScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);

    //Provide minimum sizes for the two components in the split pane.
    Dimension minimumSize = new Dimension(100, 50);
    listScrollPane.setMinimumSize(minimumSize);
    pictureScrollPane.setMinimumSize(minimumSize);

    //Provide a preferred size for the split pane.
    splitPane.setPreferredSize(new Dimension(400, 200));
    updateLabel(imageNames[list.getSelectedIndex()]);
    }

    //Listens to the list
    public void valueChanged(ListSelectionEvent e) {
    JList list = (JList)e.getSource();
    updateLabel(imageNames[list.getSelectedIndex()]);
    }

    //Renders the selected image
    protected void updateLabel (String name) {
    ImageIcon icon = createImageIcon("images/" + name + ".gif");
    picture.setIcon(icon);
    if (icon != null) {
    picture.setText(null);
    } else {
    picture.setText("Image not found");
    }
    }

    //Used by SplitPaneDemo2
    public JList getImageList() {
    return list;
    }

    public JSplitPane getSplitPane() {
    return splitPane;
    }


    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = SplitPaneDemo.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    }
    }

    /**
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    */
    private static void createAndShowGUI() {

    //Create and set up the window.
    JFrame frame = new JFrame("SplitPaneDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    SplitPaneDemo splitPaneDemo = new SplitPaneDemo();
    frame.getContentPane().add(splitPaneDemo.getSplitP ane());

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }


    }

    There are some files came along with this i can't attach them here so by following this link you can download all the files that required to execute this program

    Take a look at " S " Section and download the "SplitPaneDemo" files.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Please use code tags when posting code in the forum. If you click on the link in my signature, you'll see how to use these.

    Now as for your problem, where's your code to create a JApplet?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

Similar Threads

  1. Need Help - Beginner
    By ooooohmaul in forum New To Java
    Replies: 4
    Last Post: 08-08-2010, 05:22 AM
  2. Beginner, need a little help
    By jimmy-lin in forum New To Java
    Replies: 6
    Last Post: 10-10-2009, 02:00 AM
  3. beginner here...help please
    By shroomiin in forum New To Java
    Replies: 6
    Last Post: 09-16-2009, 12:06 AM
  4. Beginner needs help!
    By Polyy in forum New To Java
    Replies: 1
    Last Post: 11-27-2008, 06:12 AM
  5. almost done...beginner needs help plz..
    By shongo in forum New To Java
    Replies: 15
    Last Post: 11-10-2008, 09:14 AM

Posting Permissions

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