Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31
  1. #21
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    Java Code:
    the error message is in this line
    Code:
    public String openFile() throws FileNotFoundException, IOExveption {
    try to change "IOExveption" with "IOException".

  2. #22
    EBBOOO is offline Member
    Join Date
    Jun 2010
    Posts
    42
    Rep Power
    0

    Default

    thanks cselic for your help
    Java Code:
    Can you explain to us what you're trying to do in with the code in actionPerformed method?
    now i want to do now is to open a .txt file, not just to show the open dialog
    i found some methods but i don't know exactly how to use them

  3. #23
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    I don't know if it is a good way but I think that you should do something like that:

    you want to have some txt file, for example myfile.txt
    So try to open that file and put those lines of text to your textArea. I guess that fileChooser is here just to help you to locate that file (but I'm not sure).

    Try first to use FileReader or something similary to find how to put text lines from that file to textArea lines. Later you can find a way to do it with FileChooser.
    Try first to do something simple and that as you progress you can do it on a more advanced level.

  4. #24
    EBBOOO is offline Member
    Join Date
    Jun 2010
    Posts
    42
    Rep Power
    0

    Default

    i defined a method in a superclass name "OpenFile", so i'm askin is this the right way to call a method??
    Java Code:
    myTextArea.OpenFile();
    they both are in the same package but i always get an error "cann't find symbol-method OpenFile()"

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    Several requirements for: myTextArea.OpenFile();
    to be "the right way"
    There needs to be a class defined with a (not private) method OpenFile() that takes no args.
    The variable: myTextArea must be an instance of that class.

    "cann't find symbol-method OpenFile()"
    Its better to copy and paste error messages instead of typing them in.

  6. #26
    EBBOOO is offline Member
    Join Date
    Jun 2010
    Posts
    42
    Rep Power
    0

    Default

    the method OpenFile is public

    and there is no main method in the superclass

    with my stupid program i can' copy errors

    Java Code:
    The variable: myTextArea must be an instance of that class.
    how can i do this?

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    An example. Say the OpenFile() method is a member of the FileStuff class.
    Java Code:
    class FileStuff {
     public void OpenFile() {
     ...
    }
    Your create an instance of the FileStuff class by using new:

    FileStuff myTextArea = new FileStuff();

    then the statement:
    myTextArea.OpenFile();
    is legal code

  8. #28
    EBBOOO is offline Member
    Join Date
    Jun 2010
    Posts
    42
    Rep Power
    0

    Default

    thank you very much

    OpenFile method is to open a .txt file, and i wanna use it in my notePad class
    so what i did is:
    Java Code:
            else if (file.equals("Open")){
                BufferReader a = new BufferReader();
              myTextArea=a.OpenFile();
    but i got an error "incompatible types - found void but expected javax.swing.JTextArea"

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    incompatible types - found void but expected javax.swing.JTextArea
    myTextArea=a.OpenFile();
    The compiler is complaining that the variable on the left of the = sign does not have the same type as what is returned by the method on the right side of the = sign.
    It thinks the type on the left is a JTextArea and it thinks that the type returned by the method is void. They must match for the compiler to be happy.

    What are you trying to do with the code in this statement?

  10. #30
    EBBOOO is offline Member
    Join Date
    Jun 2010
    Posts
    42
    Rep Power
    0

    Default

    OpenFile show the content of a .txt file
    and i want it to show the content in myTextArea in the subclass

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    show the content
    You need to describe what you want at a lower level. "Show the content" can be done by using the println() method.
    I think what you want is to add lines of text from a file to a JTextArea. The lines of text are to be read by the OpenFile() method and returned as a String that can be placed in the JTextArea for viewing.

    That is not the only why to "show the content". But its probably what you are trying to do.

    To do the above, you need to read the contents of the file into a String and concatenate all the Strings together into one String with the whole contents of the file.
    When the method has all the lines in a String, it returns the String.
    The code receiving that String has to use one of JTextArea's methods to put that String into the JTextArea's text/document.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. What's going wrong with this code?
    By Suurisa in forum New To Java
    Replies: 5
    Last Post: 10-19-2009, 11:59 PM
  2. what's the wrong in this Code
    By the swan in forum AWT / Swing
    Replies: 1
    Last Post: 04-04-2009, 04:27 AM
  3. what's wrong with my code? please help me...
    By lovely23 in forum Java Applets
    Replies: 2
    Last Post: 03-01-2009, 01:33 PM
  4. What's wrong with this code?
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 11-29-2008, 05:44 PM
  5. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •