Results 1 to 6 of 6
  1. #1
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Running code cant pause to run other class

    Hello

    I have a problem with this two classes of java.
    when i run the callfile.java runs the code both of the classes ant dosnot wait to iput the files from the second class (PlayerFileChooser.java).
    I want to make it to wait to input the files with tha jframe of the second class and then to end the code.
    Actually to continue running the code after i press the (continou the code) button.
    I mean when i press the (continou the code) button to close the frame of the PlayerFileChooser.java class and then to continue to the next code of the callfile.java class.
    to be more specific i need this steps
    1-Run the callfile.java
    2-print in the output window the "start'
    3- call PlayerFileChooser.java class an sellect the files from the button (Find the Player Net)
    4- when i press the (continou the code) jbutton from the frame to close the frame and continue running next code from callfile.java an that prints in the output windows "end";

    Thank you in advanced.


    image from frame of PlayerFileChooser.java class

    Running code cant  pause to run other class-screenshot-2012-01-08-21-00-32.png


    callfile.java
    Java Code:
    public class callfile {
        public static void main(String[] args){
        
        System.out.println("Start\n");
        PlayerFileChooser choose = new PlayerFileChooser();
        choose.createAndShowGUI();
        
        System.out.println("end");
         
        }
    }


    PlayerFileChooser.java
    Java Code:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.SwingUtilities;
    import javax.swing.filechooser.*;
    
    public class PlayerFileChooser extends JPanel
                                 implements ActionListener {
        static private final String newline = "\n";
        JButton openButton, saveButton;
        JTextArea log;
        JFileChooser fc;
    
        public PlayerFileChooser() {
            super(new BorderLayout());
    
            //Create the log first, because the action listeners
            //need to refer to it.
            log = new JTextArea(10,40);
            log.setMargin(new Insets(5,5,5,5));
            log.setEditable(false);
            JScrollPane logScrollPane = new JScrollPane(log);
    
            //Create a file chooser
            fc = new JFileChooser();
    
            openButton = new JButton("Find the Player Nets");
            openButton.addActionListener(this);
    
            saveButton = new JButton("continou the code");
            saveButton.addActionListener(this);
    
            //For layout purposes, put the buttons in a separate panel
            JPanel buttonPanel = new JPanel(); //use FlowLayout
            buttonPanel.add(openButton);
            buttonPanel.add(saveButton);
    
            //Add the buttons and the log to this panel.
            add(buttonPanel, BorderLayout.PAGE_START);
            add(logScrollPane, BorderLayout.CENTER);
        }
    
        public void actionPerformed(ActionEvent e) {
    
            //Handle open button action.
            if (e.getSource() == openButton) {
                int returnVal = fc.showOpenDialog(PlayerFileChooser.this);
    
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File Netfile = fc.getSelectedFile();
                    //This is where a real application would open the file.
                    log.append("Opening: " + Netfile.getName() + "." + newline);
                    log.append("First Player Folder: " + Netfile.getAbsolutePath() + ""+ newline);
                } else {
                    log.append("Open command cancelled by user." + newline);
                }
                log.setCaretPosition(log.getDocument().getLength());
    
            //Handle save button action.
            } else if (e.getSource() == saveButton) {
                
                
                
            }
        }
    
        public static   void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("FileChooser");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();   
            
            frame.setLocation(((screenSize.width/2)-200), ((screenSize.height/2)-50));
    
            //Add content to the window.
            frame.add(new PlayerFileChooser());
    
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
    
    
        
    }
    Last edited by Fubarable; 01-08-2012 at 08:06 PM. Reason: code tags added

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

    Default Re: Running code cant pause to run other class

    If you want a window to open as a modal dialog (which is what I think you are trying to achieve), then consider using just that -- a modal JDialog, not a JFrame. There are many examples of how to use them here in this forum.

    As an aside, be sure to use a background thread to load your files such as is available with a SwingWorker. I would add a PropertyChangeListener to the SwingWorker and listen for its completion. Only when it's complete would I enable the second JButton.

  3. #3
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Running code cant pause to run other class

    thank you very much
    i will try it and replay you.

  4. #4
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Running code cant pause to run other class

    can i open a filechooser from Jdialog do you have any sample??????

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

    Default Re: Running code cant pause to run other class

    Quote Originally Posted by ki_ha1984 View Post
    can i open a filechooser from Jdialog do you have any sample??????
    Yes. The code is no different from opening a JFileChooser elsewhere.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: Running code cant pause to run other class

    Quote Originally Posted by ki_ha1984 View Post
    can i open a filechooser from Jdialog do you have any sample??????
    Yes, you can do that; no problem. The JFileChooser class simply opens another modal JDialog and does its work.

    kind regards,

    Jos

    edit: too slow again (as ususal ...)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 1
    Last Post: 02-12-2011, 05:36 PM
  2. Replies: 14
    Last Post: 07-23-2010, 10:02 PM
  3. my code compiling but not running
    By girishkumar in forum New To Java
    Replies: 16
    Last Post: 03-16-2010, 04:45 PM
  4. How to stop/pause running third party exe?
    By 2bGeek in forum AWT / Swing
    Replies: 3
    Last Post: 02-28-2009, 07:26 AM
  5. problem while running java code..
    By Jjava in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 06:33 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
  •