GUI (メインの JFrame をレンダリングする) と Print クラス (GUI クラスの JButton によって呼び出される) の 2 つのクラスがあります。私のGUIクラスには、JTextAreaとメソッドがあります:
void setOutput(String data)
{
// output is JTextArea
output.setText(data);
}
ただし、データは、アクションリスナーを持つ JButton がある Print JFrame に提供されます。
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);
}
});