Advertisement
ljukk

zoznam

May 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.83 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class JFrame extends javax.swing.JFrame {
  4.  
  5.     LinkedList men = new LinkedList();
  6.     LinkedList women = new LinkedList();
  7.      
  8.      
  9.     public JFrame() {
  10.         initComponents();
  11.     }
  12.  
  13.     /**
  14.      * This method is called from within the constructor to initialize the form.
  15.      * WARNING: Do NOT modify this code. The content of this method is always
  16.      * regenerated by the Form Editor.
  17.      */
  18.     @SuppressWarnings("unchecked")
  19.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  20.     private void initComponents() {
  21.  
  22.         buttonGroup1 = new javax.swing.ButtonGroup();
  23.         jTextField1 = new javax.swing.JTextField();
  24.         jRadioButton1 = new javax.swing.JRadioButton();
  25.         jRadioButton2 = new javax.swing.JRadioButton();
  26.         jScrollPane1 = new javax.swing.JScrollPane();
  27.         jTextArea1 = new javax.swing.JTextArea();
  28.         jButton1 = new javax.swing.JButton();
  29.         jButton2 = new javax.swing.JButton();
  30.         jButton3 = new javax.swing.JButton();
  31.         jLabel1 = new javax.swing.JLabel();
  32.  
  33.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  34.  
  35.         jTextField1.setText("Meno a Priezvisko");
  36.  
  37.         jRadioButton1.setText("Muž");
  38.  
  39.         jRadioButton2.setText("Žena");
  40.  
  41.         jTextArea1.setColumns(20);
  42.         jTextArea1.setRows(5);
  43.         jScrollPane1.setViewportView(jTextArea1);
  44.  
  45.         jButton1.setText("Vytvor páry");
  46.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  47.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  48.                 jButton1ActionPerformed(evt);
  49.             }
  50.         });
  51.  
  52.         jButton2.setText("Odstráň");
  53.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  54.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  55.                 jButton2ActionPerformed(evt);
  56.             }
  57.         });
  58.  
  59.         jButton3.setText("Pridaj študenta");
  60.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  61.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  62.                 jButton3ActionPerformed(evt);
  63.             }
  64.         });
  65.  
  66.         jLabel1.setText("Info");
  67.  
  68.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  69.         getContentPane().setLayout(layout);
  70.         layout.setHorizontalGroup(
  71.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  72.             .addGroup(layout.createSequentialGroup()
  73.                 .addContainerGap()
  74.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  75.                     .addComponent(jScrollPane1)
  76.                     .addGroup(layout.createSequentialGroup()
  77.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  78.                             .addGroup(layout.createSequentialGroup()
  79.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  80.                                     .addGroup(layout.createSequentialGroup()
  81.                                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
  82.                                         .addGap(44, 44, 44)
  83.                                         .addComponent(jRadioButton1))
  84.                                     .addGroup(layout.createSequentialGroup()
  85.                                         .addComponent(jButton3)
  86.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  87.                                         .addComponent(jButton1)))
  88.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  89.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  90.                                     .addComponent(jButton2)
  91.                                     .addComponent(jRadioButton2)))
  92.                             .addComponent(jLabel1))
  93.                         .addGap(0, 67, Short.MAX_VALUE)))
  94.                 .addContainerGap())
  95.         );
  96.         layout.setVerticalGroup(
  97.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98.             .addGroup(layout.createSequentialGroup()
  99.                 .addContainerGap()
  100.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  101.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  102.                     .addComponent(jRadioButton1)
  103.                     .addComponent(jRadioButton2))
  104.                 .addGap(18, 18, 18)
  105.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  106.                     .addComponent(jButton1)
  107.                     .addComponent(jButton2)
  108.                     .addComponent(jButton3))
  109.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
  110.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
  111.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  112.                 .addComponent(jLabel1)
  113.                 .addGap(9, 9, 9))
  114.         );
  115.  
  116.         pack();
  117.     }// </editor-fold>//GEN-END:initComponents
  118.  
  119.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  120.         if (jRadioButton1.isSelected()){
  121.             men.add(jTextField1.getText());
  122.             jTextArea1.append(jTextField1.getText()+"\n");
  123.         } else if (jRadioButton2.isSelected()) {
  124.             women.add(jTextField1.getText());
  125.             jTextArea1.append(jTextField1.getText()+"\n");
  126.         } else {
  127.         }
  128.     }//GEN-LAST:event_jButton3ActionPerformed
  129.  
  130.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  131.         if(men.size() == women.size()){
  132.             jLabel1.setText("Dajú sa vytvoriť páry.");
  133.         } else {
  134.             jLabel1.setText("Nedajú sa vytvoriť páry.");
  135.         }
  136.     }//GEN-LAST:event_jButton1ActionPerformed
  137.  
  138.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  139.         int gender = (int) (Math.random()* 2);
  140.         int index;
  141.         int prevMen = men.size();
  142.         int prevWom = women.size();
  143.         if (gender == 1){
  144.             index = (int) (Math.random()* men.size());
  145.             System.out.println(men.get(index));
  146.             String name = (String)men.get(index);
  147.             jTextArea1.setText(jTextArea1.getText().replaceAll( name + "\n", "" ));
  148.             men.remove(index);
  149.         } else {
  150.             index = (int) (Math.random()* women.size());
  151.             System.out.println(women.get(index));
  152.             String name = (String) women.get(index);
  153.             jTextArea1.setText(jTextArea1.getText().replaceAll( name + "\n", "" ));
  154.             women.remove(index);
  155.         }
  156.         jLabel1.setText("Predošlí počet: " + prevMen + " chlapov a " + prevWom + " dievčat. A teraz je " + men.size() + " chalpov a " + women.size() + " dievčat.");
  157.     }//GEN-LAST:event_jButton2ActionPerformed
  158.  
  159.     private void deletingGendre(String gendre) {
  160.         if (gendre == "man"){
  161.             men.clear();
  162.         } else {
  163.             women.clear();
  164.         }
  165.     }
  166.  
  167.     public static void main(String args[]) {
  168.         /* Set the Nimbus look and feel */
  169.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  170.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  171.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  172.          */
  173.         try {
  174.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  175.                 if ("Nimbus".equals(info.getName())) {
  176.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  177.                     break;
  178.                 }
  179.             }
  180.         } catch (ClassNotFoundException ex) {
  181.             java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  182.         } catch (InstantiationException ex) {
  183.             java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  184.         } catch (IllegalAccessException ex) {
  185.             java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  186.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  187.             java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  188.         }
  189.         //</editor-fold>
  190.  
  191.         /* Create and display the form */
  192.         java.awt.EventQueue.invokeLater(new Runnable() {
  193.             public void run() {
  194.                 new JFrame().setVisible(true);
  195.             }
  196.         });
  197.     }
  198.  
  199.     // Variables declaration - do not modify//GEN-BEGIN:variables
  200.     private javax.swing.ButtonGroup buttonGroup1;
  201.     private javax.swing.JButton jButton1;
  202.     private javax.swing.JButton jButton2;
  203.     private javax.swing.JButton jButton3;
  204.     private javax.swing.JLabel jLabel1;
  205.     private javax.swing.JRadioButton jRadioButton1;
  206.     private javax.swing.JRadioButton jRadioButton2;
  207.     private javax.swing.JScrollPane jScrollPane1;
  208.     private javax.swing.JTextArea jTextArea1;
  209.     private javax.swing.JTextField jTextField1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement