My alarm program needs to reset all the content inside the "Status" box and "Alarm countdown" box, as well as re-enable the two disarm buttons.
The "Check Alarm Status" button can reset everything.
I have attached the Netbeans project, called Call.zip, in case it is needed.
Anyway help would be appreciated :-)

Call.java:
/*
* This is the Call class.
*
* Timer code from http://www.ehow.com/how_8675868_countdown-tutorial-java.html
*
*/
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JOptionPane;
import java.util.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rith
*/
public class Call extends javax.swing.JFrame {
/**
* Creates new form Call
*/
public Call() {
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() {
checkAlarmStatus = new javax.swing.JButton();
statusOfAlarmText = new javax.swing.JTextField();
statusOfAlarmLabel = new javax.swing.JLabel();
statusLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
statusText = new javax.swing.JTextArea();
countdownLabel = new javax.swing.JLabel();
countdownText = new javax.swing.JTextField();
disarmStructuredOccupantsButton = new javax.swing.JButton();
disarmCallCenterButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("MAS alarm status");
checkAlarmStatus.setText("Check Alarm Status");
checkAlarmStatus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkAlarmStatusActionPerformed(evt);
}
});
statusOfAlarmLabel.setText("Enter status of the alarms? (0 = healthy / 1 = not healthy):");
statusLabel.setText("Status:");
statusText.setColumns(20);
statusText.setEditable(false);
statusText.setRows(5);
jScrollPane1.setViewportView(statusText);
countdownLabel.setText("Alarm Countdown:");
countdownText.setEditable(false);
disarmStructuredOccupantsButton.setText("Structured Occupants Disarm");
disarmStructuredOccupantsButton.setToolTipText("");
disarmStructuredOccupantsButton.setEnabled(false);
disarmStructuredOccupantsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
disarmStructuredOccupantsButtonActionPerformed(evt);
}
});
disarmCallCenterButton.setText("Call Center Disarm");
disarmCallCenterButton.setToolTipText("");
disarmCallCenterButton.setEnabled(false);
disarmCallCenterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
disarmCallCenterButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(statusLabel)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(statusOfAlarmLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusOfAlarmText, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(checkAlarmStatus)
.addGroup(layout.createSequentialGroup()
.addComponent(countdownLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(77, 77, 77))
.addComponent(disarmStructuredOccupantsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(countdownText, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(disarmCallCenterButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(54, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusOfAlarmLabel)
.addComponent(statusOfAlarmText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkAlarmStatus))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusLabel)
.addComponent(countdownLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(countdownText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(disarmStructuredOccupantsButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(disarmCallCenterButton)))
.addContainerGap(22, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void checkAlarmStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkAlarmStatusActionPerformed
//declared variable
int alarm;
//begin try and catch
try {
//get the number entered by the end-user and assign it to the variable
//called 'alarm'
alarm = Integer.parseInt(statusOfAlarmText.getText());
//begin if else
//to determine the health of the alarm system
if (alarm == 0) {
statusText.setText(String.valueOf("The alarms are healthy."));
} else if (alarm == 1) {
statusText.setText(String.valueOf("The alarms are not healthly!\n"
+ "Calling structured occupant and remote call center...\n"));
//if the alarm is not healthy, the buttons to disable the alarms
//will become clickable
disarmStructuredOccupantsButton.setEnabled(true);
disarmCallCenterButton.setEnabled(true);
//start the countdown since alarm is not healthy
setTimer();
} //end if else
else {
JOptionPane.showMessageDialog(this, "Must be a 0 or 1!",
"Error", JOptionPane.ERROR_MESSAGE);
}
} //end try
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Not a number. Try again.",
"Error", JOptionPane.ERROR_MESSAGE);
} //end catch
}//GEN-LAST:event_checkAlarmStatusActionPerformed
private void disarmStructuredOccupantsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disarmStructuredOccupantsButtonActionPerformed
//disable the Call Center disarm button when pressed
disarmCallCenterButton.setEnabled(false);
//will display the message in this method
callStructuredOccupant();
}//GEN-LAST:event_disarmStructuredOccupantsButtonActionPerformed
private void disarmCallCenterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disarmCallCenterButtonActionPerformed
//disable the Strucutured Occupants disarm button when pressed
disarmStructuredOccupantsButton.setEnabled(false);
//will display the message in this method
callCallCenter();
}//GEN-LAST:event_disarmCallCenterButtonActionPerformed
//this method is a counter than starts at 60 and counts down to 0
Timer timer;
public void setTimer() {
//start timer to attempt to call for 60 seconds
timer = new Timer();
timer.schedule(new DisplayCountdown(), 0, 100);
} //end setTimer method
//this displays the countdown in seconds
class DisplayCountdown extends TimerTask {
int seconds = 60;
public void run() {
if (seconds > 0) {
countdownText.setText(seconds + " seconds remaining");
seconds--;
} else{
countdownText.setText("Countdown finished");
//when countdown reaches 0, the police and fire department will
//be contacted and the buttons to disarm will be disabled
callPoliceFireDept();
disarmStructuredOccupantsButton.setEnabled(false);
disarmCallCenterButton.setEnabled(false);
}
}
} //end DisplayCountdown method
public void callPoliceFireDept() {
statusText.setText(String.valueOf("Police and Fire department contacted."));
} //end callPoliceFireDept method
public void callStructuredOccupant(){
statusText.setText(String.valueOf("Structured Occupants disabled alarm."));
} //end callStructuredOccupant method
public void callCallCenter(){
statusText.setText(String.valueOf("Call center disabled alarm."));
} //end callCallCenter method
/**
* @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(Call.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Call.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Call.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Call.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Call().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton checkAlarmStatus;
private javax.swing.JLabel countdownLabel;
private javax.swing.JTextField countdownText;
private javax.swing.JButton disarmCallCenterButton;
private javax.swing.JButton disarmStructuredOccupantsButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel statusLabel;
private javax.swing.JLabel statusOfAlarmLabel;
private javax.swing.JTextField statusOfAlarmText;
private javax.swing.JTextArea statusText;
// End of variables declaration//GEN-END:variables
} //end Call class
Main.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rith
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//create a new constructor called 'form'
Call form = new Call();
//used to display the GUI
form.setVisible(true);
}
}
Attached File(s)
-
Call.zip (27.68K)
Number of downloads: 6

New Topic/Question
Reply




MultiQuote





|