Java tutorial
/* * 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 com.cch.aj.entryrecorder.frame; import com.cch.aj.entryrecorder.common.AppConfig; import com.cch.aj.entryrecorder.common.AppContext; import com.cch.aj.entryrecorder.common.AppHelper; import com.cch.aj.entryrecorder.common.ApplicationContextProvider; import javax.swing.JFrame; import javax.swing.JOptionPane; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; /** * * @author chacao */ @Component("HomeJFrame") public class HomeJFrame extends javax.swing.JFrame { /** * Creates new form HomeJFrame */ public HomeJFrame() { initComponents(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; btnShift = new javax.swing.JButton(); btnEntry = new javax.swing.JButton(); btnSettings = new javax.swing.JButton(); btnSearch = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setPreferredSize(new java.awt.Dimension(400, 500)); getContentPane().setLayout(new java.awt.GridBagLayout()); btnShift.setText("New Entry"); btnShift.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnShiftActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 9; gridBagConstraints.ipady = 9; gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 15); getContentPane().add(btnShift, gridBagConstraints); btnEntry.setText("Main Record"); btnEntry.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEntryActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 9; gridBagConstraints.ipady = 9; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 15); getContentPane().add(btnEntry, gridBagConstraints); btnSettings.setText("Settings"); btnSettings.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSettingsActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 9; gridBagConstraints.ipady = 9; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 15); getContentPane().add(btnSettings, gridBagConstraints); btnSearch.setText("Search"); btnSearch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSearchActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 9; gridBagConstraints.ipady = 9; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(15, 15, 15, 15); getContentPane().add(btnSearch, gridBagConstraints); jLabel1.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabel1.setText("Main Menu"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.insets = new java.awt.Insets(17, 0, 17, 0); getContentPane().add(jLabel1, gridBagConstraints); pack(); }// </editor-fold>//GEN-END:initComponents private void btnEntryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEntryActionPerformed MainJFrame mf = AppContext.getApplicationContext().getBean("MainJFrame", MainJFrame.class); mf.init(); mf.setVisible(true); }//GEN-LAST:event_btnEntryActionPerformed private void btnShiftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShiftActionPerformed EntryJFrame ef = AppContext.getApplicationContext().getBean("EntryJFrame", EntryJFrame.class); ef.setVisible(true); }//GEN-LAST:event_btnShiftActionPerformed private void btnSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSettingsActionPerformed String login = JOptionPane.showInputDialog(this, "Please enter 'UserName/Password'"); if (login != null && (login.equals("aj") || login.equals("admin/ajpro123"))) { SettingsJFrame sf = AppContext.getApplicationContext().getBean("SettingsJFrame", SettingsJFrame.class); sf.setVisible(true); } }//GEN-LAST:event_btnSettingsActionPerformed private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed SearchJFrame sf = AppContext.getApplicationContext().getBean("SearchJFrame", SearchJFrame.class); sf.setVisible(true); }//GEN-LAST:event_btnSearchActionPerformed /** * @param args the command line arguments */ 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(HomeJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(HomeJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(HomeJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(HomeJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> AppHelper.Logger.warn("###Start the Program###"); /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { AppContext.setApplicationContext(new AnnotationConfigApplicationContext(AppConfig.class)); HomeJFrame hf = new HomeJFrame(); hf.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnEntry; private javax.swing.JButton btnSearch; private javax.swing.JButton btnSettings; private javax.swing.JButton btnShift; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }