JAVA GUI : How to use button listener to read and display text file?
-
What i want to happen in my program is when the button is clicked, it will initiate a button listener to read a text file and display the text in a dialog box. Can anyone give examples on how to do this?
-
Answer:
Are you planning some thing like editor? May be in your actionPerformed method you can write the following assuming A is an TextArea type of global object public void actionPerformed(ActionEvent E) { Scanner S= new Scanner(new File("filename")); while(S.next()) { String L=S.nextLine(); A.append(L); or A.add(L); } }
Ame at Yahoo! Answers Visit the source
Other answers
You can find several examples on the internet, when utilizing Google's search. However, it can be hard to find when you don't know the right phrases to search for. Following are some links that might help (since I don't know if you are utilizing swing or awt): http://docs.oracle.com/javase/tutorial/ui/index.html http://docs.oracle.com/javase/tutorial/uiswing/index.html As mentioned on the last URL, there's a IDE (Integrated Development Environment) called NetBeans. The IDE is free for download. In addition, the download page (wwww.netbeans.org) also has several tutorials that might help you.
Neunerball
Related Q & A:
- How to program java GUI?Best solution by Yahoo! Answers
- How to read UTF-8 .txt file in Android?Best solution by wiki.mcneel.com
- How to use GUI in c language?Which is best GUI for c?Best solution by Quora
- How do I read an ETD extension file?Best solution by Stack Overflow
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
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.