hi friends,
i have been stuck with this prototype for 2 weeks.........i have 2 java files.....the first code is the interface code....and the second code is a code that reads the contents of a file.
the thing is ...i want to make the contents of the file appear in the TextBox of the interface.........i dont know how to do that..?......how i can link the 2 files together....how can i direct the file contents to appear in the TextBox in my interface........
HERE IS MY CODES..
1....INTERFACE CODE......
import javax.swing.*;
import javax.swing.border.*;
public class sanesense
{
public static void main (String[] args)
{
// creating the components
// Paragraph TextField + Question TextField + Answer TextField + ASK Button
JLabel Paragraph = new JLabel("Please Enter a Text..");
JTextArea ParagraphText = new JTextArea(6, 30);
ParagraphText.setEditable(true); // thi function disallow the user from changing the information in the text area.
JLabel Question = new JLabel("Your Question");
JTextArea QuestionText = new JTextArea(2,30);
JLabel Answer = new JLabel("The Answer");
JTextArea AnswerText = new JTextArea(5,30);
JButton button = new JButton ("ASK");
button.setLocation(100,200);
// creating the panel
JPanel panel = new JPanel();
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "");
panel.setBorder(titled);
panel.add(Paragraph);
panel.add(ParagraphText);
panel.add(Question);
panel.add(QuestionText);
panel.add(Answer);
panel.add(AnswerText);
panel.add(button);
// creating the frame
JFrame frame = new JFrame();
frame.setTitle("THE SANESENSE PROJECT");
frame.setContentPane(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,450);
frame.setResizable(true);
frame.setVisible(true);
frame.show();
}
}
2...CODE TO READ FROM A FILE....
import java.io.*;
class FileReadTest {
public static void main (String[] args)
{
FileReadTest t = new FileReadTest();
t.readMyFile();
}
void readMyFile()
{
String record = null;
int recCount = 0;
try {
FileReader fr = new FileReader("mydata");
BufferedReader br = new BufferedReader(fr);
record = new String();
while ((record = br.readLine()) != null) {
recCount++;
System.out.println(recCount + ": " + record);
}
} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("an IOException error!");
e.printStackTrace();
}
}
}
i will be very grateful for any comments or help.........even my bect coffee didnt help me to figure this out
Thank you very much