I know its easy but I am freaking doing it for about 2 hours now and I can’t seems figure out why I can’t pass the JTextArea value from a variable to the other java files because I separated my ActionEvent code to another File from my Object (specifically the JTextArea), guys find out what went wrong on my code.
actionlistener code:
public class ButtonAction{
public static class AddInv implements ActionListener{
public void actionPerformed(ActionEvent e){
AbstractButton inv = (AbstractButton)e.getSource();
AddInventory addInv = new AddInventory();
if(inv.getActionCommand().equals("SAVE")){
invName = addInv.areaName.getText();
JOptionPane.showMessageDialog(null, invName);
}
}
}
}
Here’s my Button and textarea object code from another java file, this is my class AddInventory:
ActionListener add = new ButtonAction.AddInv();
areaName = new JTextArea(2, 35);
//my TextArea
JButton buttonSave = new JButton("SAVE");
buttonSave.addActionListener(add);
Guys can you try this code and tell me if it is working in your computer guys.
because what I’m planning to do is save this text area value to my database.
I’m already connected the oracle database and I just need to insert some records.
I’d start by examining the purpose of
To me, this says, create me a new
AddInventoryand give me the default value of it’sareaNametext field…which is probably nothing…UPDATE
Still the same problem…
Some how, you either need to pass the reference to the text area to the action…
UPDATE EXAMPLE
Ideally you want some kind of controller/model to take care of this, but as an example…
And you action class…