How to access components in multiple frames?

View: New views
3 Messages — Rating Filter:   Alert me  

How to access components in multiple frames?

by mohitkk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

   I am new to junit and i am using the JFCUnit for swing application
under eclipse 3.0 IDE. I have an application in which i have one frame
and on that frame i have multiple frames. The gui components are
present on these multiple frames. Now, how do i test the gui component
which is present on that multiple frames. Please suggest me a solution.

Thanks
Mohit




Parent Message unknown RE: How to access components in multiple frames?

by Colin Vipurs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Again Mohit,

 

Do you mean frames as in JFrame or Panels? If you mean frames (JFrame,
JDialog) an approach I use is to treat any other dialog that can be
displayed as a separate service within the system, utilising a
service-oriented architecture (SOA).  You can then keep your individual
frames down to a single unit, improving coupling and cohesion.  For
example, imagine you have a screen where a user is entering some
Customer details, part of which requires a separate dialog for entering
an Address.  On your CustomerDetailsView there would be an "Address"
button which is linked to a call to "enterAddress" on the
CustomerDetailsController, which would take care of popping up the
dialog, so:

 

In CustomerDetailsView:

 

addressBtn.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {

            controller.enterAddress();

   }

};

 

In CustomerDetailsController:

 

public void enterAddress() {

            Address address =
ServiceRegistry.getAddressService().getNewAddress();

            currentCustomer.setAddress(address);

            view.setAddress(address);

}

 

In your customer details controller/view, your test is just limited to
testing that the correct service call was made, not with having to enter
details on the form and clicking the Ok/Cancel buttons.

 

Again, shout if I haven't been clear enough.

 

________________________________

From: java-gui-testing@...
[mailto:java-gui-testing@...] On Behalf Of mohitkk
Sent: 13 March 2007 09:17
To: java-gui-testing@...
Subject: [java-gui-testing] How to access components in multiple frames?

 

Hi,

I am new to junit and i am using the JFCUnit for swing application
under eclipse 3.0 IDE. I have an application in which i have one frame
and on that frame i have multiple frames. The gui components are
present on these multiple frames. Now, how do i test the gui component
which is present on that multiple frames. Please suggest me a solution.

Thanks
Mohit

 


How to access components in multiple frames?

by mohitkk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Colin,

   Thanks for your worthful suggestion. Your response is really
appreciable. But still i am facing a problem related to the components
i.e. I'm not able to find the particular component from the container.
The template of my code looks like this...

public class mWindow implements ActionListener
{
        //Button for tool bar
        public static JButton tHome  = new JButton();
       
        public static final JDesktopPane desktop = new JDesktopPane();
       
        JMenuBar mBar = new JMenuBar();
       
        JToolBar tBar = new JToolBar();
       
        //main frame in which all components are attaching
        public static Jframe mainWindow = new Jframe("Main");
       
        public mWindow()
        {
                …
                //Creating a menu bar
                this.CreateMenuBar();

                //add menu bar to main frame
                mainWindow.setJMenuBar(mBar);
               
                //creating a tool bar
                this.CreateToolBar();
               
                //add tool bar to main frame
                  mainWindow.getContentPane().add(tBar,BorderLayout.NORTH);
               
                //adding desktop pane
                mainWindow.getContentPane().add(desktop,BorderLayout.CENTER);

                tHome.setEnabled(false);
        }
        …
}
 
Now, in this code what problem i'm facing is that i'm not able to get
the reference of the component. Suppose i want to get the reference of
ToolBar's button i.e. tHome in my test case but i'm always getting the
null value. Whether i try to find the component of ToolBar or MenuBar.
Could you please send me solution of this problem.

   Once again thanks for your worthful suggestion.

Thanks
Mohit