0

hi pple

I am building this electronic role using an interface. during the course of designing the interface, tried running it just to see the look and feel of it and it is not showing can someone tell me why this happen. here is the code. havent start coding it yet

package AttendanceRecordSystem;

public class AttendanceRegistrationForm extends javax.swing.JFrame {

    public AttendanceRegistrationForm() {

        initComponents();
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new AttendanceRegistrationForm().setVisible(true);

            }
        });
2
Contributors
13
Replies
62
Views
1 Week
Discussion Span
Last Post by divinity02
Featured Replies
  • What about `initComponents`? You need to have at least one control in the JFrame to get something worth seeing (unless you are using absolute sizing...) ps: You are probably getting a visible JFrame thats just a few pixels big hiding at the very top left of your screen Read More

0

hi j
i put it in the main method and still getting the same result

  public static void main(String args[]) {

         java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new AttendanceRegistrationForm().setVisible(true);

            }
        });
1

What about initComponents? You need to have at least one control in the JFrame to get something worth seeing (unless you are using absolute sizing...)

ps: You are probably getting a visible JFrame thats just a few pixels big hiding at the very top left of your screen

Edited by JamesCherrill

Votes + Comments
"Your app in a pixel!"
0

hi j

there is the initComponents right after public AttendanceRegistrationForm() isnt that supposed to do something.

package AttendanceRecordSystem;
public class AttendanceRegistrationForm extends javax.swing.JFrame {
    public AttendanceRegistrationForm() {
        initComponents();
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new AttendanceRegistrationForm().setVisible(true);
            }
        });
0

You haven't shown us your initComponents, so nobody has any idea what may be in it.

setVisible does what it is supposed to. The question is what did you have for it to set visible? My money's still on it displaying a tiny empty frame at the TLS of the screen where nobody will notice it.

0

is dis wah yuh asking 4

 private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbllectlogin = new javax.swing.JLabel();
        lblLecID = new javax.swing.JLabel();
        jtxtlect = new javax.swing.JTextField();
        lblpwd = new javax.swing.JLabel();
        lbljpwd = new javax.swing.JPasswordField();
        jbtnsubmit = new javax.swing.JButton();
        lblstd = new javax.swing.JLabel();
        lblstdnum = new javax.swing.JLabel();
        jtxtstd = new javax.swing.JTextField();
        jlblpwd = new javax.swing.JLabel();
        jpwd = new javax.swing.JPasswordField();
        submitjbtn = new javax.swing.JButton();
        jbtnexit = new javax.swing.JButton();
        jbtnNext = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setMinimumSize(new java.awt.Dimension(950, 980));
        jPanel1.setPreferredSize(new java.awt.Dimension(1095, 990));

        jLabel1.setFont(new java.awt.Font("Cambria", 3, 18)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Attendance Tracker");

        lbllectlogin.setFont(new java.awt.Font("Cambria", 3, 14)); // NOI18N
        lbllectlogin.setText("Lecturer Login");

        lblLecID.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        lblLecID.setText("Lecturer ID");

        jtxtlect.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N

        lblpwd.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        lblpwd.setText("Password");

        lbljpwd.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N

        jbtnsubmit.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jbtnsubmit.setText("Submit");

        lblstd.setFont(new java.awt.Font("Cambria", 3, 14)); // NOI18N
        lblstd.setText("Student Login");

        lblstdnum.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        lblstdnum.setText("Student ID");

        jtxtstd.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N

        jlblpwd.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jlblpwd.setText("Password");

        jpwd.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N

        submitjbtn.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        submitjbtn.setText("Submit");

        jbtnexit.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jbtnexit.setText("Exit");
        jbtnexit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnexitActionPerformed(evt);
            }
        });

        jbtnNext.setFont(new java.awt.Font("Cambria", 3, 12)); // NOI18N
        jbtnNext.setText("Next");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(240, 240, 240)
                        .addComponent(submitjbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jbtnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(325, 325, 325)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblstd, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlblpwd, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblstdnum, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(49, 49, 49)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtxtstd)
                                    .addComponent(jpwd, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(245, 245, 245)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbllectlogin, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(lblLecID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lblpwd, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jbtnsubmit, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
                                .addGap(36, 36, 36)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtxtlect, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                                    .addComponent(lbljpwd))))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(lbllectlogin)
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLecID)
                    .addComponent(jtxtlect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblpwd)
                    .addComponent(lbljpwd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addComponent(jbtnsubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(lblstd)
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtstd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblstdnum))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jpwd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblpwd))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(submitjbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 632, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>      
0

I can't see any obvious problems with the various bits and pieces that you have posted, but without the whole code I can't test it here.
Maybe you can reduce all that to a smaller simpler stand-alone runnable version - maybe just delete all the components except for one JLabel - that we can download and run to see the problem ourselves.

0
package ElectronicRole;

public class Login extends javax.swing.JFrame {

    public Login() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Login().setVisible(true);
            }
        });
    }

hey james

I have decided to do over the whole thing and in the new one, I am still experiencing the same problem.

0

That class has no main method! (Which may be good thing, since if you did try to create a new Login then that constructor calls initComponents - which schedules another new Logon, that calls initComponents... until you run out of memory.)

Your constructor needs to add all the components to the frame, and your main needs to create a new instance of the frame. I've rearranged your test code into a correct structure like this:

class Login extends javax.swing.JFrame {

    public Login() {
        // create a new frame by adding all the components and 
        // then displaying it in the center of the screen
        initComponents();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private void initComponents() { 
        // all the tedious generated code to build the
        // frame's contents goes here (and nothing else!)
        add(new JLabel("Hello"));
        pack();
    }

    public static void main(String[] args) {
        // Create a new instance of the form on the Swing thread
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Login();
            }
        });
        // or, using the current version of Java...
        // java.awt.EventQueue.invokeLater(Login::new);
    }
}

Edited by JamesCherrill

0

hi james
I delete the whole program (the attendance record system) and rename it an Electronic Role and I have got the gui interface to show when i run it.

what I would like to do now is to get to go from one interface to another. something like, when I login using the login form, it should go to the student homepage (depends if it is the student) or if it is the lecture, it should go to the lecturer home page, trying something but when i run it both the login form and the student homepage came up at the same time. is there a way to do it. tell me where I have made the error

This is the login form below

package ElectronicRole;

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

public class Login extends javax.swing.JFrame implements ActionListener {

    public Login() {

        initComponents();

    }
    private void jbtnCancelActionPerformed(java.awt.event.ActionEvent evt) {                                           
       this.dispose();
    }                                          
private JButton btnOk;
    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {                                      

    }   
     java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Login().setVisible(true);
               new StudentHomePage().setVisible(true);                
}
        });
}

and this is the student homepage

package ElectronicRole;

import javax.swing.*;

public class StudentHomePage extends javax.swing.JFrame {

    public StudentHomePage() {
        initComponents();

    }
    private JFrame frame;
    private void jbtnexitActionPerformed(java.awt.event.ActionEvent evt) {                                         
          frame = new JFrame("Exit");
       if(JOptionPane.showConfirmDialog(frame,"Confirm if yuh wish to exit", "Clear TextField System",
               JOptionPane.YES_NO_OPTION)== JOptionPane.YES_NO_OPTION ){
                 System.exit(0);

    }                                        
    }
    private void jtxtgetstdinfoActionPerformed(java.awt.event.ActionEvent evt) {                                               
        JTextField jtxtgetstdinfo = new JTextField("get student info");
        jtxtgetstdinfo.getText();

    }                                              

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

    }    
     public static void main(String args[]) {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new StudentHomePage().setVisible(true);

                new Login().setVisible(false);
            }
        });
    }
0

new StudentHomePage().setVisible(true);

You want that to run when the user hits enter in the logon screen? So it should be in the actionPerformed for the Logon OK button (and nowhere else).

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.