participate


New To Java Technology Archive - GUI Bulletin Board Question
<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
sspurcell
Posts:72
Registered: 12/27/00
GUI Bulletin Board Question   
Aug 29, 2001 6:03 AM

 
Hello,
I want to produce a simple GUI application that mimics a bulletin board. Where there would be a GUI that people could insert a message, and I could allow others to view the past messages and possibly allow some filtering as to what they see.

I want to go from the GUI window to a text file to hold the past messages. After the text file I will probably move up to a DB, but for now, I think it is a good starter application.

I am having trouble with the IO class, because of the so many ways to read and write data, and was hoping someone may give me some guidance as to the best way to handle the IO, (which classes) or point me to a tutorial where they are reading a line at a time, and possibly putting them into a collection and then showing it in a GUI.

I know that is kind of a large question, but any assistance to get me started would be helpful, and then I can refine my questions as I begin building my project.

Thanks for your time,
Scott
 
bx573
Posts:18
Registered: 10/17/97
Re: GUI Bulletin Board Question   
Aug 29, 2001 8:26 AM (reply 1 of 2)  (In reply to original post )

 
Check this for IO
http://java.sun.com/docs/books/tutorial/essential/io/index.html
 
tkroger
Posts:32
Registered: 9/7/01
Re: GUI Bulletin Board Question   
Sep 14, 2001 4:44 AM (reply 2 of 2)  (In reply to original post )

 
Check out:
http://www.javacoffeebreak.com/java103/java103.html
and
http://java.sun.com/docs/books/tutorial/essential/io/index.html

I used the above links to come up with the above code to write to a file:
try {
FileOutputStream out = new FileOutputStream("SearchTableFile.Dat"); // Output file name
PrintStream p = new PrintStream(out); //Create a stream to write to the file.
for (int i=0; i<SearchTableFileData.length; i++) {
p.print(SearchTableFileData[i]); //write data stored in SearchTableFileData Array
p.print("\n"); // write end of line character.
}
// try and catch are error handling
} catch(IOException ioe) {
System.out.println("Error: " ioe);
}

To read the file back into the Array I have:
try {
DataInputStream in2 = new DataInputStream(
new FileInputStream("SearchTableFile.Dat")); // Input File Name and Stream
SearchTableFileData = new String[SearchTableFileLines];
line = in2.readLine(); //reads first line
SearchTableFileLines = 0;
while (line != null) {
SearchTableFileData[SearchTableFileLines] = line;
SearchTableFileLines
= 1;
line = in2.readLine(); //reads next line
}
in2.close();
} catch (EOFException e) {

} catch(IOException ioe) {
System.out.println("Error: " + ioe);
}

Hope this helps. The file reading routine has some variable that are declared elsewhere in the code and I didn't think it was necessary to explain all of them.
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 59
  • Guests : 125

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums