Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Interfaz; import Utils.TestWebServer; import static Utils.TestWebServer.getString; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.RequestBody; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JPanel; /** * * @author ana_j */ public class MenuLista extends javax.swing.JFrame { /** * Creates new form MenuLista */ TestWebServer server = new TestWebServer(); public MenuLista() { initComponents(); /** * ******** Colocar una imagen de fondo ********* */ ((JPanel) getContentPane()).setOpaque(false); ImageIcon uno = new ImageIcon(this.getClass().getResource("/Imagenes/lista.jpg")); JLabel fondo = new JLabel(); fondo.setIcon(uno); getLayeredPane().add(fondo, JLayeredPane.FRAME_CONTENT_LAYER); fondo.setBounds(0, 0, uno.getIconWidth(), uno.getIconHeight()); } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); jTextPane1 = new javax.swing.JTextPane(); btnBack = new javax.swing.JButton(); txtPalabraLista = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); btnAgregarLista = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); txtIndiceLista = new javax.swing.JTextField(); btnEliminarLista = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); txtPalabraBuscar = new javax.swing.JTextField(); btnBuscarLista = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); txtSalidaLista = new javax.swing.JTextPane(); btnGraficarLista = new javax.swing.JButton(); jScrollPane1.setViewportView(jTextPane1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); btnBack.setBackground(new java.awt.Color(255, 204, 204)); btnBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/left_arrow.png"))); // NOI18N btnBack.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBackActionPerformed(evt); } }); txtPalabraLista.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N jLabel1.setFont(new java.awt.Font("Century Gothic", 1, 16)); // NOI18N jLabel1.setForeground(new java.awt.Color(0, 0, 153)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("INGRESE NUEVA PALABRA"); btnAgregarLista.setFont(new java.awt.Font("Century Gothic", 1, 18)); // NOI18N btnAgregarLista.setText("AGREGAR"); btnAgregarLista.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAgregarListaActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Century Gothic", 1, 16)); // NOI18N jLabel2.setForeground(new java.awt.Color(0, 0, 153)); jLabel2.setText("INDICE NUMRICO A ELIMINAR"); txtIndiceLista.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N btnEliminarLista.setFont(new java.awt.Font("Century Gothic", 1, 18)); // NOI18N btnEliminarLista.setText("ELIMINAR"); btnEliminarLista.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEliminarListaActionPerformed(evt); } }); jLabel3.setFont(new java.awt.Font("Century Gothic", 1, 16)); // NOI18N jLabel3.setForeground(new java.awt.Color(0, 0, 153)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("INGRESE PALABRA A BUSCAR"); txtPalabraBuscar.setFont(new java.awt.Font("Century Gothic", 0, 14)); // NOI18N btnBuscarLista.setFont(new java.awt.Font("Century Gothic", 1, 18)); // NOI18N btnBuscarLista.setText("BUSCAR"); btnBuscarLista.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBuscarListaActionPerformed(evt); } }); txtSalidaLista.setBackground(new java.awt.Color(0, 0, 0)); txtSalidaLista.setFont(new java.awt.Font("Consolas", 0, 14)); // NOI18N txtSalidaLista.setForeground(new java.awt.Color(0, 51, 153)); jScrollPane2.setViewportView(txtSalidaLista); btnGraficarLista.setBackground(new java.awt.Color(153, 255, 153)); btnGraficarLista.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N btnGraficarLista.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/graph2.png"))); // NOI18N btnGraficarLista.setText("GRAFICAR"); btnGraficarLista.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnGraficarListaActionPerformed(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(10, 10, 10) .addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnGraficarLista).addContainerGap()) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane2) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(34, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txtPalabraBuscar, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel2) .addComponent(txtIndiceLista, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtPalabraLista, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnAgregarLista, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnEliminarLista, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBuscarLista, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(28, 28, 28))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnBack).addComponent(btnGraficarLista)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtPalabraLista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnAgregarLista)) .addGap(18, 18, 18).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtIndiceLista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnEliminarLista)) .addGap(18, 18, 18).addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtPalabraBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBuscarLista)) .addGap(37, 37, 37) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE) .addContainerGap())); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed // TODO add your handling code here: MenuPrincipal menu = new MenuPrincipal(); menu.setVisible(true); this.setVisible(false); }//GEN-LAST:event_btnBackActionPerformed private void btnAgregarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarListaActionPerformed // TODO add your handling code here: String palabra = txtPalabraLista.getText(); RequestBody formBody = new FormEncodingBuilder().add("palabra", palabra).build(); String r = getString("insertarLista", formBody); System.out.println(r); txtSalidaLista.setText(r); this.txtPalabraLista.setText(""); }//GEN-LAST:event_btnAgregarListaActionPerformed private void btnEliminarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarListaActionPerformed // TODO add your handling code here: String indice = txtIndiceLista.getText(); RequestBody formBody = new FormEncodingBuilder().add("indice", indice).build(); String r = getString("eliminarLista", formBody); System.out.println(r); txtSalidaLista.setText(r); this.txtIndiceLista.setText(""); }//GEN-LAST:event_btnEliminarListaActionPerformed private void btnBuscarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarListaActionPerformed // TODO add your handling code here: String palabra = txtPalabraBuscar.getText(); RequestBody formBody = new FormEncodingBuilder().add("palabra", palabra).build(); String r = getString("buscarLista", formBody); System.out.println(r); txtSalidaLista.setText(r); }//GEN-LAST:event_btnBuscarListaActionPerformed private void btnGraficarListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraficarListaActionPerformed // TODO add your handling code here: String palabra = ""; RequestBody formBody = new FormEncodingBuilder().add("palabra", palabra).build(); String r = getString("graficarLista", formBody); System.out.println(r); txtSalidaLista.setText(r); }//GEN-LAST:event_btnGraficarListaActionPerformed /** * @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(MenuLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MenuLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MenuLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MenuLista.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 MenuLista().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAgregarLista; private javax.swing.JButton btnBack; private javax.swing.JButton btnBuscarLista; private javax.swing.JButton btnEliminarLista; private javax.swing.JButton btnGraficarLista; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextPane jTextPane1; private javax.swing.JTextField txtIndiceLista; private javax.swing.JTextField txtPalabraBuscar; private javax.swing.JTextField txtPalabraLista; private javax.swing.JTextPane txtSalidaLista; // End of variables declaration//GEN-END:variables }