/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * NewJDialog.java * * Created on Nov 27, 2013, 2:16:15 PM */ package com.server.gui; import com.server.conn.ClientManager; import com.server.conn.ConnectionManager; import com.server.utils.SettingsConstatnts; import java.util.ArrayList; import java.util.Enumeration; import javax.swing.JOptionPane; /** * * @author Administrator */ public class AlertUser extends javax.swing.JDialog { /** Creates new form NewJDialog */ public AlertUser(java.awt.Frame parent, boolean modal) { super(parent, modal); 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() { jLabel1 = new javax.swing.JLabel(); titleTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); contentTextArea = new javax.swing.JTextArea(); sendButton = new javax.swing.JButton(); closeButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Alert Users"); jLabel1.setText("Title :"); jLabel2.setText("Content :"); contentTextArea.setColumns(20); contentTextArea.setRows(5); jScrollPane1.setViewportView(contentTextArea); sendButton.setText("Send"); sendButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendButtonActionPerformed(evt); } }); closeButton.setText("Close"); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeButtonActionPerformed(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() .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(closeButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sendButton)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane1) .addComponent(titleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)))) .addContainerGap(30, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(22, 22, 22) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sendButton) .addComponent(closeButton)) .addContainerGap(13, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed // TODO add your handling code here: this.dispose(); }//GEN-LAST:event_closeButtonActionPerformed private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendButtonActionPerformed // TODO add your handling code here: String title = titleTextField.getText(); String content = contentTextArea.getText(); if (title.length() == 0) { JOptionPane.showMessageDialog(this, "Please provide a title", "No Title", JOptionPane.WARNING_MESSAGE); } else if (content.length() == 0) { JOptionPane.showMessageDialog(this, "Please provide a content", "No Content", JOptionPane.WARNING_MESSAGE); } else { // COde to Send Follows if (!ConnectionManager.connectedClients.isEmpty()) { Enumeration keys = ConnectionManager.connectedClients.keys(); while (keys.hasMoreElements()) { Object nextElement = keys.nextElement(); if (nextElement instanceof String) { System.out.println("nxt ellement" + nextElement); ClientManager client = (ClientManager) ConnectionManager.connectedClients.get(nextElement); client.sendRequestToClient("ALERT:" + title + "|" + content); } else { System.out.println(nextElement.getClass().getName()); } } this.dispose(); JOptionPane.showMessageDialog(this, "Alert has been send successfully", "Alert Info", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(this, "No Clinets Where Available", "No Clents", JOptionPane.OK_OPTION); } } }//GEN-LAST:event_sendButtonActionPerformed /** * @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(AlertUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(AlertUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(AlertUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(AlertUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { AlertUser dialog = new AlertUser(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton closeButton; private javax.swing.JTextArea contentTextArea; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton sendButton; private javax.swing.JTextField titleTextField; // End of variables declaration//GEN-END:variables }