Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Moving between frames

Fri Jun 15, 2007 4:55 pm

Hi sami and all of codemiles members,

Is there a standard way to move between frames within a single application, if there exist please give me an example?

thank you



Re: Moving between frames

Fri Jun 15, 2007 5:32 pm

Mohamed Alzahar wrote:Hi sami and all of codemiles members,

Is there a standard way to move between frames within a single application, if there exist please give me an example?

thank you

What Do u mean to move between Frame. In Java u can open and close frames and the application will still be running !! :roll:

Re: Moving between frames

Fri Jun 15, 2007 6:30 pm

suppose you develop an application that contain multiple JFrame classes and one Main class, and each JFrame class contain two buttons labled as Next and Previous:
public class Main{
private JFrame1 f1;
private JFrame2 f2;
private JFrame3 f3;
private JFrame4 f4;

public static void main(String [] args)
{
f1=new JFrame1();
f1.show();
}

In the previous code you create an instance from f1 and f1 currently on your screen that display a simple frame contain Next and Previous buttons,

The Challange here "My question ", how you can link Next button using actionPerformed to display f2 and Previous button using the actionPerformed to display f3?


If the above code not correct send the correct code but consider my question

salam


}

Re: Moving between frames

Fri Jun 15, 2007 7:16 pm

Oh ,First of all using show() is not good , Because Java Designers noticed problems in some cases. you can use setVisible(true) to show a frame and setVisible(false) to hide a frame and use dispose() function to close the frame (remove it from the memory ) .
well using the ActionListener implementation you will write
Code:
   next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                    setVisible(false); // for the current frame
                   if(nextframe!=null)
                    nextframe.setVisible(true); // for the next frame
                }
            }
        });

so i mean u will take a reference to the next frame for each frame
Code:
public class Main{
private myFrame f1;
private myFrame f2;
private myFrame f3;
private myFrame f4;

public static void main(String [] args)
{
f4=new myFrame(null);
f3=new myFrame(f4);
f2=new myFrame(f3);
f1=new myFrame(f2);



f1.show();
}



i hope i helped u ! :mrgreen:

Post a reply
  Related Posts  to : Moving between frames
 moving glasspane between frames     -  
 moving files in php     -  
 HOW TO KEEP OBJECT MOVING FOLLOW.     -  
 Moving Background in flash     -  
 moving file with copy() function in php     -  
 Create a moving text banner     -  
 a moving graph sortof widget build using Swing     -  
 Javascript Code For Moving Images On Click Of A Button     -  

Topic Tags

Java Swing