Results 1 to 4 of 4
  1. #1
    kovalensue is offline Member
    Join Date
    Nov 2010
    Posts
    19
    Rep Power
    0

    Default Log file trouble

    hello guys,

    i have made a .log file:

    Java Code:
    public class Start {
    
    public static void main(String[] args) {
    
    
    //Zápis do logu
    String logFile = System.getProperty("java.io.tmpdir") + "adventure.log"; System.out.println(logFile);
    
    .
    .
    .
    GUI gui = new GUI();
    gui.setVisible(true);
    }
    when i run a programme in output window shows this directory of logFile

    C:\Users\VLASTN~1\AppData\Local\Temp\adventure.log
    and now i want to put a button into my GUI and when you click on it then will show up a dialog window with logFile....:

    Java Code:
    private class OvladacLog implements ActionListener {
            private JDialog log;
            private JEditorPane logOutput;
            private String fileDirectory;
    
    
            @Override
            public void actionPerformed(ActionEvent e) {
                log = new JDialog();
                log.setTitle("Log");
                log.setModal(false);
                log.setVisible(true);
                logOutput = new JEditorPane();
                logOutput.setEditable(false);
                log.add(new JScrollPane(logOutput));
                URL fileDirectory = ???? 
                try {
                    logOutput.setPage(fileDirectory);
                } catch (IOException exception) {
                    JOptionPane.showMessageDialog(null,
                            "Log file not found",
                            "Loading failed",
                            JOptionPane.ERROR_MESSAGE);
                }
                log.setLocation(700, 200);
                log.setSize(400, 600);
            }
    
        }
    So, my question is: How to get the .log file which i created in main method and put it into Dialog window??....thanks for help....

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Read the contents of log file using BufferedReader and then add those contents to JTextArea.

    See this code example for more help:
    http://download.oracle.com/javase/tu...tAreaDemo.java

  3. #3
    kovalensue is offline Member
    Join Date
    Nov 2010
    Posts
    19
    Rep Power
    0

    Default

    i dont understand it

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

    Default

    Quote Originally Posted by kovalensue View Post
    i dont understand it
    Unfortunately, that's not a statement that we can answer, and I doubt that you want us to re-write the tutorial. What specifically don't you understand? What have you tried that's not working?

Similar Threads

  1. Having trouble opening and reading a txt file
    By DBaskov in forum New To Java
    Replies: 14
    Last Post: 01-29-2011, 02:55 AM
  2. Trouble drawing image from file picked by JFileChooser
    By I = new NewToJava() in forum New To Java
    Replies: 6
    Last Post: 12-26-2010, 03:54 PM
  3. Trouble with Try Catch blocks and file reading.
    By theBurgh22 in forum New To Java
    Replies: 2
    Last Post: 11-30-2010, 01:11 AM
  4. Having trouble reading external txt file to an array
    By Metastar in forum New To Java
    Replies: 18
    Last Post: 07-21-2010, 11:29 PM
  5. Replies: 0
    Last Post: 12-01-2008, 09:50 PM

Posting Permissions

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