so i have a frame with a jtextarea and i want to write to it from a separate class i (for example)
try to write to it from the eventlistener here they are:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; public class PFrame extends JFrame { JPanel pane1 = new JPanel(); JPanel pane2 = new JPanel(); JPanel pane3 = new JPanel(); JButton browse; JButton artist; JButton name; JTextArea textBox; JScrollPane scroll; JLabel numLabel; int count=0; public PFrame() { super("mikey's program"); setSize(350, 400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); browse = new JButton("browse"); browse.setActionCommand("browse button"); browse.addActionListener(new ActListener()); textBox = new JTextArea(); textBox.setEditable(false); scroll = new JScrollPane(textBox); numLabel = new JLabel("number of songs:" +count); artist = new JButton("artist"); name = new JButton("name"); BoxLayout box = new BoxLayout(pane1, BoxLayout.Y_AXIS); pane1.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); pane1.setLayout(box); pane1.add(browse); pane1.add(Box.createRigidArea(new Dimension(0, 10))); pane1.add(scroll); pane1.add(numLabel); pane2.setLayout(new FlowLayout(FlowLayout.LEFT)); pane2.add(artist); pane2.add(name); pane3.setLayout(new BoxLayout(pane3, BoxLayout.X_AXIS)); pane3.add(pane1); pane3.add(pane2); add(pane3); //try{ // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // SwingUtilities.updateComponentTreeUI(this); // } catch (Exception e){ // e.getMessage(); // } setVisible(true); } [B] public void setTextBox(String str) { this.textBox.append(str); System.out.println(str); //maybe you repaint or something....... }[/B] [B] public static void main(String[] args)[/B] { [B] PFrame mainFrame = new PFrame();[/B] } }
and the listener
class ActListener implements ActionListener { JFileChooser myChooser = new JFileChooser(); public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("browse button")) { Container a = new Container(); JButton b = (JButton)event.getSource(); ; a = b.getParent(); myChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int retval = myChooser.showDialog(a, "OK"); [B]PFrame corrant =(PFrame)a; corrant.setTextBox("check if update works");[/B] if (retval == JFileChooser.APPROVE_OPTION) { File myDirectory = myChooser.getSelectedFile(); } } } }
a am not sure but i think the problem is that i cant get to the right instance of my PFrame
if some one could please help me i well be so happy thanks....