sharath123in
asked on
Navigation to another frame by Buton click
Here is my code after I execute it. It results in a frame with, fist and last names. when I click the login button it opens in a new window. But, the labels from previous frame are there. I want to open a new frame and close old one and those should not appear in the new one.
code..............
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StudentRegister extends JFrame
{
private JTextField textfirstName,textlastName ,textStude ntid;
private JButton buttonSubmit,buttonAdd,but tonDrop,bu ttonFee,bu ttonEE,but tonME,butt onCE,butto nIE;
//status==submit
private JLabel labelfirstName,labellastNa me,labelSt udentI d;
public String firstName[] = new String[50];
public String lastName[] = new String[50];
public StudentRegister()
{
Container container = getContentPane() ;
container.setLayout(new FlowLayout());
labelfirstName = new JLabel("FirstName") ;
container.add(labelfirstNa me );
textfirstName = new JTextField(15) ;
container.add(textfirstNam e );
labellastName = new JLabel("LastName ") ;
container.add(labellastNam e );
textlastName = new JTextField(15) ;
container.add(textlastName );
buttonSubmit = new JButton("LogIn");
container.add(buttonSubmit ) ;
ButtonHandler handler = new ButtonHandler();
buttonSubmit.addActionList ener( handler );
setSize ( 500,600) ;
setVisible(true);
}
public void StudentRegister1()
{
Container container1 = getContentPane() ;
container1.setLayout(new FlowLayout());
buttonAdd = new JButton("AddCourse");
container1.add(buttonAdd) ;
buttonDrop = new JButton("DropCourse");
container1.add(buttonDrop) ;
buttonFee = new JButton("ViewFee");
container1.add(buttonFee) ;
setSize ( 500,600) ;
setVisible(true);
}
public static void main(String args[])
{
StudentRegister student = new StudentRegister() ;
student.setDefaultCloseOpe ration(JFr ame.EXIT_O N_CLOSE );
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEven t event)
{
if (event.getSource() == buttonSubmit)
{
StudentRegister student1 = new StudentRegister() ;
student1.StudentRegister1( );
}
}
}
}
code..............
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StudentRegister extends JFrame
{
private JTextField textfirstName,textlastName
private JButton buttonSubmit,buttonAdd,but
//status==submit
private JLabel labelfirstName,labellastNa
public String firstName[] = new String[50];
public String lastName[] = new String[50];
public StudentRegister()
{
Container container = getContentPane() ;
container.setLayout(new FlowLayout());
labelfirstName = new JLabel("FirstName") ;
container.add(labelfirstNa
textfirstName = new JTextField(15) ;
container.add(textfirstNam
labellastName = new JLabel("LastName ") ;
container.add(labellastNam
textlastName = new JTextField(15) ;
container.add(textlastName
buttonSubmit = new JButton("LogIn");
container.add(buttonSubmit
ButtonHandler handler = new ButtonHandler();
buttonSubmit.addActionList
setSize ( 500,600) ;
setVisible(true);
}
public void StudentRegister1()
{
Container container1 = getContentPane() ;
container1.setLayout(new FlowLayout());
buttonAdd = new JButton("AddCourse");
container1.add(buttonAdd) ;
buttonDrop = new JButton("DropCourse");
container1.add(buttonDrop)
buttonFee = new JButton("ViewFee");
container1.add(buttonFee) ;
setSize ( 500,600) ;
setVisible(true);
}
public static void main(String args[])
{
StudentRegister student = new StudentRegister() ;
student.setDefaultCloseOpe
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEven
{
if (event.getSource() == buttonSubmit)
{
StudentRegister student1 = new StudentRegister() ;
student1.StudentRegister1(
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if (event.getSource() == buttonSubmit)
{
StudentRegister student1 = new StudentRegister() ;
student1.StudentRegister1(
dispose();
}