Opening a new form by the click of a button

Hi all, am new to java. am working on a project, i want to know how i can get to open a form when a button in another form is clicked.
[141 byte] By [ucy_laga] at [2007-11-26 16:19:38]
# 1
put a button on form one, and add an actionlistener to it. In the actionPerformed method of the actionlistener, show your new form.~Tim
SomeoneElsea at 2007-7-8 22:43:06 > top of Java-index,Java Essentials,New To Java...
# 2

thanks a lot, how to get the actionperformed to show the second form is the problem. plz take a look at the work, its really rough at this point. where i have the ****** is where i got stuck.import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class ApplicationFrm1 extends JFrame implements ActionListener

{

static JFrame frame;

static JPanel panel;

JLabel lformname;

JLabel lapplying;

JLabel lprogram;

JLabel lschool;

JLabel lpersonaldetails;

JLabel lname;

JLabel lfirst;

JLabel lmiddle;

JLabel llast;

JLabel laddress;

JLabel lcity;

JLabel lstate;

JLabel lzipcode;

JLabel lcountry;

JLabel lphoneres;

JLabel lcountrycode;

JLabel lareacode;

JLabel lphoneno;

JLabel lphoneoffice;

JLabel lcountrycode1;

JLabel lareacode1;

JLabel lphoneno1;

JLabel lemail;

JLabel lgender;

JLabel ldob;

JLabel lmonth;

JLabel lday;

JLabel lyear;

JLabel lcitizen;

JButton bcontinue;

JTextField tapplying;

JTextField tprogram;

JTextField tschool;

JTextField tname;

JTextField tfirst, tmiddle, tlast;

JTextField taddress;

JTextField tcity, tstate, tzipcode, tcountry;

JTextField tcountrycode, tareacode, tphoneno;

JTextField tcountrycode1,tareacode1,tphoneno1;

JTextField temail;

JComboBox cbgender;

JComboBox cdmonth;

JComboBox cdday;

JComboBox cdyear;

JComboBox ccitizen;

GridBagLayout g;

GridBagConstraints gbc;

public ApplicationFrm()

{

super("Application Form");

g = new GridBagLayout();

gbc = new GridBagConstraints();

panel = (JPanel)getContentPane();

frame = new JFrame ("Application form ");

frame.getContentPane().add(panel);

panel.setLayout(g);

gbc.fill = GridBagConstraints.BOTH;

lformname = new JLabel ("Application Form");

gbc.gridx = 0;

gbc.gridy = 1;

g.setConstraints(lformname, gbc);

panel.add(lformname);

lapplying = new JLabel ("Applying For:");

gbc.gridx = 0;

gbc.gridy = 2;

g.setConstraints(lapplying, gbc);

panel.add(lapplying);

tapplying = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 2;

g.setConstraints(tapplying, gbc);

panel.add(tapplying);

lprogram = new JLabel ("Graduation Degree Program:");

gbc.gridx = 0;

gbc.gridy = 3;

g.setConstraints(lprogram, gbc);

panel.add(lprogram);

tprogram = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 3;

g.setConstraints(tprogram, gbc);

panel.add(tprogram);

lschool = new JLabel ("School:");

gbc.gridx = 0;

gbc.gridy = 4;

g.setConstraints(lschool, gbc);

panel.add(lschool);

tschool = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 4;

g.setConstraints(tschool, gbc);

panel.add(tschool);

lpersonaldetails = new JLabel ("Personal Details:");

gbc.gridx = 0;

gbc.gridy = 5;

g.setConstraints(lpersonaldetails, gbc);

panel.add(lpersonaldetails);

lname = new JLabel ("Name:");

gbc.gridx = 0;

gbc.gridy = 6;

g.setConstraints(lname, gbc);

panel.add(lname);

lfirst = new JLabel ("First:");

gbc.gridx = 0;

gbc.gridy = 7;

g.setConstraints(lfirst, gbc);

panel.add(lfirst);

tfirst = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 7;

g.setConstraints(tfirst, gbc);

panel.add(tfirst);

lmiddle = new JLabel ("Middle:");

gbc.gridx = 2;

gbc.gridy = 7;

g.setConstraints(lmiddle, gbc);

panel.add(lmiddle);

tmiddle = new JTextField(20);

gbc.gridx= 3;

gbc.gridy = 7;

g.setConstraints(tmiddle, gbc);

panel.add(tmiddle);

llast = new JLabel ("Last:");

gbc.gridx = 4;

gbc.gridy = 7;

g.setConstraints(llast, gbc);

panel.add(llast);

tlast = new JTextField(20);

gbc.gridx= 5;

gbc.gridy = 7;

g.setConstraints(tlast, gbc);

panel.add(tlast);

laddress = new JLabel ("Address:");

gbc.gridx = 0;

gbc.gridy = 8;

g.setConstraints(laddress, gbc);

panel.add(laddress);

taddress = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 8;

g.setConstraints(taddress, gbc);

panel.add(taddress);

lcity = new JLabel ("City:");

gbc.gridx = 0;

gbc.gridy = 9;

g.setConstraints(lcity, gbc);

panel.add(lcity);

tcity = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 9;

g.setConstraints(tcity, gbc);

panel.add(tcity);

lzipcode = new JLabel ("Zip Code:");

gbc.gridx = 3;

gbc.gridy = 9;

g.setConstraints(lzipcode, gbc);

panel.add(lzipcode);

tzipcode = new JTextField(20);

gbc.gridx= 4;

gbc.gridy = 9;

g.setConstraints(tzipcode, gbc);

panel.add(tzipcode);

lcountry = new JLabel ("Country:");

gbc.gridx = 5;

gbc.gridy = 9;

g.setConstraints(lcountry, gbc);

panel.add(lcountry);

tcountry = new JTextField(20);

gbc.gridx= 6;

gbc.gridy = 9;

g.setConstraints(tcountry, gbc);

panel.add(tcountry);

lphoneres = new JLabel ("Phone(Residence):");

gbc.gridx = 0;

gbc.gridy = 10;

g.setConstraints(lphoneres, gbc);

panel.add(lphoneres);

lcountrycode = new JLabel ("Country Code:");

gbc.gridx = 0;

gbc.gridy = 11;

g.setConstraints(lcountrycode, gbc);

panel.add(lcountrycode);

tcountrycode = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 11;

g.setConstraints(tcountrycode, gbc);

panel.add(tcountrycode);

lareacode = new JLabel ("Area Code:");

gbc.gridx = 2;

gbc.gridy = 11;

g.setConstraints(lareacode, gbc);

panel.add(lareacode);

tareacode = new JTextField(20);

gbc.gridx= 3;

gbc.gridy = 11;

g.setConstraints(tareacode, gbc);

panel.add(tareacode);

lphoneno = new JLabel ("Phone Number:");

gbc.gridx = 4;

gbc.gridy = 11;

g.setConstraints(lphoneno, gbc);

panel.add(lphoneno);

tphoneno = new JTextField(20);

gbc.gridx= 5;

gbc.gridy = 11;

g.setConstraints(tphoneno, gbc);

panel.add(tphoneno);

lphoneoffice = new JLabel ("Phone(Office):");

gbc.gridx = 0;

gbc.gridy = 12;

g.setConstraints(lphoneoffice, gbc);

panel.add(lphoneoffice);

lcountrycode1 = new JLabel ("Country Code:");

gbc.gridx = 0;

gbc.gridy = 13;

g.setConstraints(lcountrycode1, gbc);

panel.add(lcountrycode1);

tcountrycode1 = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 13;

g.setConstraints(tcountrycode1, gbc);

panel.add(tcountrycode1);

lareacode1 = new JLabel ("Area Code:");

gbc.gridx = 2;

gbc.gridy = 13;

g.setConstraints(lareacode1, gbc);

panel.add(lareacode1);

tareacode1 = new JTextField(20);

gbc.gridx= 3;

gbc.gridy = 13;

g.setConstraints(tareacode1, gbc);

panel.add(tareacode1);

lphoneno1 = new JLabel ("Phone Number:");

gbc.gridx = 4;

gbc.gridy = 13;

g.setConstraints(lphoneno1, gbc);

panel.add(lphoneno1);

tphoneno1 = new JTextField(20);

gbc.gridx= 5;

gbc.gridy = 13;

g.setConstraints(tphoneno1, gbc);

panel.add(tphoneno1);

lemail = new JLabel ("E-mail Address:");

gbc.gridx = 0;

gbc.gridy = 14;

g.setConstraints(lemail, gbc);

panel.add(lemail);

temail = new JTextField(20);

gbc.gridx= 1;

gbc.gridy = 14;

g.setConstraints(temail, gbc);

panel.add(temail);

lgender = new JLabel ("Gender:");

gbc.gridx = 0;

gbc.gridy = 15;

g.setConstraints(lgender, gbc);

panel.add(lgender);

cbgender = new JComboBox();

cbgender.addItem("Female");

cbgender.addItem("Male");

gbc.gridx = 1;

gbc. gridy = 15;

g.setConstraints(cbgender, gbc);

panel.add(cbgender);

ldob = new JLabel ("Date of Birth:");

gbc.gridx = 0;

gbc.gridy = 16;

g.setConstraints(ldob, gbc);

panel.add(ldob);

lmonth = new JLabel ("Month:");

gbc.gridx = 0;

gbc.gridy = 17;

g.setConstraints(lmonth, gbc);

panel.add(lmonth);

cdmonth = new JComboBox();

cdmonth.addItem("January");

cdmonth.addItem("Febuary");

cdmonth.addItem("March");

cdmonth.addItem("April");

gbc.gridx = 1;

gbc. gridy = 17;

g.setConstraints(cdmonth, gbc);

panel.add(cdmonth);

lday = new JLabel ("Day:");

gbc.gridx = 2;

gbc.gridy = 17;

g.setConstraints(lday, gbc);

panel.add(lday);

cdday = new JComboBox();

cdday.addItem("1");

cdday.addItem("2");

cdday.addItem("3");

cdday.addItem("4");

cdday.addItem("5");

cdday.addItem("6");

cdday.addItem("7");

cdday.addItem("8");

gbc.gridx = 3;

gbc. gridy = 17;

g.setConstraints(cdday, gbc);

panel.add(cdday);

lyear = new JLabel ("Year:");

gbc.gridx = 4;

gbc.gridy = 17;

g.setConstraints(lyear, gbc);

panel.add(lyear);

cdyear = new JComboBox();

cdyear.addItem("1990");

cdyear.addItem("1991");

cdyear.addItem("1992");

cdyear.addItem("1993");

cdyear.addItem("1994");

cdyear.addItem("1995");

cdyear.addItem("1996");

cdyear.addItem("1997");

cdyear.addItem("1998");

cdyear.addItem("1999");

cdyear.addItem("2000");

cdyear.addItem("2001");

cdyear.addItem("2002");

cdyear.addItem("2003");

cdyear.addItem("2004");

cdyear.addItem("2005");

gbc.gridx = 5;

gbc. gridy = 17;

g.setConstraints(cdyear, gbc);

panel.add(cdyear);

lcitizen = new JLabel ("Citizenship Status:");

gbc.gridx = 0;

gbc.gridy = 18;

g.setConstraints(lcitizen, gbc);

panel.add(lcitizen);

ccitizen = new JComboBox();

ccitizen.addItem("U.S Citizen");

ccitizen.addItem("U.S Permanent Resident");

ccitizen.addItem("Not a U.s Citizen");

ccitizen.addItem("Decline to state");

gbc.gridx = 1;

gbc. gridy = 18;

g.setConstraints(ccitizen, gbc);

panel.add(ccitizen);

bcontinue = new JButton ("CONTINUE");

gbc.gridx = 0;

gbc.gridy = 19;

g.setConstraints(bcontinue, gbc);

panel.add(bcontinue);

bcontinue.addActionListener(this);

}

public void actionPerformed(ActionEvent ae)

{

string s = ae.getActionCommand();

if("CONTINUE".equals(s))

{

***************************************************************************

}

}

}

public class QualificationDetails extends JFrame

{

static JFrame frame;

static JPanel panel;

JLabel lquldetails;

JLabel lprogram;

JLabel lgrade;

JLabel lschool;

JLabel luniversity;

JLabel lgrescore;

JLabel ltestdate;

JLabel lscore;

JLabel ltoefl;

JLabel lhonors;

JTextField tquldetails;

JTextField tprogram;

JTextField tgrade;

JTextField tschool;

JTextField tuniversity;

JTextField tgrescore;

JTextField ttestdate;

JTextField tscore;

JTextField ttoefl;

JTextField thonors;

JButton bsubmit;

GridBagLayout g;

GridBagConstraints gbc;

public QualificationDetails()

{

super("Qualification details");

g = new GridBagLayout();

gbc = new GridBagConstraints();

panel = (JPanel)getContentPane();

frame = new JFrame ("Application form ");

frame.getContentPane().add(panel);

panel.setLayout(g);

gbc.fill = GridBagConstraints.BOTH;

lquldetails = new JLabel ("Qualification Details:");

gbc.gridx = 0;

gbc.gridy = 1;

g.setConstraints(lquldetails, gbc);

panel.add(lquldetails);

lprogram = new JLabel ("Graduation degree Program:");

gbc.gridx = 0;

gbc.gridy = 2;

g.setConstraints(lprogram, gbc);

panel.add(lprogram);

tprogram = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 2;

g.setConstraints(tprogram, gbc);

panel.add(tprogram);

lgrade = new JLabel ("Grade:");

gbc.gridx = 2;

gbc.gridy = 2;

g.setConstraints(lgrade, gbc);

panel.add(lgrade);

tgrade = new JTextField(50);

gbc.gridx= 3;

gbc.gridy = 2;

g.setConstraints(tgrade, gbc);

panel.add(tgrade);

lschool = new JLabel ("School:");

gbc.gridx = 0;

gbc.gridy = 3;

g.setConstraints(lschool, gbc);

panel.add(lschool);

tschool = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 3;

g.setConstraints(tschool, gbc);

panel.add(tschool);

luniversity = new JLabel ("University:");

gbc.gridx = 2;

gbc.gridy = 3;

g.setConstraints(luniversity, gbc);

panel.add(luniversity);

tgrade = new JTextField(50);

gbc.gridx= 3;

gbc.gridy = 3;

g.setConstraints(tuniversity, gbc);

panel.add(tuniversity);

lgrescore = new JLabel ("Graduate Record Examination(GRE) Score:");

gbc.gridx = 0;

gbc.gridy = 4;

g.setConstraints(lgrescore, gbc);

panel.add(lgrescore);

tgrescore = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 4;

g.setConstraints(tgrescore, gbc);

panel.add(tgrescore);

ltestdate = new JLabel ("Test Date:");

gbc.gridx = 0;

gbc.gridy = 5;

g.setConstraints(ltestdate, gbc);

panel.add(ltestdate);

ttestdate = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 5;

g.setConstraints(ttestdate, gbc);

panel.add(ttestdate);

lscore = new JLabel ("Score(%):");

gbc.gridx = 2;

gbc.gridy = 5;

g.setConstraints(lscore, gbc);

panel.add(lscore);

tscore = new JTextField(50);

gbc.gridx= 3;

gbc.gridy = 5;

g.setConstraints(tscore, gbc);

panel.add(tscore);

ltoefl = new JLabel ("TOEFL Score (If required):");

gbc.gridx = 0;

gbc.gridy = 6;

g.setConstraints(ltoefl, gbc);

panel.add(ltoefl);

ttoefl = new JTextField(50);

gbc.gridx= 1;

gbc.gridy = 6;

g.setConstraints(ttoefl, gbc);

panel.add(ttoefl);

lhonors = new JLabel ("Details of Recent Honors and Awards:");

gbc.gridx = 0;

gbc.gridy = 7;

g.setConstraints(lhonors, gbc);

panel.add(lhonors);

thonors = new JTextField(100);

gbc.gridx= 1;

gbc.gridy = 7;

g.setConstraints(thonors, gbc);

panel.add(thonors);

}

}

public static void main(String[] args)

{

ApplicationFrm af = new ApplicationFrm();

}

}

}

ucy_laga at 2007-7-8 22:43:06 > top of Java-index,Java Essentials,New To Java...
# 3

That's just nasty. Could you have tried to present a smaller example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Simple implements ActionListener {

private JFrame another = new JFrame("another");

public Simple() {

another.getContentPane().add(new JLabel("Another frame"));

another.pack();

}

public static void main(String[] args) {

JButton btn = new JButton("press me");

btn.addActionListener(new Simple());

JFrame main = new JFrame("main frame");

main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

main.getContentPane().add(btn, BorderLayout.NORTH);

main.setSize(400,300);

main.setLocationRelativeTo(null);

main.setVisible(true);

}

public void actionPerformed(ActionEvent evt) {

another.setLocationRelativeTo((Component) evt.getSource());

another.setVisible(true);

}

}

DrLaszloJamfa at 2007-7-8 22:43:06 > top of Java-index,Java Essentials,New To Java...