Results 1 to 7 of 7
  1. #1
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default I need help new with java

    I'm trying to figure out how to display a JPANEL and be able to select a file to review it, but off the bat I having problmes figuring out the first steps I have some code if someone could give me some guidance to how to start properly or what i need to make this work, thanks

    import java.io.*;
    import javax.swing.*;

    public class checkValue {
    //create a Dialog box to locate the site file
    public static String propertiesFilePath;
    public static JButton siteBrowse = new JButton("Browse");
    public static void main(String[] args){
    //Variables
    // String GetSiteFile;
    // String propertiesFilePath;
    // GetSiteFile = JOptionPane.showInputDialog("Get Site File");

    JPanel sitePanel = new JPanel();
    sitePanel.setLayout(null);
    JLabel siteLabel = new JLabel("File");
    sitePanel.add(siteLabel);
    // sitePanel.add(siteText);
    sitePanel.add(siteBrowse);


    try {
    JFileChooser fileChooser = new JFileChooser();
    //File currentDir = new File
    File currentDir = new File(propertiesFilePath);
    fileChooser.setCurrentDirectory(currentDir);
    //look at startupdialog in MDN code gui/components/
    // /** Button to browse for site file. */
    // final JButton siteBrowse = new JButton("Browse");
    //below section will open the broswer to a directory
    fileChooser.setApproveButtonText("Select Site File");
    fileChooser.setDialogTitle("Site File");

    }
    catch (Exception e)
    {
    System.err.println("yes)");
    }
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: I need help new with java

    When posting code, please use the code tags to preserve formatting.

    What does this code do? Does it compile? Does it run? Does it exhibit some strange behavior? Does it gain sentience and refuse to follow your commands, preventing you from going on an evolutionary adventure through the stars, eventually finding out essential truths about the universe, humanity, and yourself? Or something else?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: I need help new with java

    Quote Originally Posted by KevinWorkman View Post
    When posting code, please use the code tags to preserve formatting.

    What does this code do? Does it compile? Does it run? Does it exhibit some strange behavior? Does it gain sentience and refuse to follow your commands, preventing you from going on an evolutionary adventure through the stars, eventually finding out essential truths about the universe, humanity, and yourself? Or something else?
    not sure how to use code marks,
    the code needs to read a file that a person selects from a current directory and find speific words in that text file.
    it compiles but hits the exception thread all the time, I think I'm missing how the beginning should work.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: I need help new with java

    You can use code tags by putting your code between code tags, without the spaces:

    [ CODE ]
    code goes here
    [ /CODE ]

    What Exception do you get? What happened when you googled that Exception?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: I need help new with java

    Quote Originally Posted by KevinWorkman View Post
    You can use code tags by putting your code between code tags, without the spaces:

    [ CODE ]
    code goes here
    [ /CODE ]

    What Exception do you get? What happened when you googled that Exception?
    it hits the exception println with 'yes' as the object to be printed, I'm not sure if I even have he code setup properly the I am new to Java so thanks for your patience it should show a dialog box with a button to select a file, then open a window at a the current directory.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: I need help new with java

    What line in your code throws the exception? What is the *exact* text of the error? Feel free to copy and paste the stack trace here.

    In your catch block, you can print the stack trace by calling Exception.printStackTrace();

    Java Code:
    try{
       //some dangerous code here
    }
    catch(Exception e){
       e.printStackTrace();
    }
    Also, see how much nicer code looks when you use the code tags?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: I need help new with java

    Quote Originally Posted by KevinWorkman View Post
    What line in your code throws the exception? What is the *exact* text of the error? Feel free to copy and paste the stack trace here.

    In your catch block, you can print the stack trace by calling Exception.printStackTrace();

    Java Code:
    try{
       //some dangerous code here
    }
    catch(Exception e){
       e.printStackTrace();
    }
    Also, see how much nicer code looks when you use the code tags?

    yes thanks i understand a little better i will reply for more help, thanks

Posting Permissions

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