我创建了一个按钮,给按钮一个鼠标监听器。按下按钮会获得一个文本区的字符串给masage,当我在其他包中调用getMasage方法,得到的字符串是123而不是文本区的字符串。
import java.awt.Color;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextArea;
public class setButton11 extends setButton10{
private JTextArea information = null;
private JTextArea jText = null;
public String masage = "123";
public String getMasage(){
return masage;
}
public void addListener(JButton jButton, Color fColor, ImageIcon fIcon, JTextArea information, JTextArea jText){
this.information = information;
this.jText = jText;
super.addListener(jButton, fColor, fIcon);
}
public void mouseClicked(MouseEvent e) {
masage = information.getText();
information.setText(null);
}