private void resetButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_resetButtonActionPerformed // TODO add your handling code here: String input = new String(passwordField.getPassword()); if (pM.checkParentPassword(input)) { try { int n = JOptionPane.showConfirmDialog( this, "Would you like to reset every setting of the game?", "Warning", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { session.logout(); FileUtils.deleteDirectory(manager.getDirectory()); resposeLabel.setText("Successful."); // change the logout button visibility in the main frame MainFrame frame = (MainFrame) javax.swing.SwingUtilities.getWindowAncestor(this); frame.logoutButton.setVisible(false); controller.goToInitialSetup(); } } catch (IOException ex) { resposeLabel.setText("Error!"); Logger.getLogger(ResetGamePanel.class.getName()).log(Level.SEVERE, null, ex); } } else { resposeLabel.setText("Wrong password! Try again."); } } // GEN-LAST:event_resetButtonActionPerformed
/** * Creates new form <code>ResetGamePanel</code> This panel resets all settings for the game as well * as delete any custom questions and pictures * * @author baris & david c */ public class ResetGamePanel extends javax.swing.JPanel { ParentManager pM = UserDatabaseFactory.aParentManager(); private FileManager manager = FileManagerImpl.getInstance(); private PanelController controller = PanelController.getInstance(); private Session session = Session.aSession(); /** * Creates new form ResetGamePanel This panel resets all settings for the game as well as delete * any custom questions and pictures */ public ResetGamePanel() { initComponents(); } /** * 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() { passwordField = new javax.swing.JPasswordField(); warningLabel = new javax.swing.JLabel(); resetButton = new javax.swing.JButton(); resposeLabel = new javax.swing.JLabel(); enterLabel = new javax.swing.JLabel(); setBounds(new java.awt.Rectangle(0, 0, 380, 370)); setMaximumSize(new java.awt.Dimension(311, 300)); setMinimumSize(new java.awt.Dimension(300, 300)); setOpaque(false); passwordField.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N passwordField.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { passwordFieldActionPerformed(evt); } }); warningLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N warningLabel.setForeground(new java.awt.Color(255, 255, 255)); warningLabel.setText("This will reset to the initial setup of the game."); warningLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); resetButton.setText("Reset"); resetButton.setBounds(new java.awt.Rectangle(0, 0, 380, 370)); resetButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resetButtonActionPerformed(evt); } }); resposeLabel.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N resposeLabel.setForeground(new java.awt.Color(255, 0, 51)); enterLabel.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 18)); // NOI18N enterLabel.setForeground(new java.awt.Color(255, 255, 255)); enterLabel.setText("Enter password"); enterLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add( layout .createSequentialGroup() .add( layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup().add(94, 94, 94).add(resetButton)) .add(layout.createSequentialGroup().add(54, 54, 54).add(resposeLabel)) .add( layout .createSequentialGroup() .add(46, 46, 46) .add( passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 171, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(layout.createSequentialGroup().add(60, 60, 60).add(enterLabel)) .add(layout.createSequentialGroup().add(30, 30, 30).add(warningLabel))) .addContainerGap(189, Short.MAX_VALUE))); layout.setVerticalGroup( layout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add( org.jdesktop.layout.GroupLayout.TRAILING, layout .createSequentialGroup() .addContainerGap(129, Short.MAX_VALUE) .add(enterLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add( passwordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(resetButton) .add(10, 10, 10) .add(warningLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(resposeLabel) .add(110, 110, 110))); } // </editor-fold>//GEN-END:initComponents private void passwordFieldActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_passwordFieldActionPerformed // TODO add your handling code here: } // GEN-LAST:event_passwordFieldActionPerformed private void resetButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_resetButtonActionPerformed // TODO add your handling code here: String input = new String(passwordField.getPassword()); if (pM.checkParentPassword(input)) { try { int n = JOptionPane.showConfirmDialog( this, "Would you like to reset every setting of the game?", "Warning", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { session.logout(); FileUtils.deleteDirectory(manager.getDirectory()); resposeLabel.setText("Successful."); // change the logout button visibility in the main frame MainFrame frame = (MainFrame) javax.swing.SwingUtilities.getWindowAncestor(this); frame.logoutButton.setVisible(false); controller.goToInitialSetup(); } } catch (IOException ex) { resposeLabel.setText("Error!"); Logger.getLogger(ResetGamePanel.class.getName()).log(Level.SEVERE, null, ex); } } else { resposeLabel.setText("Wrong password! Try again."); } } // GEN-LAST:event_resetButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel enterLabel; private javax.swing.JPasswordField passwordField; private javax.swing.JButton resetButton; private javax.swing.JLabel resposeLabel; private javax.swing.JLabel warningLabel; // End of variables declaration//GEN-END:variables }