Results 1 to 14 of 14
Thread: Please help me ASAP!
- 05-17-2011, 05:17 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
Please help me ASAP!
Hey guys.. I was looking to study from this code example the guys over at oracle.com made:
Java Code:/* * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of Oracle or the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package components; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * @author ges * @author kwalrath */ /* MenuLayoutDemo.java requires no other files. */ public class MenuLayoutDemo { public JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.PAGE_AXIS)); menuBar.add(createMenu("Menu 1")); menuBar.add(createMenu("Menu 2")); menuBar.add(createMenu("Menu 3")); menuBar.setBorder(BorderFactory.createMatteBorder(0,0,0,1, Color.BLACK)); return menuBar; } // used by createMenuBar public JMenu createMenu(String title) { JMenu m = new HorizontalMenu(title); m.add("Menu item #1 in " + title); m.add("Menu item #2 in " + title); m.add("Menu item #3 in " + title); JMenu submenu = new HorizontalMenu("Submenu"); submenu.add("Submenu item #1"); submenu.add("Submenu item #2"); m.add(submenu); return m; } /** * 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("MenuLayoutDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. MenuLayoutDemo demo = new MenuLayoutDemo(); Container contentPane = frame.getContentPane(); contentPane.setBackground(Color.WHITE); //contrasting bg contentPane.add(demo.createMenuBar(), BorderLayout.LINE_START); //Display the window. frame.setSize(300, 150); 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(); } }); } class HorizontalMenu extends JMenu { HorizontalMenu(String label) { super(label); JPopupMenu pm = getPopupMenu(); pm.setLayout(new BoxLayout(pm, BoxLayout.LINE_AXIS)); } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getMaximumSize() { return getPreferredSize(); } public void setPopupMenuVisible(boolean b) { boolean isVisible = isPopupMenuVisible(); if (b != isVisible) { if ((b==true) && isShowing()) { //Set location of popupMenu (pulldown or pullright). //Perhaps this should be dictated by L&F. int x = 0; int y = 0; Container parent = getParent(); if (parent instanceof JPopupMenu) { x = 0; y = getHeight(); } else { x = getWidth(); y = 0; } getPopupMenu().show(this, x, y); } else { getPopupMenu().setVisible(false); } } } } }
- 05-17-2011, 05:23 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Can you copy and paste the error...that's unreadable.
Also identify what line it occurred on.
- 05-17-2011, 05:47 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-17-2011, 06:10 PM #4
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 05-17-2011, 06:17 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
Oh shikes.. sorry for that attachment.. didn't know the forum would shrink it down so much.. Sorry!
Thanks for teaching me something new! :)
Java Code:Exception in thread "main" java.lang.NoClassDefFoundError: MenuLayoutDemo (wrong name: components/MenuLayoutDemo) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14 1) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: MenuLayoutDemo. Program will exit. Press any key to continue . . .
- 05-17-2011, 06:19 PM #6
Where is the command line you used to execute the program?
The program is in a package, so you need to consider that when executing the program.
In the folder containing the components folder, enter:
java components.MenuLayoutDemo
- 05-17-2011, 06:21 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-17-2011, 06:24 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
- 05-17-2011, 06:27 PM #9
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
I ran it as components.MenuLayoutDemo and it still gave me the same error.. The class file and java file are in the same folder!
- 05-17-2011, 06:37 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
And are you running the command from the folder above that one?
Not the components folder.
- 05-17-2011, 06:49 PM #11
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
remove "package components;" from the code.
- 05-17-2011, 06:53 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-17-2011, 06:54 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 05-17-2011, 06:55 PM #14
Similar Threads
-
Please need help asap
By Tamtome in forum New To JavaReplies: 9Last Post: 02-04-2011, 09:19 PM -
Need help ASAP, please
By KAM0002 in forum New To JavaReplies: 6Last Post: 12-08-2010, 05:58 PM -
Need help asap please!
By mbm4ever in forum Java AppletsReplies: 4Last Post: 08-12-2010, 04:57 PM -
Need some help ASAP
By varma in forum New To JavaReplies: 11Last Post: 01-08-2010, 01:15 AM -
HELP PLEASE! Need reply ASAP
By SteroidalPsycho in forum New To JavaReplies: 3Last Post: 10-21-2009, 09:28 AM
Bookmarks