[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Navigation to another frame by Buton click

Posted on 2005-04-28
Medium Priority
Last Modified: 2012-06-27
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.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class StudentRegister extends JFrame
      private JTextField textfirstName,textlastName,textStudentid;
      private JButton buttonSubmit,buttonAdd,buttonDrop,buttonFee,buttonEE,buttonME,buttonCE,buttonIE;
      private JLabel labelfirstName,labellastName,labelStudentI 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(labelfirstName );
      textfirstName = new JTextField(15) ;
      container.add(textfirstName );

      labellastName = new JLabel("LastName ") ;
      container.add(labellastName );
      textlastName = new JTextField(15) ;
      container.add(textlastName );

      buttonSubmit = new JButton("LogIn");
    container.add(buttonSubmit) ;

    ButtonHandler handler = new ButtonHandler();
      buttonSubmit.addActionListener( handler );

      setSize ( 500,600) ;


      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) ;

      public static void main(String args[])
            StudentRegister student = new StudentRegister() ;
            student.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );

            class ButtonHandler implements ActionListener
                  public void actionPerformed(ActionEvent event)

                        if (event.getSource() == buttonSubmit)
                        StudentRegister student1 = new StudentRegister() ;



Question by:sharath123in
LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 13889770
Really the best way to do this sort of thing is to use a JTabbePane and use the first tab to login. Proceed to the main tab if successful

LVL 92

Expert Comment

ID: 13890017
call dispose() after opening the new window

                  if (event.getSource() == buttonSubmit)
                    StudentRegister student1 = new StudentRegister() ;

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question