need to display in jtextarea
i have the following program but i need to edit it in order to open the text file and display its contents in a jtextarea anyone know how i could do this
import java.io.*;
//this is a cprogram i have created so the users data entered into my main program can be read in a text file
class cdetailreader
{
public static void main (String args[])
{
int input;
try
{
// I have created a filereader to read the contents of the text file i created to hold customer data
// In my main program i named the text file to store customer details cdetails.txt
FileReader readcdetails = new FileReader("cdetails.txt");
input = readcdetails.read();
while (input >=0)
{
System.out.print ((char) input);
input = readcdetails.read();
}
}
catch(Exception e){
System.out.println("File does not exist"+e);
}
}
}
[942 byte] By [
jonathanca] at [2007-11-27 11:48:25]

right i had a bit of problems understanding that example but i have changed the code to as follows does anyone know how to solve the error and if this would show the contants of my text file
import java.io.*;
import java.awt.*;
import javax.swing.*;
//this is a cprogram i have created so the users data entered into my main program can be read in a text file
class cdetailreader
{
public static void main (String args[])
{
int input;
try
{
// I have created a filereader to read the contents of the text file i created to hold customer data
// In my main program i named the text file to store customer details cdetails.txt
FileReader readcdetails = new FileReader("cdetails.txt");
input = readcdetails.read();
while (input >=0)
{
System.out.print ((char) input);
input = readcdetails.read();
}
}
catch(Exception e){
System.out.println("File does not exist"+e);
}
}
}
class TextA extends cdetailreader{
//Text area for displaying cdetails.txt
JTextArea read1 = new JTextArea(6, 20);
public TextAreadetails() {
_ta.setText();
JScrollPane scrollingArea = new JScrollPane(_ta);
JPanel tpanel = new JPanel();
tpanel.add("cdetails.txt");
tpanel.setLayout(new BorderLayout());
tpanel.add(scrollingArea, BorderLayout.CENTER);
this.setContentPane(tpanel);
this.pack();
TextAreadetails.setvisible(true);
}
public static void main(String[] args) {
new TextAreadetails();
}
}
> invalid method declaration; return type required
Methods require a return type. You don't have a return type declared for that method. Therefore, your method declaration is invalid.
If you intended that to be a constructor (which cannot declare a return type), note that it doesn't match the name of your class and therefore isn't recognized as a constructor.
~
1) Swing related questions should be posted in the Swing forum.
2) All text components support a read method.
3) I've posted an example of a text area using the read method in the Swing forum that you can search for.