Here is the code of my HomePage.java file in which I have created the object of LoginPageService class to call its methods.
public class HomePage extends javax.swing.JFrame {
CardLayout cl;
private LoginPageService service;
/**
* Creates new form trial
*/
public HomePage() {
initComponents();
cl = (CardLayout) (jPanel6.getLayout());
service = new LoginPageService();
JTable jTable = service.getScheduledLectureList(jTable1, ScheduleLecture.class);
jTable.setRowHeight(45);
jTable.getColumnModel().getColumn(0).setPreferredWidth(1);
JTableHeader tableHeader = jTable.getTableHeader();
tableHeader.setBackground(new java.awt.Color(119, 124, 168));
tableHeader.setForeground(Color.black);
Font headerFont = new Font("Verdana", Font.PLAIN, 19);
tableHeader.setFont(headerFont);
}
private void jLabel26MouseClicked(java.awt.event.MouseEvent evt) {
service = new LoginPageService();
String id = getId1().getText();
char ch[] = getPassword1().getPassword();
String password = new String(ch);
String value = (String) jComboBox2.getSelectedItem();
Boolean result = service.checkCredential(id, password, value);
if (result == true) {
JOptionPane.showMessageDialog(this, "Welcome " + id);
if ("Student".equals(value)) {
new SignInAsStudent().setVisible(true);
dispose();
}
if ("Instructor".equals(value)) {
new main.java.com.lecture_backup.view.SignInAsInstructor().setVisible(true);
dispose();
}
} else {
JOptionPane.showMessageDialog(this, "Invalid Id or Password");
getPassword1().setText("");
getId1().setText("");
}
}
}
this is the code of LoginPageService:
public class LoginPageService {
private HomePage hm;
public LoginPageService(){
hm = new HomePage();
}
public JTable getScheduledLectureList(JTable jTable1, Class sdl) {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Date date = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
hm.getPassword1().setText("");
hm.getjLabel13().setText("" + df.format(date));
Criteria crit1 = session.createCriteria(sdl);
Criteria crit = session.createCriteria(ScheduleLecture.class);
crit.add(Restrictions.ge("date", df.format(date)));
List<ScheduleLecture> data = crit.list();
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
dtm.setRowCount(0);
for (ScheduleLecture sl : data) {
Object obj[] = {sl.getSerialNo(), sl.getSubject(), sl.getTopic(), sl.getName(), sl.getDate(), sl.getTime()};
dtm.addRow(obj);
}
return jTable1;
}
Can you please tell me is this the right way to declare the reference object first private variable, then instantiate it in the respective methods to call the methods of LoginPageService class?
I have added the code of both the files. can someone tell me now where s the problem. Why after running the code it is not directing me to HomePage.