hi danpost
is there anyway possible that there are any source for an ok jbutton to work. have been trying to get a OK Jbutton to work but everything ah tried is not working.
JButton button = new JButton("Okay"); button.setActionCommand("okay"); button.addActionListener(this);
public void actionPerformed(ActionEvent e) { if ("okay".equals(e.getActionCommand())) { // perform button action here } }
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; } } here is the dbcon /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ElectronicRole; import java.sql.*; /** * * @author luanataylor */ public class DBCon { public Connection con; public Statement stmt; public DBCon(){ try{ //connecting to the db Class.forName("com.mysql.jdbc.Driver"); this.con = DriverManager.getConnection("dbc.sql://localhost:3306/electronic role", "dbuser", "dbpass"); this.stmt = con.createStatement(); } catch(Exception e){ System.out.println(e); } } public ResultSet executeQuery(String querystr) throws SQLException{ ResultSet rs = this.stmt.executeQuery(querystr); return rs; } } and there is the login 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 codes here is to check to see if it is the lecturer or the student int i = jBoxselect.getSelectedIndex(); String UserType =""; if(i == 0){ 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 public boolean isLoginValid(){ return this.isLoginValid; } } here is the appmain where the program will run from /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ElectronicRole; /** * * @author luanataylor */ public class AppMain { public static void main(String args[]) { } //</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); } }
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver SELECT COUNT (STUDENTID) AS count FROM students WHERE StudentID="null" AND Password="lt748" Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at ElectronicRole.DBCon.executeQuery(DBCon.java:35) at ElectronicRole.Model.isLoginValid(Model.java:37) at ElectronicRole.Login.validateLogin(Login.java:52) at ElectronicRole.Login.btnOKActionPerformed(Login.java:197) at ElectronicRole.Login.access$100(Login.java:16) at ElectronicRole.Login$2.actionPerformed(Login.java:110)