How do you link two forms together? T_T
I need to link two forms in my programme.
I tried calling this method;
public static void showProfitGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
profitFrame = new JFrame("profit sharing");
profitFrame.setSize(400, 400);
profitFrame.setLocation(200, 200);
profitFrame.setVisible(true);
profitFrame.setResizable(false);
}
But, now a frame comes out without any of the content on the page. I use a gridbag layout, and all the components are added to a container, with the name "c"
sample code;
c.add(componentname);
Is there anyway i can fix this so it shows all the items on the c container, instead of the Jframe?
ANy other way of linking forms together is welcomed,
[765 byte] By [
Serenit_ya] at [2007-11-27 1:41:27]

# 2
FIRST PAGE SAMPLE CODE
// Client.java
// Demonstrating ClientLayout.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class page1 extends JFrame{
private JLabel title
public page1()
{
super( "Page 1 Booking form" );
Container c = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints =
new GridBagConstraints();
c.setLayout(gridbag );
//-Search label and textbox
Name = new JLabel( "Name",JLabel.CENTER);
constraints.gridx=0;
constraints.gridy=2;
constraints.weightx=1.0;
constraints.insets = new Insets (5,0,0,0);
gridbag.setConstraints(Name,constraints);
Name.setForeground(Color.black);
Name.setFont(new Font("palatino linotype", Font.PLAIN,13));
c.add( Name);
//
txtName = new JTextField(20);
constraints.gridx=1;
constraints.gridy=2;
constraints.weightx=1.0;
constraints.insets = new Insets (5,0,0,0);
gridbag.setConstraints(txtName, constraints);
c.add(txtName);
setSize( 650, 700);
setVisible(true);
}
public static void main( String args[] )
{
page1 app = new page1();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
SECOND PAGE SAMPLE CODE
// Client.java
// Demonstrating ClientLayout.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class page2 extends JFrame{
private JLabel title
public page2()
{
super( "Page 2 Booking form" );
Container c = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints =
new GridBagConstraints();
c.setLayout(gridbag );
//-Search label and textbox
Name = new JLabel( "Name",JLabel.CENTER);
constraints.gridx=0;
constraints.gridy=2;
constraints.weightx=1.0;
constraints.insets = new Insets (5,0,0,0);
gridbag.setConstraints(Name,constraints);
Name.setForeground(Color.black);
Name.setFont(new Font("palatino linotype", Font.PLAIN,13));
c.add( Name);
//
txtName = new JTextField(20);
constraints.gridx=1;
constraints.gridy=2;
constraints.weightx=1.0;
constraints.insets = new Insets (5,0,0,0);
gridbag.setConstraints(txtName, constraints);
c.add(txtName);
setSize( 650, 700);
setVisible(true);
}
public static void main( String args[] )
{
page2 app = new page2();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
--
I need to link Page1 to Page2. So when i click a button in Page1, page 2 comes up.
The forms are gridbag based, and the only component on them, is a label. Just to make things simpler.
# 3
well your code isn't running, as it have some undeclared variables.
probably you didn't paste the whole code.
never the less heres what you can do to link page2 with page1 button....
what have you done here is you using both the pages as separate JFrame..... having main() method in each page.
now to get what you need, remove main() method from page2, as page2 is suppose to be called by page1 not by itself.
and copy this code from page2 main() method i.e
page2 app = new page2();
and place it wherever you define the actionlistener of button of page1.
though i failed to see where you adding a button which will bring up the page2 upon clicking.....