I am having horrible problems getting some examples to work

I am trying to get a couple examples to work from out of Java Examples in a Nutshell, but they are programmed oddly and will not work. I am using a windows 2000 platform with JDK 1.3.1 installed and working properly.
I have so far typed in these 2 examples:
import javax.swing.*;
import java.awt.*;
public class Containers extends JPanel
{ public Containers()
{ this.setBackground(Color.white);
this.setFont(new Font("Dialog", Font.BOLD,24));
JPanel p1 = new JPanel();
p1.setBackground(new Color(200, 200, 200)); // Panel1 is darker
this.add(p1); //p1 is contained by this component
p1.add(new JButton("#1")); //Button 1 is contained in p1
JPanel p2 = new JPanel();
p2.setBackground(new Color(150,150,150)); // p2 is darker than p1
p1.add(p2); // p2 is contained in p1
p2.add(new JButton("#2")); // button 2 is contained in p2
JPanel p3 = new JPanel();
p3.setBackground(new Color(100,100,100));
p2.add(p3); // p3 is contained in p2
p3.add(new JButton("#3")); // button 3 is contained in p3
JPanel p4 = new JPanel();
p4.setBackground(new Color(150,150,150));
p1.add(p4);
p4.add(new JButton("#4")); //button 4 is contained in p4
p4.add(new JButton("#5")); //Button 5 is also contained in p4
this.add(new JButton("#6")); // button 6 is contained in this component
And this program
//ShowComponent.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.lang.reflect.*;
import java.util.Vector;
public class ShowComponent extends JPanel
public static void main(String[] args)
{  // process the command line to get the compenents to display
Vector components = getComponentsFromArgs(args);
// Create a frame (Window) to display the components to display
JFrame frame = new JFrame("ShowComponent");
// Handle window close requests by exiting the VM
frame.addWindowListener(new WindowAdapter() { //anonymous inner class
public void WindowClosing(WindowEvent e) { System.exit(0); }
// set up a menu system that allows the user to select the Look And Feel
// of the component from a list of installed PLAF's
JMenuBar menubar = new JMenuBar(); // create a menu bar
frame.setJMenuBar(menubar); // tell the frame to display the menubar
JMenu plafmenu = createPlafMenu(frame); // create a menu
menubar.add(plafmenu); // Add the menu to the menubar
// Create a JTabbedPane to display each of the components
JTabbedPane pane = new JTabbedPane();
// Now add each component as a tab of the tabbed pane
// use the unqualified component classname as the tab text
for(int i = 0; i < components.size(); i++)
{ Component c = (Component)components.elementAt(i);
String classname = c.getClass().getName();
String tabname = classname.substring(classname.lastIndexOf('.')+1);
pane.addTab(tabname,c);
// Add the tabbedpane to the frame. Note: the call to getContentPane()
// This is required for JFrame, but not for most swing components
frame.getContentPane().add(pane);
// Set the frame size and pop it up
frame.pack(); //Make the frame as big as its children need
frame.setVisible(true); // Make the frame visible on the screen
// The main() method exits now but the Java VM keeps running because
// all AWT programs automatically start an event-handling thread.
//** this static method queries the system to find out what **
//** Pluggable LookAndFeel (PLAF) implementations are available **
//** then it creates a JMenu component that lists each of the **
//** implementations by name and allows the user to select one **
//** of them using JRadioButtonMenuItem components. When the **
//** user selects one, the selected menu item traverses the **
//** component hierarchy and tells all components to use the new**
//** PLAF. **
public static JMenu createPlafMenu(final JFrame frame)
{ //Creates the menu
JMenu plafmenu = new JMenu("Look and Feel");
// Create an object used for radio button mutual exclusion
ButtonGroup radiogroup = new ButtonGroup();
//Look up the available look and feels
UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
//Loop through the plafs, add a menu item for each one
for(int i = 0; i < plafs.length; i++)
{ String plafName = plafs[i].getName();
final String plafClassName = plafs.getClassName();
// Create the menu items
JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));
// tell the menu item what to do when it is selected
item.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ try
{ // Set the new Look And Feel
UIManager.setLookAndFeel(plafClassName);
// tell each component to change its look and feel
SwingUtilities.updateComponentTreeUI(frame);
//tell the frame to resize itsself to its childrens
// new desired services
frame.pack();
catch(Exception ex) {System.err.println(ex);
// Only allow one menu item to be selected at once
radiogroup.add(item);
return plafmenu;
//** this method loops through the command line arguements looking for **
//** class names of components to create and property settings for those**
//** components in the form name=value. this method demonstrates **
//** reflection and JavaBeans introspection as they can be aplied to **
//** dynamically created GUI's **
public static Vector getComponentsFromArgs(String[] args)
{ Vector components = new Vector();  // List of Components to return
Component component = null; // the current component
PropertyDescriptor[] properties = null; // Properties of the component
Object[] methodArgs = new Object[1]; // we'll use this below
nextarg: // this is a labeled loop
for (int i = 0; i < args.length; i++)
{ // loop through all the arguments
// if the argument does not contain an equal sign, then
// it is a component class name. Otherwise it is a
// property setting
int equalsPos = args[i].indexOf('=');
if (equalsPos == -1)
{ // Its the name of a component
try { //Load the named component class
Class componentClass = Class.forName(args[i]);
//Instantiate it to create the component instance
component = ((Component)componentClass.newInstance());
//Use Java beans to introspect the component
//And get the list of properties it supports
BeanInfo componentBeanInfo = Introspector.getBeanInfo(componentClass);
properties = componentBeanInfo.getPropertyDescriptors();
catch (Exception e)
{ // If an step failed, print an error and exit
System.out.println("Can't load, instantiate, " +
"or introspect: " +args[i]);
System.exit(1);
//If we succeeded, store the component in the vector
components.addElement(component);
else { // the arg is a name=value property specification
String name = args[i].substring(0, equalsPos); //property name
String value = args[i].substring(equalsPos+1); //property value
// If we do not hava component to set this proerty on, skip!
if (component == null) continue nextarg;
// Now look through the properties descriptors for this
// Component to find one with the same name
for(int p = 0; p < properties.length; p++)
{ if (properties[p].getName().equals(name))
{ // okay, we found a property of the right name
// now to get its type, and the setter method
Class type = properties[p].getPropertyType();
Method setter = properties[p].getWriteMethod();
//check if property is read- only !
if (setter == null)
{ System.err.println("Property " + name+ "is read-only");
continue nextarg; // continue with the next arguement
// try to convert the property value to the right type
// we support a small set of common property types here
// Store the converted value in an object[] so it can
//be easily passed when we invoke the property setter
try { if (type == String.class)
{ // no conversion needed
methodArgs[0] = value;
else if (type == int.class)
{ // String to int
methodArgs[0] = Integer.valueOf(value);
else if (type == boolean.class)
{ //to boolean
methodArgs[0] = Boolean.valueOf(value);
else if (type == Color.class)
{ // to Color
methodArgs[0] = Color.decode(value);
else if (type == Font.class)
{ // String to Font
methodArgs[0] = Font.decode(value);
else { // if we cannotconvert, ignore the proprty
System.err.println("Property " + name+ " is of unsupported type "
+ type.getName());
continue nextarg;
catch (Exception e)
{ System.err.println("Can't set Property: " + name);
// NOw go to next command-line arg
continue nextarg;
// If we get here we didn't find the named property
System.err.println("Warning: No such property: " + name);
return components;
//** A component subclass that demonstrates nested containers and components.
//** It creates the hierarchy shown below, and uses different colors to
//** distinguish the different nesting levels of the containers
//** containers---panel1----button1
//** | |---panel2----button2
//** | | |----panel3----button3
//** | |------panel40---button4
//** | |---button5
//** |---button6
They both compile fine but when I go to run them together I get an error. the command given in the book to run them both together is:
java ShowComponent\Containers
But it does not work. I also tried to append Containers to the bottom of ShowComponent and I got an error that said public class Containers extends JPanel needs to have its own file called Containers.java . . I do not understand that as the file was named correctly for ShowComponent.java. I need to knw either what the true command is for running the programs together or what to name container.java that will make it run inside of ShowContainer.java
this is very frustrating as I need to know these answers for work and no one here in the IT department knows how to program in Java but me

Hi,
I tried the example and got some weird error messages as follows:
********* error messages*********
ShowComponent.java:90: cannot resolve symbol
symbol : method getName ()
location: class javax.swing.UIManager.LookAndFeelInfo[]
{ String plafName = plafs.getName();
^
ShowComponent.java:91: cannot resolve symbol
symbol : method getClassName ()
location: class javax.swing.UIManager.LookAndFeelInfo[]
final String plafClassName = plafs.getClassName();
^
ShowComponent.java:139: cannot resolve symbol
symbol : method indexOf (char)
location: class java.lang.String[]
int equalsPos = args.indexOf('=');
^
ShowComponent.java:143: cannot resolve symbol
symbol : method forName (java.lang.String[])
location: class java.lang.Class
Class componentClass = Class.forName(args);
^
ShowComponent.java:161: cannot resolve symbol
symbol : method substring (int,int)
location: class java.lang.String[]
String name = args.substring(0, equalsPos); //property name
^
ShowComponent.java:162: cannot resolve symbol
symbol : method substring (int)
location: class java.lang.String[]
String value = args.substring(equalsPos+1); //property value
^
6 errors.
*****end of error messages*****
I use jdk1.3 and Win2000. Can anybody tell me how to delete above error messages?
Thanks a lot.
Li

Similar Messages

  • Problem getting JSP examples to work

    Hi,
    I just installed weblogic few days back. I'm trying to run the jsp examples.
    I cannot get them work. I keep getting 404 object not found error when I try
    an url like
    http://localhost:7004/examplesWebApp/HellowWorld.jsp
    . I followed the docs and run the scripts.
    There is a HellowWorld.jsp file under
    .\bea\wlserver\config\examples\applications\defaultWebApp.
    Also I can run petstore fine or hellowworld works with default server.
    But when I cannot get it tow work with exampleserver
    Any pointer to debug is greatly appreciated.
    There was a 'servlet mapping' error in hte xml parsing in the weblogic.xml file
    which come with istallaiton for the example.
    Anyone experienced that.
    thanks

    if you put the HellowWorld.jsp under
    \bea\wlserver\config\examples\applications\defaultWebApp. that means you
    have it under default webapp, then your url should be:
    http://localhost:7004/HellowWorld.jsp
    The url pattern should be http://server:port/webappName/filename.jsp
    thanks
    "b gosh" <[email protected]> wrote in message
    news:[email protected]..
    >
    Hi,
    I just installed weblogic few days back. I'm trying to run the jspexamples.
    I cannot get them work. I keep getting 404 object not found error when Itry
    an url like
    http://localhost:7004/examplesWebApp/HellowWorld.jsp
    I followed the docs and run the scripts.
    There is a HellowWorld.jsp file under
    \bea\wlserver\config\examples\applications\defaultWebApp.
    Also I can run petstore fine or hellowworld works with default server.
    But when I cannot get it tow work with exampleserver
    Any pointer to debug is greatly appreciated.
    There was a 'servlet mapping' error in hte xml parsing in the weblogic.xmlfile
    which come with istallaiton for the example.
    Anyone experienced that.
    thanks

  • Having a problem getting smpatch update to work

    I keep on getting this error message :
    # smpatch update -i 119108-06
    Unexpected Failure: com.sun.patchpro.util.FailedStateException: StateMachine.start(): com/sun/cc/platform/clientsignature/CNSSignException
    I cannot find any docs on this problem...any ideas ?

    Make sure you setup smpatch to go to sunsolve and use your sunsolve userID and pass correctly as with solaris 10 not all patches all accessable to the world with out a support account.

  • Having a real problem getting my vi to work - great difficulty running sequence as desired

    Hi
    I am have a real problem getting my vi to work as required.
    I would like the my vi (EXAMPLE.vi in the vi library attached) to run continuously.  It should update the graphs on the front pannel and also save data to file when requested using the  save data to file button. (I have written a sub vi. to deal with this data handling and file saving which run in two while loops with the vi as can be seen on inspection of the block diagram)
    Now, what I would like is for the updating to pause whenever I change any of the settings on the front panel (which are controls in the first half of the sequence of the vi) so the hardware is reset.  As it is at the moment I have to stop the vi to change the front panel settings and then restart it in order for the first part of the sequence to run and re-set the values on the hardware.
    I guess I need to use some kind of event driven programming an event stucture or something like that. This is quite advanced and I don't know how to implement it. 
    Can anybody offer any Ideas. 
    Many many thanks
    Ashley
    Attachments:
    test library.llb ‏470 KB

    Hi,
    If you are new to event structures then you may find the following tutorial useful:
    Event-Driven Programming in LabVIEW
    http://zone.ni.com/devzone/conceptd.nsf/webmain/E5F8474BDA20C97786256B5A0066968B?opendocument
    A powerful New Tool for UI Programming--User Interface Event Programming
    http://zone.ni.com/devzone/conceptd.nsf/webmain/2a8ab43b28bbde1086256b830059875c
    Advanced Event Handling with LabVIEW 7 Express
    http://zone.ni.com/devzone/conceptd.nsf/webmain/aa79ff38336eb38886256d2b004aca49#1
    I hope this helps
    All the best
    Kurt

  • I'm having a problem getting on/listening most stations?

    I'm having a problem getting on/listening most stations?

    I really wish I had started counting, you must be post #100 or something.  I suggest you browse this forum.  This issue has been going on for at least 3 days now.  It happens to some part of the time, some for all the time, not at all to others.
    It's not clear what the issue is, or where it lies.  If it's something to do with Apple's servers they are not likely to discuss it.  There was an issue like this a few months ago with the weather widgets and people kept on posting with no news until one day it suddenly started working, again with no news.  If you wish to, you can report to Apple.
    http://www.apple.com/feedback/itunesapp.html
    There are other applications that let you listed to online radio if you are desperate.  Check www.pure-mac.com

  • I am having a problem getting my office jet pro 8500 to go online to print. How do i set it to go on

    I am having a problem getting my office jet pro 8500 to go online to print. How do i set it to go online. I have run all of hp's diagnostics and everything passes. it prints the test pages but will not print any other jobs for me.

    This might help - https://discussions.apple.com/docs/DOC-3792

  • Hello, i am having problems getting face time to work, I keep getting an error message saying the server could not process the registration, I am using the username and password I always have and it has always worked in the past, any ideas?

    Hello, i am having problems getting face time to work, I keep getting an error message saying the server could not process the registration, I am using the username and password I always have and it has always worked in the past, any ideas?

    We aren't Apple, just users like you volunteering to help other users with problems. Threatening to go to Samsung doesn't mean anything to us. What troubleshooting have you tried so far?

  • Having a problem getting the Viber 4 digit SMS access code.

    Having a problem getting the 4 digit SMS access code. Even when I click on the get code tab, It says an error has occurred during the Viber activation process.

    Is Viber an app? have you tried contacting the developer?

  • Hi ya'll! I'm still learning how to navigate my way with Lightroom. (Last time I wrote, I did get some responses that work. Thanks so much!) Now, I have another question. When I try to copy pics from my external drive to a CD/DVD, no matter if do it from

    Hi ya'll! I'm still learning how to navigate my way with Lightroom. (Last time I wrote, I did get some responses that work. Thanks so much!) Now, I have another question. When I try to copy pics from my external drive to a CD/DVD, no matter if do it from LR or my drive, I keep getting the message; "Disk burning is not supported by LR on this computer." I've tried everything I can think of, so, I thought I'd see if anyone may know if there's anything I can do. Or could it be that my computer just can't handle it? Help!!! So frustrating!!  I have a PC Lenovo computer, I don't know if this makes any difference. Any ideas? Thanks so much for your help!!!

    Have you burned Discs with other programs using this computer? Are you certain that you have a drive that will burn discs?

  • I am having problems getting some of my bookmarks to open in Safari

    I am having problems recently with getting some of my bookmarks to open in Safari. They used to open without problems. I have checked to see if the bookmarks were corrupted but the same thing happens when I type the web address in. It shows that it is downloading but never does. I have checked the DNS and added the DNS suggested by Open DNS but this does not help. Any suggestions?

    Welcome!
    It would be very useful if you posted your Mac OS version, your version of Safari, and your model/version of iMac. That info can affect the responses you get. Also remember that there is a special forum area for Safari here:
    http://discussions.apple.com/forum.jspa?forumID=876
    People in that forum would need the same additional info.

  • Having problems with some links not working. Especially with webhost

    I sent this about 1/2 hour ago but never received the confirming email so thought I would try again. Sorry about the dupe if you did receive this.
    I am having a problem with Firefox. I have a website that I need to check stats with. I was able to login but when I clicked on the link for the stats nothing happened. No new page, no new window, no new screen. I tried all links and still nothing. At bottom of page it said "done". Then I got out of the webhost and tried other links, some worked some didn't.
    I went into Safari to check, and I was able to get my stats, so I tried again on Firefox, still nothing. I noticed a few other problems also, where I got the strangest things happening. Like when I tried to get on GoogleAds and YahooAds it didn't recognize me and also started redirecting me to other stuff.
    I prefer using Firefox, is there anyway to make the fixes?

    Downgrading is not supported by Apple.
    For better or worse, the burden is on app developers to make their apps compliant to the current iOS. If they haven't done that, then unfortunately users are stuck until they do so. The most you can do is communicate your issues to your app developers and see if they will get an update out to make their app work again. That or find another app.

  • I'm having a problem getting a custom persona to dispaly.

    I'm having a problem with getting a custom persona to be able to be used, I followed all the size rules, and the instructions for getting it to be used, but it won't stay up. I have FF 4 and windows 7. It will display while I'm in edit, but will not stay up. I do not intend to upload to sight, it's for my own use.

    I went and shut all addons down except for personas and it still persisted not to have my custom one stay "up". but would switch to a gallery one I had on previously. I tried an old custom one I had success with before I updated to FF 4, and it would not let it stay up. Thanks though for the suggestion.

  • HT1688 I am having a problem getting on iTunes Store app

    I am having a problem accessing my iTunes Store app. When ever tap on the app it kicks me right off. I tried to turn my phone off for a few minutes and turn it back on but it didn't work. Can you please help me figure out what is going on.

    Start here and see if any of these steps help.
    Cannot connect to the iTunes Store
    Try this first.
    Try resetting (turning off and then on again) your Wi-Fi router

  • Is anyone else having a problem getting their iPod touch to show up in iTunes?

    I really don't feel like paying iTunes for technical support, so can someone please help me?! My iPod touch will NOT show up on the side bar of iTunes!

    I'm having this problem as well. Did you ever find a resolution? I have a 2nd generation iPod and it doesn't show up as a device on my itunes account. When I connect it, the iPod icon shows up on iTunes but when I click the icon, it disappears. I can't figure out how to edit the content on my iPod. It used to be so easy, but maybe since it's an older unit it's obsolete?? So annoying. I have updated the software and run diagnostics, but its not recognizing the device. Please comment if you found any answers to your issue, it might help me too!

  • Anyone else having a problem getting rented movies to play?

    rented movies will download, but when I try to play them it says unknown error. Anyone had this?

    I'm having this problem as well. Did you ever find a resolution? I have a 2nd generation iPod and it doesn't show up as a device on my itunes account. When I connect it, the iPod icon shows up on iTunes but when I click the icon, it disappears. I can't figure out how to edit the content on my iPod. It used to be so easy, but maybe since it's an older unit it's obsolete?? So annoying. I have updated the software and run diagnostics, but its not recognizing the device. Please comment if you found any answers to your issue, it might help me too!

Maybe you are looking for

  • How do I move photos to a new folder without it showing in the original folder

    I am trying to rearrange my iPhoto 11 folders. Every time I move a photo to a new album it stays in the original folder. If I delete the photo it is gone from both the folder and the album I created. Is there a way to do this. I am trying to separate

  • Is there any Alternate for synronizing a method ???

    Hi, My application uses syncrozation of method to stop multithreading . Is there any effective technology by which i can make it possible ????... My objective is to stop multiple user access a single method at one time. I want only one user can acces

  • Docs for implementing Digital signatures

    Hello Everyone, We would like to implement digital signature in our landscpae for sending Form 16 from SAP system. Please  let me the step by step configuration guide for digital signature along with pre-requistive if anything applicable. Thanks in a

  • "An error occured saving the ActiveX control"

    I pulled up an old LabVIEW program today that I used to work on under Win-NT. Now I use Win-XP. We're talking about LabVIEW 5.1.1 on this program. The program suddenly throws "An error occured saving the ActiveX control" when I try to save the progra

  • Com.borland.jbcl.layout package

    When I am executing my code I am getting this error. "package com.borland.jbcl.layout does not exist" So from where can I download this package and where to load this pacage. Can anyone help me fast.