Strange Cast Exception - AbstractAction
Hi all,
NOTE: for some strange reason - - does not format my code.
I am busy designing a biggish swing application and I was taken aback by a cast exception. As I was not expecting an exception I decided to test this somewhere else.
So I have class (ActionFactory
) that extends AbstractAction. The Main class I am testing from is [PopWindowManager->callsTest()-> creates a button and a new action. Then set the action to the button
My code is as follows:
//
//Test ActionFactory
//
privateclass ActionFactoryextends AbstractAction{
/**
* Constructor to create an new action from the gvien parameters.
* @param name
* @param hint
* @param mnemonic
*/
public ActionFactory(String name, String hint,char mnemonic){
putValue(Action.NAME, name);
putValue(Action.SHORT_DESCRIPTION, hint);
putValue(Action.MNEMONIC_KEY, mnemonic);
}
publicvoid actionPerformed(ActionEvent e){
System.out.println("Check if this has an exception as well");
}
}
//
//Then I have fucntion to test the action into. Uses a JButton
//
privatevoid test(){
JButton test =new JButton();
ActionFactory factory =new ActionFactory("Test","Click To Test",'T');
test.setAction(factory);
}// test--
//
//Here is the exception
//
Exception in thread "main" java.lang.ClassCastException: java.lang.Character
at javax.swing.AbstractButton.configurePropertiesFromAction(AbstractButton.java:11 17)
at javax.swing.AbstractButton.configurePropertiesFromAction(AbstractButton.java:10 63)
at javax.swing.JButton.configurePropertiesFromAction(JButton.java:220)
at javax.swing.AbstractButton.setAction(AbstractButton.java:997)
at com.mkhululi.desktion.popup.PopWindowManager.test(PopWindowManager.java:120)
at com.mkhululi.desktion.popup.PopWindowManager. (PopWindowManager.java:112)
at com.mkhululi.desktion.popup.PopWindowManager.main(PopWindowManager.java:127)
//
PLEASE, help what am I doing wrong!
Thanks in advance!
Yours,
Me
NOTE: for some strange reason - - does not format my code.

