/** * Constructor of the class Connection * * @param esServidor indicates if is a server */ public Conexion(boolean esServidor) { // Set connection if (!this.establecer()) { // TODO Check wrong connection } Mensaje msg = new MensajeSistema(); // Configure the message connection msg.setTipo(msg.CREATE_CONNECTION); // FIXME esto no se sabe muy bien // It's not neccesary set connection because there is id // datos.setOrigen(""); // Send the message connection this.send(null, msg); // Recive the answer msg = this.receive(null); // TODO tratamiento de errores del sistema if (msg.getTipo() == msg.OK) { // TODO mensaje de configuracion�? this.id = ((MensajeString) msg).getContenido(); } else { // TODO tratamiento de errores } // Disconnect this.desconectar(); // TODO: Establecer conexion con tu Demonio*/ }
@RequestMapping( value = "/mensaje", method = RequestMethod.GET, headers = {"Accept=application/json"}) @ResponseBody String buscartodos() throws Exception { // esto va a ser obtenido a travez de DAOmensaje y su metodo obtener todos Mensaje m1 = new Mensaje(); m1.setTitulo("Springboot"); m1.setCuerpo("Springboot es la neta camioneta"); Mensaje m2 = new Mensaje(); m2.setTitulo("Java 3"); m2.setCuerpo("Esta materia es facil'Segun'"); Mensaje m3 = new Mensaje(); m3.setTitulo("Jessi"); m3.setCuerpo("Tu no vas a pasar muajaja"); ArrayList<Mensaje> arreglo = new ArrayList<Mensaje>(); arreglo.add(m1); arreglo.add(m2); arreglo.add(m3); // vamos a usar una clase que se llama objectmapper para traducir a jason ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(arreglo); }
public void run() { while (buffer.darCantidadMensajes() > 0) { Mensaje mensaje = buffer.recibir(); if (mensaje != null) { synchronized (mensaje) { mensaje.notify(); } } yield(); } }
// Método que vacía la tabla. public void limpiarTabla(JTable tabla) { try { DefaultTableModel modelo = (DefaultTableModel) tabla.getModel(); int filas = tabla.getRowCount(); for (int i = 0; filas > i; i++) { modelo.removeRow(0); } } catch (Exception e) { Frame f = JOptionPane.getFrameForComponent(this); Mensaje mensaje = new Mensaje(f, true, "Error al limpiar la tabla"); mensaje.show(); } }
@Override public Mensaje eliminaDecorador(Mensaje m) { if (m == this) { return decorado; } else { decorado = decorado.eliminaDecorador(m); } return decorado; }
@Override public Mensaje enviarMensaje(Mensaje msg) { // FIXME SEND MESSAGE NO TIENE TIPO // msg.setTipo(msg.SEND_MESSAGE); msg.setOrigen(this.getId()); this.establecer(); this.send(null, msg); msg = this.receive(null); this.desconectar(); return msg; }
// Dividir @Override public Entero operacionDividir(TiposDeDatos dato) { if (dato instanceof Entero) { return new Entero(this.obtenerNombre(), this.numero / ((Entero) dato).obtenerDato()); } else if (dato instanceof Decimal) { return new Entero(this.obtenerNombre(), this.numero / (int) ((Decimal) dato).obtenerDato()); } else { Mensaje.imprimir( "La variable " + dato.obtenerNombre() + " no es un Entero o Decimal", Mensaje.ERROR); } return null; }
public void enviar() { c.setContrasenia("guitarra0"); c.setUsuarioCorreo("*****@*****.**"); // base de datos! c.setAsunto("Información"); c.setMensaje(Mensaje.getText()); c.setDestino(txtPara.getText().trim()); c.setNombreArchivo("logo.png"); c.setRutaArchivo("logo.png"); Controlador co = new Controlador(); if (co.enviarCorreo(c)) { JOptionPane.showMessageDialog(null, "exito"); } else { JOptionPane.showMessageDialog(null, "fallido"); } }
// Operadores Matematicos // Asignacion @Override public Entero operacionAsignar(TiposDeDatos dato) { if (dato instanceof Entero) { this.numero = ((Entero) dato).obtenerDato(); return this; // Retorna este objeto } else if (dato instanceof Decimal) { this.numero = (int) ((Decimal) dato).obtenerDato(); return this; // Retorna este objeto } else { Mensaje.imprimir( "La variable que se le asigna a " + this.obtenerNombre() + " no es un Entero o Decimal", Mensaje.ERROR); } return null; }
@Override public Logico compararMenorIgual(TiposDeDatos datos) { if (datos instanceof Entero) { return new Logico(this.numero <= ((Entero) datos).obtenerDato()); } else if (datos instanceof Decimal) { return new Logico(this.numero <= (int) ((Decimal) datos).obtenerDato()); } Mensaje.imprimir( "No se puede comparar " + this.obtenerNombre() + " con " + datos.obtenerNombre() + " son de distintos tipo", Mensaje.ERROR); return null; }
@Override public Mensaje obtenerMensaje(int mascara, boolean espera) { Mensaje msg = new MensajeSistema(); msg.setOrigen(this.getId()); msg.setDestino(this.getId()); if (espera) msg.setTipo(msg.READ_MESSAGE_WAIT); else msg.setTipo(msg.READ_MESSAGE_NO_WAIT); msg.setMascara(mascara); this.establecer(); this.send(null, msg); msg = this.receive(null); this.desconectar(); return msg; }
public Home(VentanaPrincipal mipadre) { setSize(679, 400); this.padre = mipadre; setLayout(null); passwordField_1 = new JPasswordField(); passwordField_1.setFont(new Font("Tahoma", Font.PLAIN, 16)); passwordField_1.setBounds(523, 88, 146, 23); add(passwordField_1); passwordField_1.setColumns(20); JLabel lblContrasenha = new JLabel("Contraseña:"); lblContrasenha.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblContrasenha.setBounds(427, 88, 96, 23); add(lblContrasenha); JButton Aceptar = new JButton("Aceptar"); Aceptar.setFont(new Font("Tahoma", Font.PLAIN, 16)); Aceptar.setLocation(523, 122); add(Aceptar); Aceptar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (textField.getText().equals("") && passwordField_1.getText().equals("")) Mensaje.setText("Usuario/Contraseña vacios"); else { CodificacionPW c = new CodificacionPW(passwordField_1.getText()); if (padre .getControladorPersonas() .introduceDatosInicioSesion(textField.getText(), c.getPassword())) { PanelInicio panIni = new PanelInicio(padre, textField.getText()); padre.getContentPane().removeAll(); padre.getContentPane().validate(); padre.getContentPane().add(panIni); padre.setExtendedState(Frame.MAXIMIZED_BOTH); padre.getContentPane().repaint(); } else { Mensaje.setText("Usuario/Contraseña incorrectos"); } } } }); Aceptar.setSize(102, 23); JLabel lblUsuario = new JLabel("Usuario:"); lblUsuario.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblUsuario.setBounds(452, 59, 71, 14); add(lblUsuario); textField = new JTextField(); textField.setFont(new Font("Tahoma", Font.PLAIN, 16)); textField.setBounds(523, 54, 146, 23); add(textField); textField.setColumns(20); Mensaje.setHorizontalAlignment(SwingConstants.CENTER); Mensaje.setBounds(141, 351, 361, 23); add(Mensaje); JLabel label = new JLabel(""); label.setHorizontalAlignment(SwingConstants.CENTER); label.setIcon(new ImageIcon((this.getClass().getResource("/img/imagen.jpg")))); label.setBounds(24, 11, 558, 378); add(label); }
private void btAñadirActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btAñadirActionPerformed try { // Accedo a la base de datos con la instancia Singleton que creé y me conecto a ella. BD basedatos = BD.getInstance(); conn = basedatos.getConnection(); // Recojo los datos de los campos de texto String nombre = tfNombre.getText(); String apellidos = tfApellidos.getText(); // No podemos ingresar un nombre de Camarero vacío if (nombre.trim().length() != 0) { // No podemos ingresar un apellido de Camarero vacío if (apellidos.trim().length() != 0) { // Solo se puede introducir un dato numérico if (isNumeric(tfID.getText())) { int id = Integer.parseInt(tfID.getText()); sentencia = conn.createStatement(); // Hago un select a la clave primaria de categoria para que el usuario no pueda meter // dos iguales ResultSet existe = sentencia.executeQuery("SELECT p_camarero FROM camarero"); boolean idExiste = false; while (existe.next()) { if (existe.getInt("p_camarero") == id) { // Si el ID ya existe muestro un option pane indicando el error y marco la variable // booleana idExiste como true Frame f = JOptionPane.getFrameForComponent(this); Mensaje mensaje = new Mensaje(f, true, "El ID ya existe, introduce uno nuevo"); mensaje.show(); idExiste = true; } } // Si idExiste es false entonces puedo crear una nueva. if (!idExiste) { // Inserto en la base de datos el id y el nombre de la categoria ResultSet resultado = sentencia.executeQuery( "INSERT INTO camarero VALUES (" + id + ", '" + nombre + "', '" + apellidos + "');"); // Limpio la tabla para volver a llenarla con el nuevo contenido de la base de datos limpiarTabla(tabla); llenarTabla(); limpiar(); // Desconecto resultado.close(); conn.close(); sentencia.close(); } } else { // Muestro un mensaje de alerta en un JDialog, para poder mostrarlo necesito el Frame // que contiene // el JInternal Frame Frame f = JOptionPane.getFrameForComponent(this); Mensaje mensaje = new Mensaje(f, true, "Tienes que introducir un numero en el ID"); mensaje.show(); } } else { // Muestro un mensaje de alerta en un JDialog, para poder mostrarlo necesito el Frame que // contiene // el JInternal Frame Frame f = JOptionPane.getFrameForComponent(this); Mensaje mensaje = new Mensaje(f, true, "Tienes que introducir los apellidos del Camarero"); mensaje.show(); } } else { // Muestro un mensaje de alerta en un JDialog, para poder mostrarlo necesito el Frame que // contiene // el JInternal Frame Frame f = JOptionPane.getFrameForComponent(this); Mensaje mensaje = new Mensaje(f, true, "Tienes que introducir el nombre del Camarero"); mensaje.show(); } } catch (SQLException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } } // GEN-LAST:event_btAñadirActionPerformed
@Override public Usuario remitente() { return decorado.remitente(); }
@Override public Date fecha() { return decorado.fecha(); }
@Override public int tamaño() { return decorado.tamaño() + tamaño; }
@Override public String contenido() { return decorado.contenido(); }
/** * 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(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); txtPara = new javax.swing.JTextField(); txtDe = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); Mensaje = new javax.swing.JTextArea(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setBackground(new java.awt.Color(153, 255, 153)); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel1.setText("PARA:"); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel2.setText("DE:"); jButton1.setBackground(new java.awt.Color(0, 102, 102)); jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jButton1.setForeground(new java.awt.Color(255, 255, 255)); jButton1.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/shipping3.png"))); // NOI18N jButton1.setText("Send"); jButton1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); txtPara.setBorder(null); txtPara.setOpaque(false); txtDe.setBorder(null); txtDe.setOpaque(false); Mensaje.setColumns(20); Mensaje.setLineWrap(true); Mensaje.setRows(5); jScrollPane1.setViewportView(Mensaje); jLabel3.setText("Archivo.pdf"); jLabel4.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/icono_pdf.png"))); // NOI18N jLabel5.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/barra.png"))); // NOI18N jLabel6.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/barra2.png"))); // NOI18N jPanel1.setBackground(new java.awt.Color(0, 102, 102)); jLabel7.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/envelope74 (1).png"))); // NOI18N jLabel9.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/upload64.png"))); // NOI18N jLabel10.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel10.setForeground(new java.awt.Color(255, 255, 255)); jLabel10.setText("@Correo"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addGap(85, 85, 85) .addComponent(jLabel7) .addGap(37, 37, 37) .addComponent(jLabel10) .addGap(48, 48, 48) .addComponent(jLabel9) .addContainerGap(64, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout .createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7) .addComponent(jLabel9) .addComponent(jLabel10)) .addGap(19, 19, 19))); jLabel8.setIcon( new javax.swing.ImageIcon(getClass().getResource("/icons/link21.png"))); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createSequentialGroup() .addGap(60, 60, 60) .addComponent(jLabel2) .addGap(7, 7, 7) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addGroup( layout .createSequentialGroup() .addGap(10, 10, 10) .addComponent( txtDe, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup( layout .createSequentialGroup() .addGap(50, 50, 50) .addComponent(jLabel1) .addGap(2, 2, 2) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(10, 10, 10) .addComponent( txtPara, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel6))) .addGroup( layout .createSequentialGroup() .addGap(50, 50, 50) .addComponent(jLabel4) .addGap(12, 12, 12) .addComponent( jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(10, 10, 10) .addComponent(jLabel8)) .addGroup( layout .createSequentialGroup() .addGap(20, 20, 20) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton1) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(2, 2, 2))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(40, 40, 40) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createSequentialGroup() .addGap(10, 10, 10) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent( txtDe, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(10, 10, 10) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createSequentialGroup() .addGap(10, 10, 10) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent( txtPara, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(10, 10, 10) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent( jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8)) .addGap(16, 16, 16) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); } // </editor-fold>//GEN-END:initComponents
public Home(VentanaPrincipal mipadre) { setSize(1200, 700); this.padre = mipadre; setLayout(null); passwordField_1 = new JPasswordField(); passwordField_1.setFont(new Font("Tahoma", Font.PLAIN, 16)); passwordField_1.setBounds(1007, 61, 146, 23); add(passwordField_1); passwordField_1.setColumns(20); JLabel lblContrasenha = new JLabel("Contraseña:"); lblContrasenha.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblContrasenha.setBounds(911, 61, 96, 23); add(lblContrasenha); JButton Aceptar = new JButton("Aceptar"); Aceptar.setFont(new Font("Tahoma", Font.PLAIN, 16)); Aceptar.setLocation(1007, 95); add(Aceptar); Aceptar.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (textField.getText().equals("") && passwordField_1.getText().equals("")) Mensaje.setText("Usuario/Contraseña vacios"); else { CodificacionPW c = new CodificacionPW(passwordField_1.getText()); if (padre .getcontrolador() .introduceDatosInicioSesion(textField.getText(), c.getPassword())) { padre.getContentPane().removeAll(); padre.getContentPane().validate(); padre.getContentPane().add(new Pestanas(padre, textField.getText())); padre.getContentPane().repaint(); } else { Mensaje.setText("Usuario/Contraseña incorrectos"); } } } }); Aceptar.setSize(102, 23); JLabel lblUsuario = new JLabel("Usuario:"); lblUsuario.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblUsuario.setBounds(936, 32, 71, 14); add(lblUsuario); textField = new JTextField(); textField.setFont(new Font("Tahoma", Font.PLAIN, 16)); textField.setBounds(1007, 27, 146, 23); add(textField); textField.setColumns(20); Mensaje.setBounds(414, 61, 361, 23); add(Mensaje); JLabel label = new JLabel(""); label.setIcon(new ImageIcon((this.getClass().getResource("/img/imagen.jpg")))); label.setBounds(205, 115, 625, 464); add(label); }