Problem Writing to text area reposted forgot my code

I have 3 seperate Classes Main, GUI, and FileChange.
The Main class runs and constructs the GUI class. The GUI class builds my application. Then the program stops until a user action is committed. If the user opens a file the FileChange class gets the selected file and manipulates it. I tokenize the stings in the file and send the info i want back over to the JTextArea in the GUI class but nothing prints out. The program compiles but informaiton is not written to the text area, why?
The file change makes a call like such:
g.outputText(genre, composer, artist, albumTitle, trackNum, songTitle, count);
the the method that is called does this:
mainText.append(gnr+" ");
if(count==1){mainText.append(cmp+" ");}
mainText.append(art+" "+alb+" "+trk +" "+st.substring(3)+".mp3");
I dont understand why I cant append text to the JTextArea. I can place text in the TextArea during constructor initialization of the GUI class but not when i call the method that appends text from the FileChange class.The Code is posted below
Thanks in advance for your help
p
Main Class//////////////////////////////////////////////////
package musicmatch_library_test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
public class Main implements WindowListener
public Main()
     super();
     public static void main(String args[])
GUI f = new GUI();
f.setSize(800,600);
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
     public void windowActivated(WindowEvent e)
     public void windowClosed(WindowEvent e)
     public void windowClosing (WindowEvent e)
          GUI f = new GUI();
          f.quitApplication( );
     public void windowDeactivated(WindowEvent e)
     public void windowDeiconified(WindowEvent e)
     public void windowIconified(WindowEvent e)
     public void windowOpened(WindowEvent e)
GUI Class
package musicmatch_library_test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.io.*;
class GUI extends JFrame implements ActionListener, FilenameFilter
private JMenuBar menuBar = new JMenuBar(); // Creating The MenuBar
protected JFileChooser dialogBox = new JFileChooser(); //create load dialog box
private JMenu fileMenu, editMenu, helpMenu; // Menu Options
protected JMenuItem fileOpen, fileSaveAs, fileExit; // File Option
private JMenuItem editDelete; //Edit Options
private JCheckBoxMenuItem wordWrap;
private JMenuItem helpQuestions, helpAbout; // Help Options
private JTextArea mainText = new JTextArea();
//public FileChange changeFile = new FileChange();
public GUI()
     super("Library Converter v.001"); //Title bar text
     getContentPane().setLayout(new BorderLayout());
this.setJMenuBar(menuBar); // Add menu Bar to the screen
initFileMenu(); // goes to the file menu method
initEditMenu(); // " " edit menu method
initHelpMenu(); // " " help menu method
initTextArea();     // " " text area setup
System.setProperty("line.separator", "\r\n");
     public boolean accept(File dir, String name)
          System.out.println("accept():");
          if (name.endsWith(".txt")) return true;
          return false;
     public void actionPerformed(ActionEvent e)
if(e.getSource() == fileExit)     //if statement to close app
quitApplication();
}//end if (e.getSource() == fileExit)
if(e.getSource() == fileSaveAs)
FileChange changeFile = new FileChange();
changeFile.fileSaveAs();
}//end if (e.getSource() == fileSaveAs)
if(e.getSource() == fileOpen)     //if statement to open a file
openFile();
}//end if (e.getSource() == fileOpen)
if(e.getSource() == wordWrap)     //if statement to turn word wrap on/off
if(wordWrap.getState() == false)
mainText.setLineWrap(false);
mainText.setLineWrap(false);
}//end if (wordWrap.getState() == false)
else if(wordWrap.getState() == true)
mainText.setLineWrap(true);
mainText.setLineWrap(true);
}//end else if (wordWrap.getState() == true)
}//end if (e.getSource() == wordWrap)
     }//end action performed
     private void initEditMenu()
editMenu = new JMenu("Edit"); //Adding Edit to Menu
editMenu.setMnemonic('E');
menuBar.add(editMenu);
wordWrap = new JCheckBoxMenuItem("Word Wrap", false); //adding a word wrap on/off button
wordWrap.addActionListener(this);
wordWrap.setEnabled(true);
editMenu.add(wordWrap);
editDelete = new JMenuItem("Delete"); //adding delete inside the "edit" options
//editDelete.addActionListener(this);
editDelete.setEnabled(false);
editMenu.add(editDelete);
     }//intEditMenu
     private void initFileMenu()
fileMenu = new JMenu("File"); // Adding File to the menu bar
fileMenu.setMnemonic('F');
menuBar.add(fileMenu);
fileOpen = new JMenuItem("Open"); // Adding open to the Menu
fileOpen.setMnemonic('O');
fileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
fileOpen.addActionListener(this);
fileOpen.setEnabled(true);
fileMenu.add(fileOpen);
fileSaveAs = new JMenuItem("Save File As"); // Save file info
fileSaveAs.setMnemonic('S');
fileSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
fileSaveAs.addActionListener(this);
fileSaveAs.setEnabled(false);
fileMenu.add(fileSaveAs);
fileExit = new JMenuItem("Exit"); //Exit Item
fileExit.setMnemonic('X');
fileExit.addActionListener(this);
fileMenu.add(fileExit);
     private void initHelpMenu()
helpMenu = new JMenu("Help"); //adding help menu
helpMenu.setMnemonic('H');
menuBar.add(helpMenu);
helpQuestions = new JMenuItem("Questions"); // Questions Item
helpQuestions.addActionListener(this);
helpQuestions.setEnabled(false);
helpMenu.add(helpQuestions);
helpMenu.addSeparator();
helpAbout = new JMenuItem("About"); //addind About stuff
helpAbout.addActionListener(this);
helpAbout.setEnabled(false);
helpMenu.add(helpAbout);
private void initTextArea()
     mainText.setEditable(false);
     mainText.setVisible(true);
JScrollPane scrollPane = new JScrollPane(mainText);
getContentPane().add(scrollPane, "Center");
     public void openFile()
     {//method to start the opening of a file
          FileChange changeFile = new FileChange();
//fileSaveAs.setEnabled(true);
          mainText.setText("Please Be Patient While Opening The File");
          dialogBox.setCurrentDirectory(new File("C:/Documents and Settings/Administrator/My Documents/Java Stuff/Personal Projects")); //set default path
          dialogBox.showOpenDialog(this);                         //opens the dialog box to select a file
          changeFile.fileManip(dialogBox.getSelectedFile().getPath());//get the directory plus the file and pass it to fname in displayTab1()
     }// end openFile()
public void outputText(String gnr, String cmp, String art, String alb, String trk, String st, int count)
     mainText.append(gnr+" ");
     if(count==1){mainText.append(cmp+" ");}
     mainText.append(art+" "+alb+" "+trk +" "+st.substring(3)+".mp3");
     public void quitApplication( )
          setVisible(false );
          dispose( );
          System.exit(0);
FileChange Class
package musicmatch_library_test;
import java.io.*;
import java.util.*;
import javax.swing.*;
class FileChange extends GUI
     JTextArea fcText = new JTextArea();
public     FileChange()
     super();
     public void fileManip(String fname)
     {//this mehtod will edit and display and save certain info in tab1s display area
     GUI g = new GUI();
     try
BufferedReader inFile = new BufferedReader(new FileReader(fname));
PrintWriter outStream = new PrintWriter (new FileWriter(fileSaveAs())); //dialogBox.getSelectedFile()
          String line = inFile.readLine();
          fcText.setText("");
          int count;          
          while(line != null)
               StringTokenizer cut = new StringTokenizer(line, "\\");
               count = cut.countTokens();
               if(count == 6 || count ==7)
                    String drive = cut.nextToken();
                    String folder = cut.nextToken();
                    String genre = cut.nextToken();
                    String composer=null;
                    if(count ==7)
                         composer = cut.nextToken();
                         count = 1;
                         String artist = cut.nextToken();
                         String albumTitle = cut.nextToken();
                         String trackNum = cut.nextToken("\\ -");
                         String songTitle = cut.nextToken(".");
                         g.outputText(genre, composer, artist, albumTitle, trackNum, songTitle, count);
                    outStream.print(genre+" ");
                    if(count==1){outStream.print(composer+" ");}
                    outStream.println(artist+" "+albumTitle+" "+trackNum +" "+songTitle.substring(3)+".mp3");
                    count = 0;
               }//if(count == 6)
                    line = inFile.readLine();
          }//end while(line != null)
          outStream.close();
          inFile.close();
     }//end try
     catch(FileNotFoundException e)
          g.fileSaveAs.setEnabled(false);
          fcText.setText("NO File will be open, File Not Found");
     }//end catch (FileNotFoundException e)
     catch(IOException e)
g.fileSaveAs.setEnabled(false);
fcText.setText("NO File will be open");
System.exit(1);
     }//end catch (IOException e)
     catch(NoSuchElementException e)
          fcText.setText("No MoreTokens");
}//end FileManip()     
     public File fileSaveAs()
{//method for saving a file
     GUI a = new GUI();          
a.dialogBox.setCurrentDirectory (new File("C:/Documents and Settings/Administrator/My Documents/Java Stuff/Personal Projects"));
a.dialogBox.showSaveDialog(a.getContentPane());
//File toSaveAs = a.dialogBox.getSelectedFile();
return a.dialogBox.getSelectedFile();
}//end fileSaveAs()

For instance in your main you can have:
public class Main implements WindowListener {
  public static GUI f;
  public Main(){
    super();
  public static void main(String args[]) {
    f = new GUI();
    f.setSize(800,600);
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {
      //Window Adapter Stuff...By the way if you use the WindowAdapter
      //You don't have to stub out the methods you don't use, just write
      //the ones you do use, that is what makes adapters better then
      //listeners...
  public static GUI getGUIInstance() {
    return f;
//then in the fileChange methods that need to use the GUI do:
  GUI g = Main.getGUIInstance();Steve

Similar Messages

  • Problem with adding text area in scroll pane

    hi , i have been facing this funny problem , but cant able to get solution.
    the problem is i am trying to add text area in scroll pane , but when i add textarea in scroll pane using scrollpane.add(textarea) that text area remain disable always. i tried making it enable explicility but that code is not working.

    You don't use the add(...) method for JScrollPane. Use:
    a) new JScrollPane( textArea );
    b) scrollPane.getViewport().setView( textArea );

  • Problem with saving text areas

    I'm trying to use the FileDialog() class to save a file but I'm having a few problems - I'm only really familiar with it to open files not save them - I have the following code.
    save = new JButton("Save");
          save.addActionListener(
          new ActionListener()
        public void actionPerformed(ActionEvent evt)
          String saveName;
          saveNameBox = new FileDialog(frame,"Save File", FileDialog.SAVE);
          saveNameBox.show();
          //display the name
          saveName = saveNameBox.getDirectory()+File.separator+saveNameBox.getFile();
           try
            saveFile = new PrintWriter( new FileWriter(output.getText()));
          catch (IOException e)
            System.err.println("Error in file" + saveName + "; " + e.toString());
            System.exit(1);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    new FileWriter("abc") creates a FileWriter that will write to the specified file (abc). You have got the filename mixed up with the text you want to write to the file.
    You must then write the text after you have created the FileWriter.
    try replacing
    saveFile = new PrintWriter( new FileWriter(output.getText()));
    with
    saveFile = new PrintWriter(new FileWriter(saveName));
    saveFile.print(output.getText());
    saveFile.close();

  • Problem writing a text file to user's hard drive

    I am trying to write a "GPX" file from an Oracle report to the user's hard drive on windows XP computers. To do this I want to write an ASCII file using the distribution method in the Oracle report. My URL to generate the report is as follows:
    http://serveraddress.dot.ca.gov:7779/reports/rwservlet?destype=cache&destype=file&desformat=ascii&DESNAME=d:\test_report.txt&mode=character&report=gpx&userid=userxx/pwxx@mydatabase
    When I run the report I get the following error: "REP-1804: Unable to open printer definition file 'ascii'"
    We are running Oracle Report 10G.
    Does anyone know what I am doing wrong or is there another method to write the ASCII file. If there is a method in Oracle forms, I could also do it in a form.
    Thanks for the help.

    desname=d:\test_report.txtThat is a file on d: drive on the server. You cannot directly write to the client PC.
    For valid values of desformat:
    http://download.oracle.com/docs/cd/E14571_01/bi.1111/b32121/pbr_cla005.htm#i636884
    Ascii is not a standard desformat. Try
    mode=character&desformat=dflt
    If there is a method in Oracle forms, I could also do it in a form.Yes, you can use client_text_io. Don't use that method for large files, though. Better to use text_io and copy the result from server to client:
    http://fdegrelle.over-blog.com/article-1810290.html
    Edited by: InoL on Apr 15, 2011 3:05 PM

  • Problems writing CD TEXT in Waveburner

    Hi, I am unable to let Waveburner write the correct CD Text when I burn a CD.
    It looks like if the program only writes the default text, which shows up in ITunes as:
    'Surrender 4:26 Fireproof Fire Proof Gospel & Religious'
    Any clues?

    Agreed.
    My understanding is that CD-Text doesn't work with iTunes at all. (I remember reading it in the manual for some CD software - either Toast or Waveburner. If you have an actual CD player that reads CD-TEXT you should just try it there. You may also try try opening the CD with another player - maybe VLC - I have not had much success with CD-text yet, either.

  • SetText() works for one text area but not for another

    I am student new to java so forgive me if I'm making an obvious mistake. I have a GUI with 3 tabs. Two tabs have a text area in each in them and an action listener tells the textarea what to print. The problem is one text area works and the other doesn't. they are declared in the same way so I can't see why the problem occurs.

    If you have copied and pasted code for the second one, it is possible that you are setting text for the first text area at both the places. Check if you are calling the setText method on both the text areas and not the same one twice.

  • Text area and Word Wrapping

    I am creating a email form and am having problems with word
    wraping in the text area. You can view the page and the output if
    you put your email address in the form. The problem is the text
    areas word wrap when inputting your information but all formatting
    is lost in the email. Even if I add spacing for paragraphs. All
    data is just a big run on sentence.
    Here is the
    Page.
    I am using Dreamweaver * and php.
    Thanks

    Someone may have tried this because I received this output in
    an email. You can see the formattint is lost.
    Gear Ad:
    Description:
    This is a test. Line 1 Line 2 Line 3 Line 4 -
    Test...test...test...test...test...test...test...test...test...test...test...test...test. ..test...test...test...test...test...test...test...test...test...test...test...test...test ...done!
    Price:
    test
    Contact:
    This is a test.

  • Problems writing text on Photoshop CC

    I am having problems writing text on Photoshop CC - the image goes black.

    Windows 8?  Update your video card driver from the GPU maker's website. If you cannot update your driver (like on a locked laptop machine), then set the GPU drawing mode in Photoshop to "Basic" and relaunch the app.

  • HT4623 My texts have stopped getting through to one of my contacts. I can phone him and I can receive his calls and messages. I am the only one of his contacts whose  texts are not getting through. We have both restarted our iphones but the problem contin

    My texts have stoipped getting through to one of my contacts. I can phone him and I can receive his calls and messages. I am the only one of his contacts whose  texts are not getting through. We have both restarted our iphones but the problem continues.

    Have you talked to your carrier (or your friend to his)?  Could be an issue at their end.

  • Problem in using a text area

    Hi All,
    I am having text area in my screen.
    I am using 
    CALL METHOD editor1->get_text_as_r3table
               IMPORTING
                   table = it_text
               EXCEPTIONS
                   OTHERS = 1.
    to get the text entered in the text area.
    The problem I am facing here is, When I am executing it for the first time the text is getting populated, but when I go back to my main screen and execute it once again I could able to retrieve the text. Can some suggest me a solution for this.
    Thanks,
    Arun

    Hi,
    I got the solution.

  • Problem while copying Text from Jtext Area ..

    I am trying to copy text from a JtextArea onto any Text Editor .. What happens is that the pasted text in the Text Editor eg : TextPad, JCreator etc .. has extra Carriage Return appended at the end of everyline (line separator to be exact).
    Eg :- Actual Text on Text Area :
    Executing PU for PMGS.................
    Completed PMGS PU successfully.
    - When Pasted on a Text Editor Blank Document becomes :
    Executing PU for PMGS.................
    Completed PMGS PU successfully.
    I am not being able to understand how this extra CR (Carriage Return gets added .. Looking for an urgent solution to this problem ,,

    rathor5 wrote:
    When I am copying a song from my pc to lumia 620 . It automatically create 3 or 4 links of that song in "music+video" hub . I have already refreshed my phone but the problem is still persists.
    Do you already have the amber update on your Lumia? Pre-amber solution for that is to perform a complete hard reset of the device - so make it sure to do a backup first.
    Good luck

  • HT201269 My wife switched from an iPhone 4 to an iPhone 5.  Everything transferred over and service is on the new phone.  However, texts are going to her old phone still.  Any idea what the problem is?

    My wife switched from an iPhone 4 to an iPhone 5.  Everything transferred over and service is on the new phone.  However, texts are going to her old phone still.  Any idea what the problem is?

    As long as iMessage is enabled and the old phone is connected to a WiFi access point, it will continue to receive iMessage texts. It won't receive non-iMessage texts nor will it receive any calls.

  • Problem with Spell check in text area

    i have a item called text area with spell check. In that i have very large text. When i run spell check it open another windows and gives this message 'Checking spelling, please wait...' since last 4 hrs i have same windows.
    Please help me out.
    THanks,
    Hetal Patel.

    fruhulda wrote:
    To the spell checker the word is wrong. It could be the word is right to the OP in this document but not in the next. Why should Pages learn the word?
    It's not Pages which learn the document, it's the spell checker.
    I wish I could help the OP. Pages on his machine isn't working as it should. Ignore option should take of the red line.
    So, my machine is odd too.
    When I click ignore, the spell checker no longer halt on the word but it continue to underline it.
    As the OP didn't gave a sample we don't know what is the exact problem.
    If he want to leave a misspelling in the doc, 'learn' is not a good soluce.
    If he want to add a word to the list of allowed words, 'learn' is the soluce.
    Yvan KOENIG (VALLAURIS, France) samedi 12 septembre 2009 10:44:33

  • Hi there. I having a problem with InDesign PDF interactive export. I would keep my text area style and not text area default style when I export the PDF. How could I do?

    Could you help me?

    Thanks for the answer Sumit Singh,
    sorry but my problem keeps.
    I create a simple text area and then trasform it in interactive text area, set it, apply my paragraph/character style and at the end export it in PDF (interactive).
    I open the file with Adobe Acrobat, but when I customize it, words inside text area have stylized with default paragraph/character style.
    How could I keep my style on export interactive text area?
    Thanks a lot.

  • Forgot how to format HTML  in Text Area

    Hello all,
    I totally forgot something. How do you format HTML when rendering in Text area
    Suppose I pass in a string that a text area grabs for display.
    xxx.getAdditionalComments(existingComments + "\n"  +  "<B>" + date + "<\B> " + name);The text are will always display the <B> instead of displaying the date in bold.
    I remember putting escape characters eons ago but I forgot how that worked. Anyone know how to render this with date being bolded?
    Thanks.

    If you mean the textarea HTML tag for text entry fields, you don't. If you forgot anything it's that you can't do things like that.

Maybe you are looking for