Results 1 to 3 of 3

Thread: Help

  1. #1
    neon is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default Help

    I just started learning java swing components. I want to create an event that open a dialog box after you click button to select the files I have. I looked at some examples and they showed this.

    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //This is where a real application would open the file.
    log.append("Opening: " + file.getName() + "." + newline);
    } else {
    log.append("Open command cancelled by user." + newline);
    }
    log.setCaretPosition(log.getDocument().getLength() );

    What does the above means? what does append means? how come when i key in append in my IDE, the word "append" is highlighted in red and couldn't compile.

    Secondly, What does the below means?
    int returnVal = fc.showOpenDialog(aComponent);

    it's just a response to a mouse click right? but when i key into IDE, aComponent, the word "aComponent" is highlighted in red and couldn't compile.

    Can anyone tell me how to do to make it compile? I just started java so i have a lot of things that i don't know. Please help. Thanks in advance :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please read the tutorial on using file choosers: How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    Your error seems to be coming from trying to use a log file that doesn't exist, which you have no need for, and likely is from cutting and pasting code you've found without understanding it. Again, read the tutorial as it will explain what you need to know.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default

    Considering this
    when i key into IDE, aComponent, the word "aComponent" is highlighted in red and couldn't compile.
    you probably need to start here:
    http://download-llnw.oracle.com/javase/tutorial/

    db

Posting Permissions

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