rtmonitor.java
来自「multiplataform real time Linux monitor」· Java 代码 · 共 674 行 · 第 1/3 页
JAVA
674 行
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(layout.createSequentialGroup() .add(fraTiempo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(fraTemp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(fraServidor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(fraDisco, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnSalir, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 38, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(btnDesconectar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(fraActualizacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(22, 22, 22)) ); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-522)/2, (screenSize.height-576)/2, 522, 576); }// </editor-fold>//GEN-END:initComponents private void formWindowDeactivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeactivated }//GEN-LAST:event_formWindowDeactivated private void btnEstablecerTiempoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEstablecerTiempoActionPerformed int tiempo; if(verificarTiempo(txtTiempo)==true) { tiempo=Integer.parseInt(txtTiempo.getText())*1000; timer.setDelay(tiempo); } }//GEN-LAST:event_btnEstablecerTiempoActionPerformed private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated lblServidor.setText("Servidor: " + conexion.getDireccion()); lblPuerto.setText("Puerto: " + conexion.getPuerto()); }//GEN-LAST:event_formWindowActivated private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing timer.stop(); //Cerrar la conexion try{ conexion.cerrarConexion(); } catch (IOException e) {;} }//GEN-LAST:event_formWindowClosing private void btnDesconectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDesconectarActionPerformed timer.stop(); //Cerrar la conexion try{ conexion.cerrarConexion(); } catch (IOException e) {;} this.setVisible(false); principal.setVisible(true); }//GEN-LAST:event_btnDesconectarActionPerformed private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed timer.stop(); //Cerrar la conexion try{ conexion.cerrarConexion(); } catch (IOException e) {;} System.exit(0); }//GEN-LAST:event_btnSalirActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JProgressBar barMicro; private javax.swing.JButton btnDesconectar; private javax.swing.JButton btnEstablecerTiempo; private javax.swing.JButton btnSalir; private javax.swing.JPanel fraActualizacion; private javax.swing.JPanel fraDisco; private javax.swing.JPanel fraIntercambio; private javax.swing.JPanel fraMemoriaFisica; private javax.swing.JPanel fraMicro; private javax.swing.JPanel fraServidor; private javax.swing.JPanel fraTemp; private javax.swing.JPanel fraTiempo; private javax.swing.JLabel jLabel2; private javax.swing.JLabel lblDiscoHome; private javax.swing.JLabel lblDiscoRaiz; private javax.swing.JLabel lblEstadoCorreo; private javax.swing.JLabel lblEstadoFTP; private javax.swing.JLabel lblEstadoSSH; private javax.swing.JLabel lblEstadoSamba; private javax.swing.JLabel lblEstadoWeb; private javax.swing.JLabel lblFecha; private javax.swing.JLabel lblHora; private javax.swing.JLabel lblIntercambioLibre; private javax.swing.JLabel lblIntercambioUsado; private javax.swing.JLabel lblMemoriaBuffer; private javax.swing.JLabel lblMemoriaLibre; private javax.swing.JLabel lblMemoriaUsada; private javax.swing.JLabel lblMicro; private javax.swing.JLabel lblPuerto; private javax.swing.JLabel lblServidor; private javax.swing.JLabel lblTempCPU; private javax.swing.JLabel lblTempHD; private javax.swing.JLabel lblTempSistema; private javax.swing.JLabel lblTiempoServicio; private javax.swing.JTextField txtTiempo; // End of variables declaration//GEN-END:variables /** SubClase TimerListener que hace las veces de temporizador */ class TimerListener implements ActionListener { public void actionPerformed(ActionEvent evt) { //Aca va el codigo que se repite en cada intervalo del Timer recuperarDatos(); } } /** Verifica que el tiempo sea un valor numerico razonable */ private boolean verificarTiempo (JTextField Texto) { //Verificar que Texto sea numerico positivo y no excesivo int valor; if(Texto.getText().length()>0) { try { valor = Integer.parseInt(Texto.getText()); if(valor<=0) { JOptionPane.showMessageDialog(this, "Ingrese un valor mayor a cero."); Texto.setText(null); } else { if(valor>300) { JOptionPane.showMessageDialog(this, "Ingrese un valor menor a 300."); Texto.setText(null); } else return true; } } catch(NumberFormatException e) { Texto.setText(null); } } JOptionPane.showMessageDialog(this, "Debe ingresar un valor numérico."); Texto.setText(String.valueOf(timer.getDelay()/1000)); return false; } public void recuperarDatos() { //Recibe los objetos desde la conexion try { ut.recibirObjeto(conexion); micro.recibirObjeto(conexion); mem.recibirObjeto(conexion); swap.recibirObjeto(conexion); hora.recibirObjeto(conexion); //Hace que la lectura del servidor se realice cada 3 intervalos de tiempo //debido a que son procesos poco variantes if(cuenta3==3) { fecha.recibirObjeto(conexion); temp.recibirObjeto(conexion); disc.recibirObjeto(conexion); } cuenta3--; if(cuenta3==0) cuenta3=3; //Hace que la lectura del servidor se realice cada 5 intervalos de tiempo //debido a que es un proceso lento if(cuenta5==5) serv.recibirObjeto(conexion); cuenta5--; if(cuenta5==0) cuenta5=5; } catch (IOException e) { JOptionPane.showMessageDialog(this,"Error en la conexión. Se desconectará del servidor."); timer.stop(); //Cerrar la conexion try{ conexion.cerrarConexion(); } catch (IOException e1) {;} this.setVisible(false); principal.setVisible(true); return; } //Rellena las etiquetas con la informacion obtenida lblFecha.setText(fecha.toString()); lblHora.setText(hora.toString()); lblTiempoServicio.setText(ut.toString()); lblMicro.setText(micro.toString()); barMicro.setValue(micro.getUsoTotal()); barMicro.setStringPainted(true); barMicro.setString("Uso Total: " + String.valueOf(micro.getUsoTotal())+"%"); lblMemoriaUsada.setText(mem.getUsada() + " MB Usados"); lblMemoriaLibre.setText(mem.getLibre() + " MB Libres"); lblMemoriaBuffer.setText(mem.getBuffer() + " MB en Buffer"); lblIntercambioUsado.setText(swap.getUsada() + " MB Usados"); lblIntercambioLibre.setText(swap.getLibre() + " MB Libres"); lblTempCPU.setText("CPU: " + temp.getCPU() + "ºC"); lblTempSistema.setText("Sistema: " + temp.getSistema() + "ºC"); lblTempHD.setText("Disco Rígido: " + temp.getHD() + "ºC"); lblEstadoWeb.setText("Estado Servidor Web: " + serv.getEstadoWeb()); lblEstadoCorreo.setText("Estado Servidor Correo: " + serv.getEstadoCorreo()); lblEstadoSSH.setText("Estado Servidor SSH: " + serv.getEstadoSSH()); lblEstadoFTP.setText("Estado Servidor FTP: " + serv.getEstadoFTP()); lblEstadoSamba.setText("Estado Servidor Samba: " + serv.getEstadoSamba()); lblDiscoRaiz.setText("Particion Raiz: " + disc.getRaizTotal() + " MB Totales, " + disc.getRaizUsado() + " MB Usados, " + disc.getRaizLibre() + " MB Libres"); lblDiscoHome.setText("Particion Home: " + disc.getHomeTotal() + " MB Totales, " + disc.getHomeUsado() + " MB Usados, " + disc.getHomeLibre() + " MB Libres"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?