我有兩個clases GUI(這renderes我的主要的JFrame)和打印類(即由JButton的調用上GUI類)。現在,在我的GUI類,我有JTextArea中和的方法:靜態方法來分配非靜態變量
void setOutput(String data)
{
// output is JTextArea
output.setText(data);
}
但是數據提供了打印的JFrame在那裏我有一個JButton用行動聽衆:
sizOpt.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
// textfield is a JTextField component
String data = textfield.getText();
// My problem is here i need to invoke the setOutput
// method in GUI to output the string however i cant call that method in
// any way but making it static or calling new GUI which will create a new
// Instance of GUI class
GUI.setOutput(data);
}
});
那麼......這個問題是怎麼回事?很好很抱歉看到它,但是真的不應該把你的實際問題放在代碼示例中的註釋中。 –
對不起,這是上午5點,我的眼睛正在放血,我的思想即將臨近突破點。 –