Results 1 to 1 of 1
- 06-14-2010, 05:21 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Solution to Create Multiple Form and Switch between them Easy
Hello Friend Use JFrame to switch between forms that is easy way like below example
This is Codding for First Class of name : JF1
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JF1 extends JFrame implements WindowListener,MouseListener
{
JButton jbt;
public JF1()
{
// To Set Titile of Window and Size and Add Window Listener
super("Guru");
setSize(300,400);
addWindowListener(this);
// To create a JButton
jbt = new JButton("This is JF1");
jbt.addMouseListener(this);
add(jbt);
setVisible(true);
}
public static void main(String[] arg)
{
JF1 jf = new JF1();
}
// Window Listener Class Methods to Exit from Window and also from programe
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowOpened(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
// Mouse Listener Class Method to open another Window
public void mouseExited(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
JF2 jf2 = new JF2();
this.setVisible(false);
}
}
Now Create another class name JF2
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JF2 extends JFrame implements WindowListener,MouseListener
{
JButton jbt;
public JF2()
{
// To Set Titile of Window and Size and Add Window Listener
super("Guru");
setSize(300,400);
addWindowListener(this);
// To create a JButton
jbt = new JButton("This is JF2");
jbt.addMouseListener(this);
add(jbt);
setVisible(true);
}
public static void main(String[] arg)
{
JF2 jf = new JF2();
}
// Window Listener Class Methods to Exit from Window and also from programe
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowOpened(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
// Mouse Listener Class Method to open another Window
public void mouseExited(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
JF1 jf1 = new JF1();
this.setVisible(false);
}
}
This is completed now use this class and use Command like below
First Compile them
javac JF1.java
javac JF2.java
Now run one of them
java JF1
now you can see this it can switch both class using button just click on it and another class form will open and first will close..
we can also use constructor to send data to another class OK friends take care ....
If till you have problem then Mail me at <Moderator edit: email address removed>Last edited by DarrylBurke; 05-24-2011 at 12:26 PM. Reason: Removed email address
Similar Threads
-
Create a form, input some data and save to file
By cselic in forum AWT / SwingReplies: 5Last Post: 05-07-2010, 12:28 PM -
looking for a form pane or form group panel for the jpanel to complete tutorial
By nadeemshafi9 in forum AWT / SwingReplies: 1Last Post: 03-22-2010, 09:03 AM -
Create jar from multiple jars
By rummy in forum New To JavaReplies: 2Last Post: 01-06-2010, 03:03 PM -
want to generate a html form page with dynamic data and submit this form to a url
By vishalkrsrivastava in forum Java AppletsReplies: 10Last Post: 08-12-2009, 04:02 PM -
Is there a way to use jface to create an input dialog for multiple checkboxes?
By glmarsh in forum SWT / JFaceReplies: 1Last Post: 08-02-2009, 12:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks