invoking a class

hye..

i have a question here..

i have a radiobutton here and i would like to call a class by selecting the radiobutton..

i've tried to use new 'classname'() but it didn't work..

could please help me with this..

privatevoid jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt){

// TODO add your handling code here:

if(evt.getStateChange()== ItemEvent.SELECTED)

new argmnt(); [b]//i need to call class argmnt() [/b]

}

thanks in advanced

[761 byte] By [masliyanaa] at [2007-11-26 22:49:12]
# 1

Did you remember to add the item listener to the JRadioButton? For example if the button is named "buttonName" did you make a call similar to the following?

buttonName.addItemListener( new ItemListener() {

public void itemStateChanged(ItemEvent e) {

new argmnt();

}

});

Also, are you using either the NetBeans or Eclipse builders to build your user interface? If so, you probably need to follow a special procedure for adding a listener to the JRadioButton because those editors don't let you modify the code directly (at least I don't think they do).

@modia at 2007-7-10 12:09:30 > top of Java-index,Java Essentials,New To Java...
# 2

im using netbeans

as far as i know..

i just have to right click on radiobutton and select the actionlistener (ItemStateChanged)

and it will automatically add the listener in the source page..

am i right?did i miss any step?

i've done this before using the same class and it works.

masliyanaa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 3

> Also, are you using either the NetBeans or Eclipse builders to build your user

> interface? If so, you probably need to follow a special procedure for adding a

> listener to the JRadioButton because those editors don't let you modify the code

> directly (at least I don't think they do).

If that is true, whoever designed that tool should be horse-whipped.

DrLaszloJamfa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 4
so..is there any idea to help me solving with this?
masliyanaa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 5
Sure. What exactly "didn't work"? Is your listener never being invoked, or does the "new ..." statement not compile/run?
Lokoa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 6
You can invoke a class at runtime like this, using the log4j api:import org.apache.log4j.helpers.Loader;Object object = Loader.loadClass("classname").newInstance();Message was edited by: ReggieBE
ReggieBEa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 7

> You can invoke a class at runtime like this, using

> the log4j api:

>

> import org.apache.log4j.helpers.Loader;

> Object object =

> Loader.loadClass("classname").newInstance();

I'm willing to be a dozen doughtnuts that that is not the best way to solve

the OP's problem, whatever it is. Why compilacate things with refection?

Why suggest it? What made you think it was appropriate in this case?

DrLaszloJamfa at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 8

> > You can invoke a class at runtime like this, using

> > the log4j api:

> >

> > import

> org.apache.log4j.helpers.Loader;

> > Object object =

> >

> Loader.loadClass("classname").newInstance();

>

> I'm willing to be a dozen doughtnuts that that is not

> the best way to solve

> the OP's problem, whatever it is. Why compilacate

> things with refection?

> Why suggest it? What made you think it was

> appropriate in this case?

not only that, but why couple their code to log4j? a silly suggestion

georgemca at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...
# 9

Is it not working when you actually run the application, or when you click the Preview Design button in the GUI builder? I tried creating an application, and if you use the Preview Design button instead of actually running the application, it doesn't seem to work, but if you run the application, everything seems to work fine.

@modia at 2007-7-10 12:09:31 > top of Java-index,Java Essentials,New To Java...