but all this does is create a window showing info about whether the opened text file is a file or is a directory, file location, etc. It doesn't print the text to the Notepad text area. The JFileChooser should be used in order for the user to get the file name for my program. Can someone help me here?

In the given context, this refers to your ActionListener, not the JFrame. If you remove this from your dispose() invocation, it will invoke the dispose() method for the encapsulating Object- your JFrame.

Same thing applies here:

Quote

E:\Adv Java\NotepadIOTest\src\NotepadIO.java:138: showOpenDialog(java.awt.Component) in javax.swing.JFileChooser cannot be applied to (<anonymous java.awt.event.ActionListener>)
int option = open.showOpenDialog(this); // get the option that the user selected (approve or cancel)

I did implement the "New" menu item from the "File" menu, so that the Notepad clears the text area when I click it. However, I'm still having trouble implementing the "Open", "Save", and "Save As..." menu items correctly. I click on Open, the Open Dialog box appears, but the Notepad Window is blank. I can't save the text I type in the Notepad window either. I clicked on "Save" on the File Menu, but after I specify a file name, it doesn't save it in my chosen directory. The items in the File Menu must be implemented like a real Notepad application would do? Does the file need to have a .txt extension in order for my program to work properly?

In the given context, this refers to your ActionListener, not the JFrame. If you remove this from your dispose() invocation, it will invoke the dispose() method for the encapsulating Object- your JFrame.

Same thing applies here:

Quote

E:\Adv Java\NotepadIOTest\src\NotepadIO.java:138: showOpenDialog(java.awt.Component) in javax.swing.JFileChooser cannot be applied to (<anonymous java.awt.event.ActionListener>)
int option = open.showOpenDialog(this); // get the option that the user selected (approve or cancel)

Re: Creating a Java Notepad with file I/O and menus

For open, you have to actually read the File using either Scanner or an appopriate tool in the java.io package, and set the text of the JTextArea to the contents you read from the File.

For the Save/Save As options, you still need to write the data to the File. Again, using the appropriate java.io tools. Also, check out the JFileChooser.showSaveDialog() method, which can help you obtain where to write the File.

For open, you have to actually read the File using either Scanner or an appopriate tool in the java.io package, and set the text of the JTextArea to the contents you read from the File.

For the Save/Save As options, you still need to write the data to the File. Again, using the appropriate java.io tools. Also, check out the JFileChooser.showSaveDialog() method, which can help you obtain where to write the File.

Re: Creating a Java Notepad with file I/O and menus

Posted 22 April 2011 - 08:41 PM

Also, you are way overcommenting your code. Comments should help clarify ambiguous sections of code by saying why you are doing something, not what you are doing. Telling us you are reading in a file and what the result should be is too much. Maybe just a single-line comment if you are so inclined. But 10 lines of comments for that is overkill. Overdoing it with comments can produce just as ambiguous/hard to read code as grossly undercommented code. Plus, you code should be somewhat self-documenting with your spacing/indentation conventions and descriptive naming conventions.

Re: Creating a Java Notepad with file I/O and menus

Posted 22 April 2011 - 08:49 PM

macosxnerd101, on 22 April 2011 - 10:41 PM, said:

Also, you are way overcommenting your code. Comments should help clarify ambiguous sections of code by saying why you are doing something, not what you are doing. Telling us you are reading in a file and what the result should be is too much. Maybe just a single-line comment if you are so inclined. But 10 lines of comments for that is overkill. Overdoing it with comments can produce just as ambiguous/hard to read code as grossly undercommented code. Plus, you code should be somewhat self-documenting with your spacing/indentation conventions and descriptive naming conventions.

macosxnerd101 is 100% right
I had to remove so many lines of comments to test your code
and