Advertisement
peterzig

[JAVA] Tabelki Zubra

Apr 26th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.14 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package swing.lista.rozwijana;
  7.  
  8. import java.util.Vector;
  9.  
  10. /**
  11.  *
  12.  * @author Piotr Zuber
  13.  */
  14. public class Glowne_okno extends javax.swing.JFrame {
  15.  
  16.     /**
  17.      * Creates new form Glowne_okno
  18.      */
  19.     public Glowne_okno() {
  20.         initComponents();
  21.        // for(int i=0;i<20;i++)
  22.        //Combo_lista.addItem(String.valueOf(i));
  23.        
  24.        
  25.         Dopisz_button.setEnabled(false);
  26.     }
  27.     Vector<String> vect = new Vector<String>();
  28.  
  29.     /**
  30.      * This method is called from within the constructor to initialize the form.
  31.      * WARNING: Do NOT modify this code. The content of this method is always
  32.      * regenerated by the Form Editor.
  33.      */
  34.     @SuppressWarnings("unchecked")
  35.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  36.     private void initComponents() {
  37.  
  38.         Combo_lista = new javax.swing.JComboBox<>();
  39.         Dodaj_Button = new javax.swing.JButton();
  40.         Dopisz_button = new javax.swing.JButton();
  41.         Na_poczatku_check = new javax.swing.JCheckBox();
  42.         Tekstowe_pole = new javax.swing.JTextField();
  43.         jScrollPane1 = new javax.swing.JScrollPane();
  44.         Lista_rozwijana = new javax.swing.JList<>();
  45.  
  46.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  47.  
  48.         Combo_lista.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Hello", "world", "is", "a", "better", "place", "się", "nie", "zna", "na", "programowaniu", "ma", "tłuste", "włosy" }));
  49.         Combo_lista.addActionListener(new java.awt.event.ActionListener() {
  50.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  51.                 Combo_listaActionPerformed(evt);
  52.             }
  53.         });
  54.  
  55.         Dodaj_Button.setText("Dodaj");
  56.         Dodaj_Button.addActionListener(new java.awt.event.ActionListener() {
  57.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  58.                 Dodaj_ButtonActionPerformed(evt);
  59.             }
  60.         });
  61.  
  62.         Dopisz_button.setText("Dopisz");
  63.         Dopisz_button.addActionListener(new java.awt.event.ActionListener() {
  64.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  65.                 Dopisz_buttonActionPerformed(evt);
  66.             }
  67.         });
  68.  
  69.         Na_poczatku_check.setText("Na poczatku");
  70.         Na_poczatku_check.addActionListener(new java.awt.event.ActionListener() {
  71.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  72.                 Na_poczatku_checkActionPerformed(evt);
  73.             }
  74.         });
  75.  
  76.         Tekstowe_pole.addCaretListener(new javax.swing.event.CaretListener() {
  77.             public void caretUpdate(javax.swing.event.CaretEvent evt) {
  78.                 Tekstowe_poleCaretUpdate(evt);
  79.             }
  80.         });
  81.         Tekstowe_pole.addActionListener(new java.awt.event.ActionListener() {
  82.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  83.                 Tekstowe_poleActionPerformed(evt);
  84.             }
  85.         });
  86.  
  87.         jScrollPane1.setViewportView(Lista_rozwijana);
  88.  
  89.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  90.         getContentPane().setLayout(layout);
  91.         layout.setHorizontalGroup(
  92.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.             .addGroup(layout.createSequentialGroup()
  94.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95.                     .addGroup(layout.createSequentialGroup()
  96.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97.                             .addComponent(Dodaj_Button)
  98.                             .addComponent(Dopisz_button)
  99.                             .addComponent(Combo_lista, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
  100.                             .addComponent(Na_poczatku_check))
  101.                         .addGap(31, 31, 31)
  102.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
  103.                         .addGap(8, 8, 8))
  104.                     .addComponent(Tekstowe_pole))
  105.                 .addContainerGap())
  106.         );
  107.         layout.setVerticalGroup(
  108.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  109.             .addGroup(layout.createSequentialGroup()
  110.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  111.                     .addGroup(layout.createSequentialGroup()
  112.                         .addComponent(Dodaj_Button)
  113.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  114.                         .addComponent(Dopisz_button)
  115.                         .addGap(18, 18, 18)
  116.                         .addComponent(Combo_lista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  117.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  118.                         .addComponent(Na_poczatku_check))
  119.                     .addGroup(layout.createSequentialGroup()
  120.                         .addContainerGap()
  121.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)))
  122.                 .addGap(18, 18, 18)
  123.                 .addComponent(Tekstowe_pole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  124.                 .addGap(17, 17, 17))
  125.         );
  126.  
  127.         pack();
  128.     }// </editor-fold>                        
  129.  
  130.     private void Dodaj_ButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  131.        String temp = new String();
  132.        temp = Tekstowe_pole.getText();
  133.         if(Na_poczatku_check.isSelected())
  134.         {
  135.            
  136.             String sel_temp = temp;
  137.             temp=(String)Combo_lista.getSelectedItem();
  138.             temp+=sel_temp;
  139.          
  140.             Tekstowe_pole.setText(temp);
  141.         }
  142.         else
  143.         {
  144.             temp += (String)Combo_lista.getSelectedItem();
  145.             Tekstowe_pole.setText(temp);
  146.         }
  147.        
  148.     }                                            
  149.  
  150.     private void Dopisz_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                              
  151.         String tekst = Tekstowe_pole.getText();
  152.        
  153.         if(!tekst.equals("")){
  154.             vect.add(tekst);
  155.             Lista_rozwijana.setListData(vect);
  156.             Tekstowe_pole.setText("");
  157.         }
  158.        
  159.     }                                            
  160.  
  161.     private void Na_poczatku_checkActionPerformed(java.awt.event.ActionEvent evt) {                                                  
  162.         // TODO add your handling code here:
  163.     }                                                
  164.  
  165.     private void Tekstowe_poleActionPerformed(java.awt.event.ActionEvent evt) {                                              
  166.        
  167.     }                                            
  168.  
  169.     private void Combo_listaActionPerformed(java.awt.event.ActionEvent evt) {                                            
  170.         // TODO add your handling code here:
  171.     }                                          
  172.  
  173.     private void Tekstowe_poleCaretUpdate(javax.swing.event.CaretEvent evt) {                                          
  174.         // TODO add your handling code here:
  175.         // TODO add your handling code here:
  176.         if(!Tekstowe_pole.getText().equals(""))
  177.         {
  178.             Dopisz_button.setEnabled(true);
  179.         }
  180.         else
  181.         {
  182.             Dopisz_button.setEnabled(false);
  183.         }
  184.     }                                        
  185.  
  186.     /**
  187.      * @param args the command line arguments
  188.      */
  189.     public static void main(String args[]) {
  190.         /* Set the Nimbus look and feel */
  191.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  192.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  193.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  194.          */
  195.         try {
  196.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  197.                 if ("Nimbus".equals(info.getName())) {
  198.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  199.                     break;
  200.                 }
  201.             }
  202.         } catch (ClassNotFoundException ex) {
  203.             java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  204.         } catch (InstantiationException ex) {
  205.             java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  206.         } catch (IllegalAccessException ex) {
  207.             java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  208.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  209.             java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  210.         }
  211.         //</editor-fold>
  212.  
  213.         /* Create and display the form */
  214.         java.awt.EventQueue.invokeLater(new Runnable() {
  215.             public void run() {
  216.                 new Glowne_okno().setVisible(true);
  217.             }
  218.         });
  219.     }
  220.  
  221.     // Variables declaration - do not modify                    
  222.     private javax.swing.JComboBox<String> Combo_lista;
  223.     private javax.swing.JButton Dodaj_Button;
  224.     private javax.swing.JButton Dopisz_button;
  225.     private javax.swing.JList<String> Lista_rozwijana;
  226.     private javax.swing.JCheckBox Na_poczatku_check;
  227.     private javax.swing.JTextField Tekstowe_pole;
  228.     private javax.swing.JScrollPane jScrollPane1;
  229.     // End of variables declaration                  
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement