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]
# 1

check out the second example here it might help

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter06/textOutput.html

mark07a at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 2

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();

}

}

jonathanca at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 3

<does anyone know how to solve the error

What's the error?>

mark07a at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 4

H:\cdetailreader.java:41: invalid method declaration; return type required

public TextAreadetails() {

^

1 error

Tool completed with exit code 1

jonathanca at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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.

~

yawmarka at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 6

<TextAreadetails.setvisible(true);

I think that's why you can't see it what are you storing your text into?>

mark07a at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...
# 7

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.

camickra at 2007-7-29 18:19:08 > top of Java-index,Java Essentials,Java Programming...