Hi all,
I am looking to print text to a textarea within a scrollableTextArea in my GUI how could I do this from another class ?
GUI Class
__________________________
__________
__________
__________
____
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListe
ner;
import java.awt.event.ActionEvent
;
public abstract class GUI extends JFrame implements ActionListener
{
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private Rooms currentRoom;
public static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFe
elDecorate
d(false);
//Create and set up the window.
JFrame frame = new JFrame("World Of Steve");
frame.setDefaultCloseOpera
tion(JFram
e.HIDE_ON_
CLOSE);
//Create panel to house objects.
JPanel panel = new JPanel(null);
//Add buttons to GUI
JButton N = new JButton("North");
JButton S = new JButton("South");
JButton E = new JButton("East");
JButton W = new JButton("West");
//Set button locations x,y,w,h
N.setBounds(150, 10, 70, 20);
S.setBounds(150, 140, 70, 20);
E.setBounds(170, 120, 70, 20);
W.setBounds(10, 120, 70, 20);
//Add labels to GUI
JLabel lblLocationCaption = new JLabel("Current Location is: ");
JLabel lblCurrentLocation = new JLabel();
JLabel lblExits = new JLabel("Exits;");
//Add Main Text Area
JTextArea textArea = new JTextArea();
JScrollPane scrollableTextArea = new JScrollPane(textArea);
//Set textarea location
scrollableTextArea.setBoun
ds(160, 30, 380, 400);
//Set label locations x,y,w,h
lblLocationCaption.setBoun
ds(5, 5, 150, 20);
lblCurrentLocation.setBoun
ds(155, 5, 150, 20);
lblExits.setBounds(5, 30, 50, 20);
//Add objects to panel to display in frame
panel.add(N);
panel.add(S);
panel.add(E);
panel.add(W);
panel.add(lblLocationCapti
on);
panel.add(lblCurrentLocati
on);
panel.add(lblExits);
panel.add(scrollableTextAr
ea);
frame.getContentPane().add
(panel);
//Display the window.
int width = 700;
int height = 500;
frame.setSize(width, height);
frame.show();
frame.setVisible(true);
}
// Create an action
Action N = new AbstractAction("North") {
// This method is called when the button is pressed
public void actionPerformed(ActionEven
t evt) {
System.out.println("North hs been pressed via GUI");
}
};
}
Many Thanks
Steve
Start Free Trial