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

            }
        });

Where is your main method? The code lines 9 etc should be in main if you want them executed!

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

            }
        });

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

commented: "Your app in a pixel!" +12

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

doesn't the setVisible(true) method supposed to do something

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.

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>      

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.

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.

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

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

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

ok thnkz j

hi every 1

just want to say i got the interface to show the error I am experiencing is login. I use a db to login but am completely stuck. can someone explain this error. please thanks any help will be appreciated. I have created 2 classes. one is called the dbcon, and model class.

this is the login interface class codes

package ElectronicRole;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

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

    private boolean isLoginValid;

    public Login() {

        initComponents();
        this.isLoginValid = false;

    }
    public String getUserType(){// this method is being used to check the usertype, whether it is either the student or lecturer

        //this codes here is to check to see if it is the lecturer or the student

        int i = jBoxselect.getSelectedIndex();
        String UserType ="";
        if(i == 0){ // this is checking to see which user will be login 

            UserType = "STUDENT";
        }
        else
            if(i == 1){

                UserType =  "LECTURER";
            }
          return UserType;
    }
    public boolean validateLogin(){
      //this checking to see if the userid, password and usertype is valid or not

        Model model = new Model();
        HashMap <String, String > login = new HashMap<String, String>();   // values are pass to the ash map
        login.put("userid",txtuserid.getText());
        login.put("password", pass.getText());
        login.put("usertype", this.getUserType());
        return  model.isLoginValid(login);

    }
    // check to see if the login is valid or not and if it is, the user can login
    public boolean isLoginValid(){
        return this.isLoginValid;
    }

    @SuppressWarnings("unchecked")

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

    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {                                      
        this.isLoginValid = this.validateLogin();

    }                                     
    @Override
  public void actionPerformed(ActionEvent ae){
         if("Ok".equals(ae.getActionCommand())){
             Object src = ae.getSource();
             if(src.equals("Ok")){

             }
         }       
  }

  this is the dbcon class which supposed to connect to the db
  package ElectronicRole;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author luanataylor
 */
public class DBCon {

    public DBCon(){

    }

    public  Connection connect(){
        Connection con =null;
         try{

            //connecting to the db
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("dbc.sql://localhost:3306/electronicrole", "dbuser", "dbpass");

        }
        catch(Exception e){

            System.out.println(e);
        }
         return con;
    }
    public Statement statement(){
         Statement stmt=null;
        try {
            stmt = this.connect().createStatement();
        } catch (SQLException ex) {

        }

          return stmt;
    }

        public ResultSet executeQuery(String querystr) {

            ResultSet rs = null;

            try{
                 rs = this.statement().executeQuery(querystr);

            }
            catch(SQLException e){
                System.out.println(e);

            }
            return rs;
        }
 and this is the model class
 package ElectronicRole;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
/**
 *
 * @author luanataylor
 */
public class Model extends DBCon {

    ResultSet rs;

    public boolean isLoginValid(HashMap <String, String> login) {

        boolean valid = false;
         String querystr, table;

         //check for the usertype if it is equal to student when check for the login
        if( login.get("usertype").equals("STUDENT")){

            table = "students";
        }
        else{
            table  =  "lecturers";// it is not the students, it will be the lecturer
        }
        querystr = String.format("SELECT COUNT(StudentID) AS count FROM %s WHERE StudentID=\"%s\" AND Password=\"%s\"", table, login.get("userid"),login.get("password"));
        System.out.println(querystr); 
        try {

             this.rs =  this.executeQuery(querystr);
             rs.next();
             if(rs.getInt("count") > 0){
             valid = true;
        }
        }
             catch(SQLException e){

      }
        return valid;
  }

  }

when i run it this is the error i get

at ElectronicRole.DBCon.statement(DBCon.java:43)
    at ElectronicRole.DBCon.executeQuery(DBCon.java:58)
    at ElectronicRole.Model.isLoginValid(Model.java:37)
    at ElectronicRole.Login.validateLogin(Login.java:52)
    at ElectronicRole.Login.btnOKActionPerformed(Login.java:198)
    at ElectronicRole.Login.access$100(Login.java:16)
    at ElectronicRole.Login$2.actionPerformed(Login.java:106)

this is the main where the program run from

package ElectronicRole;

/**
 *
 * @author luanataylor
 */
public class AppMain {

      public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StudentHomePage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StudentHomePage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StudentHomePage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StudentHomePage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
             Login logscrn = new Login();
             logscrn.setVisible(true);

            while(!logscrn.isLoginValid()){

                //do nothing
            }
            if(logscrn.getUserType().equals("STUDENT")){
                StudentHomePage shp = new StudentHomePage();
                shp.setVisible(true);
            }
            else if( logscrn.getUserType().equals("LECTURER")){
             LecturerHomePage lhp = new LecturerHomePage();
             lhp.setVisible(true);
      }
            logscrn.setVisible(false);            

   }

      }

when i run it this is the error i get

You missed out the error message itself. All we see is the location where it happened - which is also useless because the line numbers don't match the way you pasted the code.

AND YOU HAVE AN EMPTY catch BLOCK!!!

where is the empty catch block

check your Model class

catch(SQLException e){
      }

and your DBCon class

  catch (SQLException ex) {
        }

stultuske, I wanna thank you I got it to work after working thru all the errors even the errors u mention

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.