How do I save input from a JTextArea to a .txt file or any other type of file?(java)?
-
I am building myself a basic text editing program. So far, this is the source code: import java.awt.*; import javax.swing.*; class testing extends JFrame{ public static void main(String[] args){ JFrame textwindow = new JFrame("WordWriter"); textwindow.setDefaultCloseOperation(… textwindow.setSize(600,600); JTextArea area = new JTextArea(20,120); textwindow.add(area); textwindow.setVisible(true); } } So far so good right? What I want to do now is have 3 buttons above the frame: I want a new button that makes a new file. I can supply the following images: .bmp, .jpg, .ico, .gif. I want a "save" button that opens up a prompt so that the user can choose their save file and file type. (.txt is all thats required though If i can get .java files and .html files that would be great to.) I want a "open" button that opens up the same save prompt exept it opens up the file. I think I need something called "JFileChooser" but have no clue how to use it. Please put in code and notinstructions because I'm pretty new to java. Also, if you can fit it in can you include how to create a window when leaving an unsaved file that says: "Save changes to current file?" or something like that. I think you can do that with the JOptionPane but I'm still kind of clueless on that as well. Thanks in advance, Fellow Java Programmer, Nighthawk0973
-
Answer:
You are asking too much for me to explain all this in a Y! Answers text box. Further, Swing code is bulky. Your program, as you envision it, would be between 200-300 lines of code and work better as modular class files. You need to know how to CD from command prompt all over your hard drive by typing in the path names. From that you know what FileChooser wants. You need to add FileFilter to do the extensions like you want. I recommend you spend some time with Manning Publications "Swing". That was the book that showed me the way. That and the Oracle Swing tutorials. The Manning Pub. book is available as a free download (1st Edition) in Word.doc format. The printed book is worth having. Download the NetBeans IDE. It will greatly enhance your learning curve. Good luck.
Nighthaw... at Yahoo! Answers Visit the source
Related Q & A:
- How to delete a line from a .txt file in node.js?Best solution by c-sharpcorner.com
- How do I save a video from a CD to a computer?Best solution by Yahoo! Answers
- How can I save money on a London trip?Best solution by international.fsu.edu
- How can I print wirelessly from a laptop to a printer without a router?Best solution by answers.yahoo.com
- How can I record directly from a keyboard onto a computer?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.