Results 1 to 3 of 3
- 03-11-2011, 07:15 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
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.
-
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?
- 03-12-2011, 02:14 PM #3
Similar Threads
-
Need Help - Beginner
By ooooohmaul in forum New To JavaReplies: 4Last Post: 08-08-2010, 04:22 AM -
Beginner, need a little help
By jimmy-lin in forum New To JavaReplies: 6Last Post: 10-10-2009, 01:00 AM -
beginner here...help please
By shroomiin in forum New To JavaReplies: 6Last Post: 09-15-2009, 11:06 PM -
Beginner needs help!
By Polyy in forum New To JavaReplies: 1Last Post: 11-27-2008, 05:12 AM -
almost done...beginner needs help plz..
By shongo in forum New To JavaReplies: 15Last Post: 11-10-2008, 08:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks