Results 1 to 3 of 3
  1. #1
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default Use multiple forms

    Hi, me and a friend are writing a java applet and want it to use multiple forms, although we haven't found a sites saying you can do this - ne advice?

    Well we use a program called netbeans to code in, basically we are coding a game and we need to have several screens,

    Mainly though one for options and one for the actual playing,

    So we need to be able to link the GUI forms together - ie if they choose play (after choosing settings on the options page) the new form/screen/page appears with the game itself.

    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Dialogs work well for these kind of things. You can use them for options, signing–in and the like and then show the game in a JFrame. See How to Make Dialogs for more information.

  3. #3
    vdparaliya is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Hello Friend U can do This .....
    I have create two Class Like below and using this method you can switch from one class to another class

    First Class is like below name is : 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);
    }
    }

    Here First Class is Completed now Second Class is like this name is 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 End of Second Class now you can use this method to create multiple forms and also you can send data from one class to another using constructor till you have problem then just send me a Mail at vdparaliya@gmail.com

Similar Threads

  1. Login Forms
    By dankonsoer in forum New To Java
    Replies: 1
    Last Post: 08-07-2008, 01:06 PM
  2. [SOLVED] Navigation between swing forms
    By stevedb in forum AWT / Swing
    Replies: 7
    Last Post: 04-01-2008, 02:23 PM
  3. JMenu calling another Forms/Panels
    By plodos in forum New To Java
    Replies: 2
    Last Post: 12-10-2007, 09:02 AM
  4. Creating Sub forms in java netbeans 5.0
    By java_newbie in forum NetBeans
    Replies: 14
    Last Post: 08-06-2007, 08:19 PM
  5. Forms in jsp
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •