Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class JFrame extends javax.swing.JFrame {
- LinkedList men = new LinkedList();
- LinkedList women = new LinkedList();
- public JFrame() {
- initComponents();
- }
- /**
- * 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() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- jTextField1 = new javax.swing.JTextField();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jTextField1.setText("Meno a Priezvisko");
- jRadioButton1.setText("Muž");
- jRadioButton2.setText("Žena");
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- jButton1.setText("Vytvor páry");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Odstráň");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("Pridaj študenta");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jLabel1.setText("Info");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(44, 44, 44)
- .addComponent(jRadioButton1))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton1)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton2)
- .addComponent(jRadioButton2)))
- .addComponent(jLabel1))
- .addGap(0, 67, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2)
- .addComponent(jButton3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel1)
- .addGap(9, 9, 9))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
- if (jRadioButton1.isSelected()){
- men.add(jTextField1.getText());
- jTextArea1.append(jTextField1.getText()+"\n");
- } else if (jRadioButton2.isSelected()) {
- women.add(jTextField1.getText());
- jTextArea1.append(jTextField1.getText()+"\n");
- } else {
- }
- }//GEN-LAST:event_jButton3ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- if(men.size() == women.size()){
- jLabel1.setText("Dajú sa vytvoriť páry.");
- } else {
- jLabel1.setText("Nedajú sa vytvoriť páry.");
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- int gender = (int) (Math.random()* 2);
- int index;
- int prevMen = men.size();
- int prevWom = women.size();
- if (gender == 1){
- index = (int) (Math.random()* men.size());
- System.out.println(men.get(index));
- String name = (String)men.get(index);
- jTextArea1.setText(jTextArea1.getText().replaceAll( name + "\n", "" ));
- men.remove(index);
- } else {
- index = (int) (Math.random()* women.size());
- System.out.println(women.get(index));
- String name = (String) women.get(index);
- jTextArea1.setText(jTextArea1.getText().replaceAll( name + "\n", "" ));
- women.remove(index);
- }
- jLabel1.setText("Predošlí počet: " + prevMen + " chlapov a " + prevWom + " dievčat. A teraz je " + men.size() + " chalpov a " + women.size() + " dievčat.");
- }//GEN-LAST:event_jButton2ActionPerformed
- private void deletingGendre(String gendre) {
- if (gendre == "man"){
- men.clear();
- } else {
- women.clear();
- }
- }
- 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(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(JFrame.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 JFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextField jTextField1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement