我不知道如何从使用该action Listener()
方法在界面上按下的按钮将文本输入发送到 Java 中的对象。
import javax.swing.*;
import java.awt.event.*;
public class Preassessment extends javax.swing.JFrame implements ActionListener {
static JTextField concept = new JTextField(15);
JButton enter = new JButton("Enter");
JLabel conceptLabel = new JLabel("Concept: ");
public Preassessment() {
super("Preassessment Sys");
setSize(350, 180);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.add(conceptLabel);
pane.add(concept);
pane.add(enter);
add(pane);
enter.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent event) {
if(event.getSource() == enter){
conceptLabel.setText(concept.getText());
}
}
public static void main(String[] arguments) {
Preassessment preassess = new Preassessment();
Preassessment agInterface = new Preassessment(); //object to receive the text
}
}