how are you?, i have a problem that i am sure is something really stupid but i can´t figure what it is. I am trying to create a button, so every time i want to use that button that does the action that i want, all i do is create that new button that already owns the action and the resourceBundle.
my code is this:
public class AcceptNewTaskButton extends JButton {
private ActionManager actionManager;
private JButton acceptNewTaskButton;
public AcceptNewTaskButton(JDialog dialog,JDateChooser dateChooser,JTextField textField){
super(ResourceBundle.getBundle("Language").getString("locale_button_accept"));
actionManager = new ActionManager(dialog,dateChooser,textField);
acceptNewTaskButton = new JButton(actionManager.getNewTaskAction(dialog,dateChooser,textField));
}}
This code doesn’t do what i want, because when i code this
okbutton = new AcceptNewTaskButton(dialog,datechooser,newTaskName);
the button is created but it doesn´t perform any action.
But, on the other hand, when i code this
public class AcceptNewTaskButton extends JButton {
private ActionManager actionManager;
private JButton acceptNewTaskButton;
public JButton AcceptNewTaskButton(JDialog dialog,JDateChooser dateChooser,JTextField textField){
actionManager = new ActionManager(dialog,dateChooser,textField);
acceptNewTaskButton = new JButton(actionManager.getNewTaskAction());
acceptNewTaskButton.setText(ResourceBundle.getBundle("Language").getString("locale_button_accept"));
return acceptNewTaskButton;
}}
And i type this
okButton = new AcceptNewTaskButton().AcceptNewTaskButton(dialog,dateChooser,newTaskName);
The action is perfectly performed.
I would like to know why this is happening, i think it is something simple but i can´t see it. I would like to do it this way because i want to have a class of every button in a package called buttons, and in this way make my code more “object oriented”
Thank you so much!
pd: excuse me if i commited any grammar mistake, english isn´t my native language
Your class already extends JButton so you don’t want to create a new button.
I think you should be doing: