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.


1 2 3 | JButton button = new JButton( "Okay" ); button.setActionCommand( "okay" ); button.addActionListener( this ); |
1 2 3 4 5 6 7 | public void actionPerformed(ActionEvent e) { if ( "okay" .equals(e.getActionCommand())) { // perform button action here } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | 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 ); } } |
1 2 3 4 5 6 7 8 9 | 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 ) |