可以通过以下方式解决这个问题:
示例代码如下:
JTextArea textArea = new JTextArea();
JButton button = new JButton("Click");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textArea.getText();
// 在这里使用文本区域的字符串值
}
});
示例代码如下:
JTextArea textArea = new JTextArea();
JButton button = new JButton("Click");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textArea.getText();
// 在这里使用文本区域的字符串值
processText(text);
}
});
// 处理文本的方法
public void processText(String text) {
// 在这里处理文本
}
通过以上两种方式,按钮事件监听器就可以从文本区域中获取到字符串值并进行处理。