I am working on an exercise to understand Java, and basically I need to combine the functionality of two classes in one application.
I am stuck on one area, though - binding objects to classes.
What I did was set up gui in one class (test1), and this has a text box, i.e.
chatLine = new JTextField();
in another class (test2), I planned to leave all the functionality there and refer to the various gui elements installed in test1 - like this test1.chatLine
I understand this link level, I checked this by setting a test method in the test2 class
public static void testpass() { test1.testfield.setText("hello"); }
I am trying to understand how to implement more complex functions in the test2 class, although, in particular, this existing code;
test1.chatLine.addActionListener(new ActionAdapter() { public void actionPerformed(ActionEvent e) { String s = Game.chatLine.getText(); if (!s.equals("")) { appendToChatBox("OUTGOING: " + s + "\n"); Game.chatLine.selectAll();
This is the bit I'm stuck on if I can do it - since it has not been compiled, I can add actionadapter material to the gui element that was sitting in test1, but to do it from test2 - I wonder if I'm trying to do something impossible .
Hope this makes sense, I'm pretty confused about this - I'm trying to figure out how the scope and links work.
Ideally, what I'm trying to achieve is one class that has all the basic elements, gui, etc., and then all the related functions in another class and are aimed at the first-class gui elements with the results, etc.
Any thoughts are greatly appreciated.