I have this class for my UI
public class MyFrame extends JFrame{
JTextArea textArea;
public MyFrame(){
setSize(100,100);
textArea = new JTextArea(50,
First of all, don't override the setText()
method unless you want different behavior. Second of all, you don't have to extend anything. All you have to do is follow these simple steps and you'll be set!
In the UpdateText
class, put these lines somewhere in it:
MyFrame gui;
public UpdateText(MyFrame in) {
gui = in;
}
In the 'MyFrame` class, put this line at the beginning:
UpdateText ut = new UpdateText(this);
Now, you can refer to everything in the MyFrame
class from the UpdateText
class by preceeding what you want to change with gui
. For example, say you wanted to change the text of your textarea. The code would be the following:
gui.textArea.setText("Works!");
Happy coding! :)