, , . , , , . myButton.getText(); ( JTextfield). :
JTextField textfield = new JTextField("", 37);
JButton myButton = new new JButton("button text here");
myButton.addActionListener(new MyActionListener (textfield, myButton));
:
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.lang.*;
class MyActionListener implements ActionListener {
JTextField textfield;
MyActionListener(JTextField textfield, JButton button) {
this.textfield = textfield;
}
public void actionPerformed(ActionEvent e) {
String letter = javax.xml.bind.DatatypeConverter.printString(textfield.getText()).concat(button.getText());
textfield.setText (letter);
}
}
the same principle applies when accessing a button. you can send by line, and this line can be used in conditional statements to determine which button was pressed.
source
share