🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages Started by Guillermo Mon, 27 Sep 2004 01:57
Action Problem
#841
Author: Guillermo
Date: Mon, 27 Sep 2004 01:57
107 lines
4682 bytes
Hi,
I defined a simple action class (AccionAlta) to test actions functionality;
when I create a button in another Frame class (FrameBanco) referencing the
action class, I get the following error:

Hit uncaught exception java.lang.ClassCastException
java.lang.ClassCastException
 at javax.swing.AbstractButton.configurePropertiesFromAction(Unknown Source)
 at javax.swing.AbstractButton.configurePropertiesFromAction(Unknown Source)
 at javax.swing.JMenuItem.configurePropertiesFromAction(Unknown Source)
 at javax.swing.AbstractButton.setAction(Unknown Source)
 at javax.swing.JMenuItem.<init>(Unknown Source)
 at lyr.FrameBanco.<init>(FrameBanco.java:31)
 at lyr.FrameMain.jMenuBancos_actionPerformed(FrameMain.java:138)
 at
lyr.FrameMain_jMenuBancos_actionAdapter.actionPerformed(FrameMain.java:188)
 at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
 at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
Source)
 at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
 at javax.swing.AbstractButton.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
 at
javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unkno
wn Source)
 at java.awt.Component.processMouseEvent(Unknown Source)
 at java.awt.Component.processEvent(Unknown Source)
 at java.awt.Container.processEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)

----------
The Action Class is:

package lyr;

import javax.swing.*;
import java.awt.event.*;

public class AccionAlta extends AbstractAction
{

  public AccionAlta()
  {
    putValue(Action.NAME, "Alta");
    putValue(Action.SMALL_ICON, "icons/db insert.bmp");
    putValue(Action.SHORT_DESCRIPTION, "Alta" );
    putValue(Action.LONG_DESCRIPTION, "Alta de un nuevo registro");
    putValue(Action.MNEMONIC_KEY, "A");
    putValue(Action.ACTION_COMMAND_KEY, "Comando Alta");
  }

  public void actionPerformed(ActionEvent e)
  {
    JOptionPane.showMessageDialog(null,"Acci�n Alta!",
"Hey!",JOptionPane.INFORMATION_MESSAGE);
  }
}

-----
The error arises in the last line of the following code of FrameBanco class,
that references the action class:

package lyr;

import javax.swing.*;
import java.awt.*;
import com.borland.dx.dataset.DataModule;
import com.borland.dbswing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;


public class FrameBanco
    extends JFrame
{

  AccionAlta accionAlta = new AccionAlta();

  protected DataModuleLyR dataModuleLyR;
  BorderLayout borderLayout2 = new BorderLayout();
  JMenuBar jMenuBarBanco = new JMenuBar();
  JMenu jMenuArchivo = new JMenu();
  JMenuItem jMenuItemSalida = new JMenuItem();
  JMenu jMenuEdicion = new JMenu();
  JMenuItem jMenuItemAlta = new JMenuItem(accionAlta);  // Error

------------

I appreciate any help please.

Thank you,
Guillermo
Re: Action Problem
#842
Author: Tor Iver Wilhelmsen [TeamB]
Date: Mon, 27 Sep 2004 06:50
13 lines
1250 bytes
"Guillermo" <gnajar@gnsis.net> writes:

>     putValue(Action.SMALL_ICON, "icons/db insert.bmp");

This should be an actual Icon, not just a file name. Use ImageIcon to
load the bitmap.

>     putValue(Action.MNEMONIC_KEY, "A");

Should be a KeyEvent, not a String.

See the docs for javax.swing.Action, the descriptions of the constants
say what type of object should be used as the value.
Re: Action Problem
#843
Author: Guillermo
Date: Tue, 28 Sep 2004 15:27
17 lines
1421 bytes
Thank you !

"Tor Iver Wilhelmsen [TeamB]" <tor.iver.wilhelmsen@broadpark.no> wrote in
message news:ufz54kxy7.fsf@broadpark.no...
> "Guillermo" <gnajar@gnsis.net> writes:
>
> >     putValue(Action.SMALL_ICON, "icons/db insert.bmp");
>
> This should be an actual Icon, not just a file name. Use ImageIcon to
> load the bitmap.
>
> >     putValue(Action.MNEMONIC_KEY, "A");
>
> Should be a KeyEvent, not a String.
>
> See the docs for javax.swing.Action, the descriptions of the constants
> say what type of object should be used as the value.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads