Wednesday 18 March 2015

Security Alarm System for Home

Structure of the Problem Requirements 

This is the simple basic level project for beginners. The Security alarm system companies basically follow this basic rule to develop high level business security alarms. The Program is applicable for police security alarm, earthquake security alarm, and fire alarm. 

Source Code  

package Alarm;

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Toolkit;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author UzairYousafZai
 */
public class Alarm extends javax.swing.JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;

public Alarm() {
initComponents();
}

private void initComponents() {

p = new javax.swing.JPanel();
police = new javax.swing.JButton();
fire = new javax.swing.JButton();
earth = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

p.setBackground(new java.awt.Color(0, 204, 204));

//police.setIcon(new javax.swing.ImageIcon(getClass().getResource("images.png"))); // NOI18N
police.setText("Police");
police.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
policeActionPerformed(evt);
}
});

//fire.setIcon(new javax.swing.ImageIcon(getClass().getResource("images.png"))); // NOI18N
fire.setText("Fire Alarm");
fire.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fireActionPerformed(evt);
}
});

//earth.setIcon(new javax.swing.ImageIcon(getClass().getResource("images.png"))); // NOI18N
earth.setText("Earthquake");
earth.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
earthActionPerformed(evt);
}
});

javax.swing.GroupLayout pLayout = new javax.swing.GroupLayout(p);
p.setLayout(pLayout);
pLayout.setHorizontalGroup(
pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pLayout.createSequentialGroup()
.addContainerGap()
.addComponent(police)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fire)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(earth)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pLayout.setVerticalGroup(
pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pLayout.createSequentialGroup()
.addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(fire)
.addComponent(earth)
.addComponent(police, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

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()
.addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void policeActionPerformed(java.awt.event.ActionEvent evt) {
police.setEnabled(false);
fire.setEnabled(true);
earth.setEnabled(true);


playSound();

sendMessage("Message send to Police");

}

private void fireActionPerformed(java.awt.event.ActionEvent evt) {
police.setEnabled(true);
fire.setEnabled(false);
earth.setEnabled(true);

playSound();

sendMessage("Message send to Fire Station");

}

private void earthActionPerformed(java.awt.event.ActionEvent evt) {
police.setEnabled(true);
fire.setEnabled(true);
earth.setEnabled(false);

playSound();

sendMessage("Message send to Everyone");

}

public static void main(String args[]) {
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(Alarm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Alarm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Alarm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Alarm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Alarm().setVisible(true);
}
});
}

private javax.swing.JButton earth;
private javax.swing.JButton fire;
private javax.swing.JPanel p;
private javax.swing.JButton police;

private void playSound() {

for (int i=0;i<10;i++){
final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
if (runnable != null) runnable.run();
try {
Thread.sleep(1000); //1000 milliseconds is one second.
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}

}
private void sendMessage(String message) {
JFrame frame=null;
JOptionPane.showMessageDialog(frame,message,"Message",JOptionPane.INFORMATION_MESSAGE);
}
}

Output of the Program

 security alarm system for police

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment