Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:10:12+00:00 2026-06-04T08:10:12+00:00

First post for me. I’m a student in my first year of a comp

  • 0

First post for me. I’m a student in my first year of a comp science degree.

I was just building a basic GUI for an assignment and for some reason, which I cannot see for the life of me, one of the JFrames I have created, an instance of the Register Class displays completely blank when it is called from the Register buttons action listener in the Login Class…

I also have an individual main Class which contains the Main method and calls the Login Class. The Login Class JFrame works fine and as mentioned, the issues only occur with the Registration Class when it is called within the Login Class’ Register button action listener. All other JFrames in the program work fine too.

I have attempted to call the Register Class direct from the main and it has the same issues, although I have attempted to reduce it to its most basic form and it still does not display anything aside from a blank uncolored JFrame.

Here is the code (Unfinished but working as is). I apologise for my sloppyness but I am a complete beginner.

Can anyone see what is wrong with it?

Thanks in advance!

    package guitest;

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;

    public class Register extends JFrame{

        JButton regSubmit = new JButton("Submit");

        JTextField email = new JTextField();
        JTextField name = new JTextField();
        JTextField Address1 = new JTextField();
        JTextField Address2 = new JTextField();

        JPasswordField password1 = new JPasswordField();
        JPasswordField password2 = new JPasswordField();

        String nameTxt = email.getText();
        String passTxt = password1.getText();
        String info = "";

        FlowLayout layout1 = new FlowLayout();    

        public void Reg(){
            this.setTitle("La Volpe Registration");
            this.setLayout(layout1);    
            this.add(Address1);
            this.add(Address2);
            this.add(email);
            this.add(password1);
            this.add(password2);
            this.add(name);
            this.add(regSubmit);
            this.getContentPane().setBackground(Color.green);
            this.setSize(370, 160);

            regSubmit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    regSubmitActionPerformed(evt);
                }

                private void regSubmitActionPerformed(java.awt.event.ActionEvent evt) { 

                String name = email.getText();
                String pass = password1.getText();
                String info = "";

                System.out.println("registering...");

                boolean eof;

                try{
                    // Create file
                    FileWriter file = new FileWriter("\\regdata.txt");
                    BufferedWriter out = new BufferedWriter(file);
                    out.write("\n"+nameTxt+", "+passTxt);
                }

                catch (Exception e){
                }   
            }   
        });
        this.setVisible(true);
    }    
}

And the class that links to it…


package guitest;

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;

    /**
    * @author david
    */

    public class Login {

    JFrame loginFrame = new JFrame();
    Register reg3 = new Register();

    JButton submit = new JButton("Submit");
    JButton clear = new JButton("Clear");
    JButton register = new JButton ("Register with Us");

    JPasswordField pass = new JPasswordField(20);
    JTextField email = new JTextField(20);
    JLabel em = new JLabel("Email Address: ");
    JLabel pw = new JLabel("Password: ");

    String pathname;
    String line;
    String [] records = new String [1000];
    int count = 0;

    FlowLayout layout1 = new FlowLayout();

        public Login(){

            //Adds Email label and text field
            loginFrame.add(em);
            loginFrame.add(email);

            //Adds password label and field
            loginFrame.add(pw);
            loginFrame.add(pass);

            //Adds buttons
            loginFrame.add(submit);
            loginFrame.add(clear);
            loginFrame.add(register);

            loginFrame.getContentPane().setBackground(Color.green);

            loginFrame.setLayout(layout1);

            loginFrame.setSize(370, 160);

            loginFrame.setTitle("La Volpe - Login");

            submit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    submitActionPerformed(evt);    
                }            

                private void submitActionPerformed(java.awt.event.ActionEvent evt){                                         
                String emailadd = email.getText();
                String password = pass.getText();
                pathname = "\\regdata.txt";

                boolean eof;

                try{
                    FileReader file = new FileReader(pathname);
                    BufferedReader buff = new BufferedReader(file);

                    eof = false; // set the eof boolean to false

                        while (!eof){
                        line = buff.readLine();
                        if (line == null){ // test to see if the end of file has been reached
                        eof = true;  // if the end of file has been found set the eof Boolean to true
                        }
                        else{ 
                        // end of file not reached so move the contents of the line to the records
                        //array
                        records[count] = line;
                        count ++;
                        System.out.println(line);  // print out the new line input for error checking
                        }
                    }    
                    buff.close();
                }
                catch (IOException e){
                    System.out.println("Error --  "+ e.toString());
                }

                boolean notTrue = false;

                for (int i = 0; i < count; i++) {       
                    if ((!notTrue)&&((emailadd + "," + password).equals(records[i]))) {
                        FoodSelectionMain loggedIn = new FoodSelectionMain();
                        loggedIn.setVisible(true);
                    } 
                }
                if (!notTrue){
                    JOptionPane.showInputDialog("Please check your login "
                    + "and try again. If you are a new user, please "
                    + "register by pressing the 'REGISTER' button");
                }
            }   

        }); 

        // TODO add your handling code here:


        clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearActionPerformed(evt);
            }

            public void clearActionPerformed(java.awt.event.ActionEvent evt){
                email.setText(null);
                pass.setText(null);
            }

        }); 
        register.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registerActionPerformed(evt);
            }

            public void registerActionPerformed(java.awt.event.ActionEvent evt){
                reg3.setVisible(true);
                    System.out.println("Register pressed");
            }
        });
        loginFrame.setVisible(true);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:10:14+00:00Added an answer on June 4, 2026 at 8:10 am

    Try this,
    in Register class, correct the constructor name to Register() from Reg().

    Keep these few Guidelines in your mind before constructing a gui app

    1. Create an object of the subclass of the container .

    2. Consider all the components which goes in the container as instance variables.

    3. Set these instance variable and event handling outside the constructor in methods, (ie setComponent(), setHandler().etc) but do these method invocations from constructor.

    4. Now in main use this…

    .

    EventQueue.invokeLater(new Runnable() {
    
        public void run() {
            Myframe f = new Myframe();
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post on the site! I'm looking for some help inserting tr elements mid-way
first post here on stack overflow, hoping to get some advice on how to
first post, so play nice! I have a fairly basic question about Python dictionaries.
first post here, hoping someone could perhaps shed some light on an issue I've
first post ever in any forum with regard to programming... i usually just search
This is my first post and I have am concerned that some might think
this is my first post so please show some understanding. I have some java
This is my first post here and I wanted to get some input from
First post so hi! (please correct me if I use some term wrong) I've
My first post on Stackoverflow! I am having some problems with a WCF service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.