actionlistener

Java actionListener for a nameless JButton?

Hey everyone, I was wondering if there is a way to implement an action listener for a Jbutton without a name. For example, I have the following for loop that creates a button for each letter of the alphabet. for (int i = 65; i < 91; i++){ alphabetPanel.add(new JButton("<html><center>" + (char)i)); } Is there a way that I can add...

How do you add an ActionListener onto a JButton in Java

private JButton jBtnDrawCircle = new JButton("Circle"); private JButton jBtnDrawSquare = new JButton("Square"); private JButton jBtnDrawTriangle = new JButton("Triangle"); private JButton jBtnSelection = new JButton("Selection"); I would like to add action listeners to these buttons, so from a main method I can call actionperformed on ...

Accessing a "nameless" Jbutton in an anonymous class from another anonymous class?

Hey all, alright I know this sounds a little far-fetched, but let me explain. I created 26 JButtons in an anonymous actionListener labeled as each letter of the alphabet. for (int i = 65; i < 91; i++){ final char c = (char)i; final JButton button = new JButton("" + c); alphabetPanel.add(button); butt...

Intercepting Exceptions with custom JSF event handlers

Is there any way to create a custom ActionListener class in JSF so that I can intercept an exception if it occurs on pressing the command button using my own ActionListener class I tried using the following code: firstpage.jsp <f:view> <html> <head> <title>firstpage</title> </head> <body> <h:form> ...

Calling this from inside a nested Java ActionListener.

Suppose I have this: class external { JFrame myFrame; ... class internal implements ActionListener { public void actionPerformed(ActionEvent e) { ... myFrame.setContentPane(this.createContentPane()); } } ... } createContentPane returns a Container. Now, if I wa...

ICEFaces action vs actionListener

I am not clear on the difference between these two methods. I see that the actionListener takes an ActionEvent as a parameter, but both may be tied to a method in the backing bean. Is the only functional difference the ActionEvent parameter? So if I need ActionEvent use the listener method, if not, either will work? ...

Is there a standard way to handle many different options for mouse events in java?

Hi all. I'm developing a grid based sim game in java, and I was wondering if there is a standard way of doing the following. I have a panel which is the game panel, and there are many different things which could happen when the panel is clicked. For example, when building a room, there are several stages, where dragging the mouse and l...

action listeners and event sources in Swing

OK, so if I add an ActionListener to a GUI element, and it's the only element I use that ActionListener with, does it matter which of the following lines (a,b) I use to get the checkbox selected state? final JCheckBox checkbox = (JCheckBox)this.buildResult.get("cbDebugTick"); checkbox.addActionListener(new ActionListener() { @Override ...

Icefaces: Multiple actionListeners for command button

Hi Folks, Is it possible to have multiple actionListeners on a command button? If not is there any way around this? Thanks for your help! ...

Java: Using an actionlistener to call a function in another class on an object from that class

Basically what I want to do is get a start button to initiate a method running in another class and acting on another object. My code for the listener: button1a.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent event) { // Figure out how to make this work //sim.runCastleCrash(); } }...

get input Text from JTextField (string to char) to show up in JButton

(new rewritten code).. I just know that "b" will always the last box that i created.So i can't use b as the equals in actionPerformed. How to include all the buttons? Anyone can help me with this? import java.awt.; import javax.swing.; import java.awt.event.*; public class Lat1 extends JFrame implements ActionListener { ...

ActionListener on JLabel or JTable cell

I have a JTable with JLabel[][] as data. Now I want to detect a double click on either the JLabel or a table cell (but only in one of the columns). How can I add an Action/MouseListener on JLabel respectively table cell? ...

Compile error when adding ActionListener to Array created GUI

I had a huge file for creating this GUI and I have shortened by using arrays. I am trying to add an ActionListener when the arrays are being added and I am getting this error /tmp/jc_3531/GUI.java:60: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (GUI) nButtons[c].addActionList...

Using an ActionListener in one class to start a timer in another class.

I have a class (simulation) which creates an instance of another class (GUI). Inside the class GUI there is a button (start) which has an actionlistener attached to it. I need this actionlistener to start a timer in simulation but I can't figure out how to do it. Code in Class Simulation: public class Simulation{ private static JFram...

Performing an action when an JMenuItem is clicked?

So i have made a simple program with a basic menu at the top of the frame, Now i just need to put actions behind each JMenuItem. Im struggling to work the code out though, Here is what i thought would work: JMenu file_Menu = new JMenu("File"); JMenuItem fileExit = new JMenuItem("Exit Program"); file_Menu.add(fileExit); fileExit.addActi...

When i import from a file, click the next and previous buttons it is exporting data to my file? is there something wrong with my action listeners?

public AddressBookApp(){ frame = new JFrame("Address Book"); frame.setSize(500, 400); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); panel = new JPanel(); panel.setBackground(Color.gray); panel.setLayout(null); frame.add(panel); frame.setVisible(true); JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); JM...

use EventObject.getSource in Actionlistener

Hi, I am refactoring some code for an assignment - currently the view has lots of buttons and menus and one action listener which decides what to do by using event.getSource(). From what I've read people seem to think its better for each GUI component to have its own action listener, perhaps created through some kind of factory. However ...

Refactoring multiple actionListeners

I am currently working on some Java code that has a lot of ActionListeners defined in it (one for each JButton) and there are around 60 buttons. These are all defined as anonymous inner classes in the JButton.addActionListener method. I have been thinking of ways to refactor this to make the code look neater as this is making it looked v...

Java: Roller program - debug - variables not updating from JTextField and NumberFormatException thrown regardless of valid information.

Problems: I am unable to get the values of the JTextFields or the rollResultTotal to update. Even if the data in the JTextFields are valid, a NumberFormatException is still thrown. Questions: Why don't the variables stay? Is this due to declaration in the class itself? Is it possible to update a JLabel panel to show an updated resu...

How could I implement new JFrame functionality.

I am trying to remove the drag bar across the top of the JFrame. I would like to keep the minimize maximize and close options that appear on this bar available. What I was thinking was to remove the bar (and icons). Then add the icons as embedded images, that implement the JFrame actionlistener. It would also be necessary for this to wor...