Results 1 to 1 of 1
  1. #1
    vdparaliya is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Thumbs up 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

  1. Create a form, input some data and save to file
    By cselic in forum AWT / Swing
    Replies: 5
    Last Post: 05-07-2010, 12:28 PM
  2. Replies: 1
    Last Post: 03-22-2010, 09:03 AM
  3. Create jar from multiple jars
    By rummy in forum New To Java
    Replies: 2
    Last Post: 01-06-2010, 03:03 PM
  4. Replies: 10
    Last Post: 08-12-2009, 04:02 PM
  5. Replies: 1
    Last Post: 08-02-2009, 12:12 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
  •