ljukk

oop list

May 12th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.51 KB | None | 0 0
  1. import javax.swing.DefaultListModel;
  2. import javax.swing.JOptionPane;
  3.  
  4. /*
  5.  * To change this license header, choose License Headers in Project Properties.
  6.  * To change this template file, choose Tools | Templates
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. /**
  11.  *
  12.  * @author sused
  13.  */
  14. public class MojeOkno extends javax.swing.JFrame {
  15.     private DefaultListModel data;
  16.     private DefaultListModel dataVIP;
  17.  
  18.     /**
  19.      * Creates new form MojeOkno
  20.      */
  21.     public MojeOkno() {
  22.         initComponents();
  23.         data = new DefaultListModel();
  24.         jList1.setModel(data);
  25.        
  26.     }
  27.  
  28.     /**
  29.      * This method is called from within the constructor to initialize the form.
  30.      * WARNING: Do NOT modify this code. The content of this method is always
  31.      * regenerated by the Form Editor.
  32.      */
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  35.     private void initComponents() {
  36.  
  37.         buttonGroup1 = new javax.swing.ButtonGroup();
  38.         buttonGroup2 = new javax.swing.ButtonGroup();
  39.         jButton1 = new javax.swing.JButton();
  40.         jTextField1 = new javax.swing.JTextField();
  41.         jLabel1 = new javax.swing.JLabel();
  42.         jButton2 = new javax.swing.JButton();
  43.         jRadioButton1 = new javax.swing.JRadioButton();
  44.         jRadioButton2 = new javax.swing.JRadioButton();
  45.         jRadioButton3 = new javax.swing.JRadioButton();
  46.         jButton3 = new javax.swing.JButton();
  47.         jCheckBox1 = new javax.swing.JCheckBox();
  48.         jCheckBox2 = new javax.swing.JCheckBox();
  49.         jCheckBox3 = new javax.swing.JCheckBox();
  50.         jLabel2 = new javax.swing.JLabel();
  51.         jScrollPane1 = new javax.swing.JScrollPane();
  52.         jTextArea1 = new javax.swing.JTextArea();
  53.         jScrollPane2 = new javax.swing.JScrollPane();
  54.         jList1 = new javax.swing.JList<>();
  55.         jButton4 = new javax.swing.JButton();
  56.         jTextField3 = new javax.swing.JTextField();
  57.         jComboBox1 = new javax.swing.JComboBox<>();
  58.         jButton5 = new javax.swing.JButton();
  59.         jRadioButton4 = new javax.swing.JRadioButton();
  60.         jRadioButton5 = new javax.swing.JRadioButton();
  61.  
  62.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  63.  
  64.         jButton1.setText("Tlacidlo Ahoj");
  65.         jButton1.setToolTipText("");
  66.         jButton1.setActionCommand("Tlacidlo Ahoj");
  67.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  68.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  69.                 jButton1ActionPerformed(evt);
  70.             }
  71.         });
  72.  
  73.         jTextField1.addActionListener(new java.awt.event.ActionListener() {
  74.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  75.                 jTextField1ActionPerformed(evt);
  76.             }
  77.         });
  78.  
  79.         jLabel1.setText("Zadaj meno:");
  80.  
  81.         jButton2.setText("Pozdrav");
  82.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  83.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  84.                 jButton2ActionPerformed(evt);
  85.             }
  86.         });
  87.  
  88.         buttonGroup1.add(jRadioButton1);
  89.         jRadioButton1.setSelected(true);
  90.         jRadioButton1.setText("SK");
  91.  
  92.         buttonGroup1.add(jRadioButton2);
  93.         jRadioButton2.setText("DE");
  94.  
  95.         buttonGroup1.add(jRadioButton3);
  96.         jRadioButton3.setText("EN");
  97.  
  98.         jButton3.setText("Vypočítaj vek");
  99.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  100.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                 jButton3ActionPerformed(evt);
  102.             }
  103.         });
  104.  
  105.         jCheckBox1.setText("Veľa programujem");
  106.  
  107.         jCheckBox2.setText("Zdravo sa stravujem");
  108.  
  109.         jCheckBox3.setText("Chodím za babami");
  110.  
  111.         jLabel2.setText("Tvoj vek bude:");
  112.  
  113.         jTextArea1.setColumns(20);
  114.         jTextArea1.setRows(5);
  115.         jScrollPane1.setViewportView(jTextArea1);
  116.  
  117.         jList1.setModel(new javax.swing.AbstractListModel<String>() {
  118.             String[] strings = { "Menu 1", "Menu 2", "Menu 3" };
  119.             public int getSize() { return strings.length; }
  120.             public String getElementAt(int i) { return strings[i]; }
  121.         });
  122.         jScrollPane2.setViewportView(jList1);
  123.  
  124.         jButton4.setText("Pridaj kamoša");
  125.         jButton4.addActionListener(new java.awt.event.ActionListener() {
  126.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  127.                 jButton4ActionPerformed(evt);
  128.             }
  129.         });
  130.  
  131.         jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
  132.         jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  133.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  134.                 jComboBox1ActionPerformed(evt);
  135.             }
  136.         });
  137.  
  138.         jButton5.setText("Odober");
  139.         jButton5.addActionListener(new java.awt.event.ActionListener() {
  140.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  141.                 jButton5ActionPerformed(evt);
  142.             }
  143.         });
  144.  
  145.         buttonGroup2.add(jRadioButton4);
  146.         jRadioButton4.setText("VIP");
  147.         jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
  148.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  149.                 jRadioButton4ActionPerformed(evt);
  150.             }
  151.         });
  152.  
  153.         buttonGroup2.add(jRadioButton5);
  154.         jRadioButton5.setSelected(true);
  155.         jRadioButton5.setText("Standard");
  156.         jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
  157.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  158.                 jRadioButton5ActionPerformed(evt);
  159.             }
  160.         });
  161.  
  162.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  163.         getContentPane().setLayout(layout);
  164.         layout.setHorizontalGroup(
  165.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  166.             .addGroup(layout.createSequentialGroup()
  167.                 .addContainerGap()
  168.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  169.                     .addComponent(jButton3)
  170.                     .addGroup(layout.createSequentialGroup()
  171.                         .addGap(10, 10, 10)
  172.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  173.                             .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
  174.                             .addComponent(jButton1)
  175.                             .addGroup(layout.createSequentialGroup()
  176.                                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
  177.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  178.                                 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))))
  179.                 .addGap(62, 62, 62)
  180.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  181.                     .addGroup(layout.createSequentialGroup()
  182.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  183.                             .addGroup(layout.createSequentialGroup()
  184.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  185.                                     .addComponent(jRadioButton1)
  186.                                     .addComponent(jRadioButton2)
  187.                                     .addComponent(jRadioButton3))
  188.                                 .addGap(54, 54, 54)
  189.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  190.                                     .addGroup(layout.createSequentialGroup()
  191.                                         .addGap(92, 92, 92)
  192.                                         .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  193.                                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  194.                                         .addGap(122, 122, 122)
  195.                                         .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  196.                                     .addGroup(layout.createSequentialGroup()
  197.                                         .addGap(92, 92, 92)
  198.                                         .addComponent(jTextField3))
  199.                                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  200.                                         .addComponent(jRadioButton4)
  201.                                         .addComponent(jRadioButton5))))
  202.                             .addComponent(jButton4))
  203.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  204.                         .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
  205.                     .addGroup(layout.createSequentialGroup()
  206.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  207.                             .addComponent(jLabel2)
  208.                             .addGroup(layout.createSequentialGroup()
  209.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  210.                                     .addComponent(jCheckBox1)
  211.                                     .addComponent(jCheckBox2)
  212.                                     .addComponent(jCheckBox3))
  213.                                 .addGap(14, 14, 14)))
  214.                         .addGap(18, 18, 18)
  215.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  216.                 .addGap(33, 63, Short.MAX_VALUE))
  217.         );
  218.         layout.setVerticalGroup(
  219.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  220.             .addGroup(layout.createSequentialGroup()
  221.                 .addContainerGap()
  222.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  223.                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
  224.                     .addGroup(layout.createSequentialGroup()
  225.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226.                             .addGroup(layout.createSequentialGroup()
  227.                                 .addComponent(jButton4)
  228.                                 .addGap(2, 2, 2)
  229.                                 .addComponent(jRadioButton1)
  230.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  231.                                 .addComponent(jRadioButton2))
  232.                             .addGroup(layout.createSequentialGroup()
  233.                                 .addComponent(jButton1)
  234.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  235.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  236.                                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  237.                                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
  238.                                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  239.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  240.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  241.                                     .addComponent(jButton5)
  242.                                     .addComponent(jButton2))))
  243.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  244.                             .addGroup(layout.createSequentialGroup()
  245.                                 .addGap(35, 35, 35)
  246.                                 .addComponent(jRadioButton3))
  247.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  248.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  249.                                 .addComponent(jRadioButton4)
  250.                                 .addGap(18, 18, 18)
  251.                                 .addComponent(jRadioButton5)))))
  252.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
  253.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  254.                     .addComponent(jButton3)
  255.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  256.                         .addGroup(layout.createSequentialGroup()
  257.                             .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  258.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  259.                             .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  260.                         .addGroup(layout.createSequentialGroup()
  261.                             .addComponent(jCheckBox1)
  262.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  263.                             .addComponent(jCheckBox2)
  264.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  265.                             .addComponent(jCheckBox3)
  266.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  267.                             .addComponent(jLabel2))))
  268.                 .addContainerGap(132, Short.MAX_VALUE))
  269.         );
  270.  
  271.         pack();
  272.     }// </editor-fold>                        
  273.  
  274.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  275.         // TODO add your handling code here:
  276.     }                                          
  277.  
  278.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  279.         // TODO add your handling code here:
  280.         JOptionPane.showMessageDialog(this, "Ahoj " + jTextField1.getText());
  281.     }                                        
  282.  
  283.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  284.         if (jRadioButton1.isSelected())
  285.         JOptionPane.showMessageDialog(this, "Ahoj ");
  286.         if (jRadioButton2.isSelected())
  287.         JOptionPane.showMessageDialog(this, "Halo ");
  288.         if (jRadioButton3.isSelected())
  289.         JOptionPane.showMessageDialog(this, "Hello ");
  290.     }                                        
  291.  
  292.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  293.         // TODO add your handling code here:
  294.         int vek = 90;
  295.         if (jCheckBox1.isSelected()) vek -= 10;
  296.         if (jCheckBox2.isSelected()) vek += 10;
  297.         if (jCheckBox3.isSelected()) vek += 20;
  298.        
  299.         jLabel2.setText("Tvoj vek bude " + vek);
  300.         jTextArea1.setText("Tvoj vek bude " + vek);
  301.     }                                        
  302.  
  303.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  304.         // TODO add your handling code here:
  305.         if (jRadioButton4.isSelected()) {
  306.         dataVIP.addElement(jTextField3.getText());
  307.         jList1.setModel(dataVIP);
  308.         }
  309.         if (jRadioButton5.isSelected()); {
  310.         data.addElement(jTextField3.getText());}
  311.         jList1.setModel(data);
  312.     }                                        
  313.  
  314.     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  315.         // TODO add your handling code here:
  316.     }                                          
  317.  
  318.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  319.         // TODO add your handling code here:
  320.         int index = jList1.getSelectedIndex();
  321.         if (index >-1) {
  322.         data.removeElementAt(index);
  323.         } else {
  324.             JOptionPane.showMessageDialog(this, "Nevybral si nikoho ");
  325.         }
  326.                
  327.     }                                        
  328.  
  329.     private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  330.         // TODO add your handling code here:
  331.         jList1.setModel(dataVIP);
  332.     }                                            
  333.  
  334.     private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  335.         // TODO add your handling code here:
  336.         jList1.setModel(data);
  337.     }                                            
  338.  
  339.     /**
  340.      * @param args the command line arguments
  341.      */
  342.     public static void main(String args[]) {
  343.         /* Set the Nimbus look and feel */
  344.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  345.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  346.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  347.          */
  348.         try {
  349.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  350.                 if ("Nimbus".equals(info.getName())) {
  351.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  352.                     break;
  353.                 }
  354.             }
  355.         } catch (ClassNotFoundException ex) {
  356.             java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  357.         } catch (InstantiationException ex) {
  358.             java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  359.         } catch (IllegalAccessException ex) {
  360.             java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  361.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  362.             java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  363.         }
  364.         //</editor-fold>
  365.  
  366.         /* Create and display the form */
  367.         java.awt.EventQueue.invokeLater(new Runnable() {
  368.             public void run() {
  369.                 new MojeOkno().setVisible(true);
  370.             }
  371.         });
  372.     }
Add Comment
Please, Sign In to add comment