[Solved] Action Listeners [closed]

And how would i make it work form a different class file? Import it, if you need to, and then create an instance of it. how to use the action listeners that are attached to the buttons Place the logic that you’d like to be executed within the actionPerformed(ActionEvent e) method of the ActionListener class … Read more

[Solved] Activating JButton when radio button is enabled? [closed]

Use itemStateChanged event to detect the radio button enabled & do your stuff, @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { yourButton.enabled=true; } else if (e.getStateChange() == ItemEvent.DESELECTED) { yourButton.enabled=false; } } 1 solved Activating JButton when radio button is enabled? [closed]

[Solved] Mouse event handling in Swing

Add an actionlistener to your JButton and it will tell you when its been clicked like so: someButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { //the button was pressed and do your stuff here. } } 3 solved Mouse event handling in Swing

[Solved] how do i create a method that generates a JButton? [closed]

You can of course write a method that creates JButton for you: public JButton createButton(String label, ActionListener listener, int x, int y) { JButton b = new JButton(label); name.addActionListener(listener); name.setBounds(x, y, 150, 50); return b; } and then use the method like this: button19 = createButton(“Toiletsager”, this, 100, 100); You can of course also specify … Read more

[Solved] java.lang.NullPointerException on method

Problem is in the actionPerformed() method. The class variable patient is null. You can do a null check like this… public void actionPerformed(ActionEvent e) { if(e.getSource() == reportButton && patient != null) { System.out.println(“I’m Clicked!”); patient.setAge(ageField, log); } } Or you can initalize the variable… public void actionPerformed(ActionEvent e) { if (patient == null) { … Read more