Results 1 to 4 of 4
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

    Default how to check the window has already opened

    hi
    my problem regarding the child window is attached

    please advice me in the code



    Thank You
    Attached Files Attached Files

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

    Default

    To improve your chances of getting decent help you may wish to:

    1) Describe in greater detail just what these two windows are supposed to do, what they're currently doing, and what they're not doing that you want them to do.
    2) Go into a little more depth describing what this part of the program does from the user's perspective, not from a code perspective.
    3) Post your code here with code tags. It's best to post the smallest amount of code necessary that compiles, runs, and demonstrates your problem.
    4) Have you tried any of the suggestions in your previous thread? If so, what are the results of these attempts? [edit: I think my suggestion is the correct one, but heck if I know without more input from you]

    The key is if you do a little more work here to make it easier for others to help you, you'll increase your chances that others will do the same.

    Best of luck!
    Last edited by Fubarable; 01-29-2010 at 05:35 AM.

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

    Default

    For example, a small program to demonstrate use of JOptionPane to show a dialog:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class FooFrame {
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("FooFrame");
          frame.getContentPane().add(new FooFrame1().getComponent());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    class FooFrame1 {
       private JPanel mainPanel = new JPanel();
       private JTextField selection1Field = new JTextField(10);
       private JTextField selection2Field = new JTextField(10);
    
       public FooFrame1() {
          selection1Field.setEditable(false);
          selection2Field.setEditable(false);
          
          JButton openDialogBtn = new JButton("Open Second Window");
          openDialogBtn.addActionListener(new OpenDialogListener());
          
          mainPanel.add(selection1Field);
          mainPanel.add(selection2Field);
          mainPanel.add(openDialogBtn);
       }
    
       public JComponent getComponent() {
          return mainPanel;
       }
       
       private class OpenDialogListener implements ActionListener {
          private FooFrame2 foo2 = new FooFrame2();
          
          public void actionPerformed(ActionEvent e) {
             int result = JOptionPane.showConfirmDialog(mainPanel, foo2.getComponent(), 
                      "Select Options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
             if (result == JOptionPane.OK_OPTION) {
                selection1Field.setText(foo2.getCombo1SelectedItem());
                selection2Field.setText(foo2.getCombo2SelectedItem());
             }
          }
       }
    }
    
    class FooFrame2 {
       public static final String[] DATA = {
         "January", "February", "March", "April", "May", "June" 
       };
       private JPanel mainPanel = new JPanel();
       private JComboBox combo1 = new JComboBox(DATA);
       private JComboBox combo2 = new JComboBox(DATA);
    
       public FooFrame2() {
          mainPanel.setLayout(new GridLayout(0, 1, 10, 10));
          mainPanel.add(combo1);
          mainPanel.add(combo2);
       }
    
       public JComponent getComponent() {
          return mainPanel;
       }
       
       public String getCombo1SelectedItem() {
          return combo1.getSelectedItem().toString();
       }
    
       public String getCombo2SelectedItem() {
          return combo2.getSelectedItem().toString();
       }
    
    }

  4. #4
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

Similar Threads

  1. Replies: 0
    Last Post: 03-23-2009, 04:19 PM
  2. Deleting a File that is opened
    By ravian in forum Advanced Java
    Replies: 6
    Last Post: 01-30-2008, 02:05 PM
  3. Reading an already opened file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 06:50 PM
  4. Replies: 0
    Last Post: 12-04-2007, 11:11 AM
  5. How to know the ports opened by JVM
    By sandeepspatil in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 01:51 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
  •