Advertisement
Alex9090

LABORATOR 9 JAVA

Apr 27th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.27 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 lab9;
  7.  
  8. /**
  9.  *
  10.  * @author Student
  11.  */
  12. public class FrameExample2 extends javax.swing.JFrame {
  13.  
  14.     /**
  15.      * Creates new form FrameExample2
  16.      */
  17.     public FrameExample2() {
  18.         initComponents();
  19.         myInitComponents();
  20.     }
  21.     public void myInitComponents(){
  22.         jCheckBox2.setText("Second option");
  23.         jCheckBox3.setText("Third option");
  24.         jCheckBox4.setText("None of the above");
  25.         jLabel1.setText("Username");
  26.         jLabel2.setText("Password");
  27.         //jPasswordField1.setText("");
  28.        
  29.        
  30.     }
  31.     /**
  32.      * This method is called from within the constructor to initialize the form.
  33.      * WARNING: Do NOT modify this code. The content of this method is always
  34.      * regenerated by the Form Editor.
  35.      */
  36.     @SuppressWarnings("unchecked")
  37.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  38.     private void initComponents() {
  39.  
  40.         jCheckBox1 = new javax.swing.JCheckBox();
  41.         jCheckBox2 = new javax.swing.JCheckBox();
  42.         jCheckBox3 = new javax.swing.JCheckBox();
  43.         jCheckBox4 = new javax.swing.JCheckBox();
  44.         jPanel1 = new javax.swing.JPanel();
  45.         jLabel1 = new javax.swing.JLabel();
  46.         jLabel2 = new javax.swing.JLabel();
  47.         jTextField1 = new javax.swing.JTextField();
  48.         jPasswordField1 = new javax.swing.JPasswordField();
  49.         jButton1 = new javax.swing.JButton();
  50.  
  51.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  52.  
  53.         jCheckBox1.setLabel("FirstOption");
  54.         jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
  55.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  56.                 jCheckBox1ActionPerformed(evt);
  57.             }
  58.         });
  59.  
  60.         jCheckBox2.setText("jCheckBox2");
  61.         jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
  62.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  63.                 jCheckBox2ActionPerformed(evt);
  64.             }
  65.         });
  66.  
  67.         jCheckBox3.setText("jCheckBox3");
  68.         jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
  69.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  70.                 jCheckBox3ActionPerformed(evt);
  71.             }
  72.         });
  73.  
  74.         jCheckBox4.setText("jCheckBox4");
  75.         jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
  76.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  77.                 jCheckBox4ActionPerformed(evt);
  78.             }
  79.         });
  80.  
  81.         jLabel1.setText("Username");
  82.  
  83.         jLabel2.setText("jLabel2");
  84.  
  85.         jTextField1.addActionListener(new java.awt.event.ActionListener() {
  86.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  87.                 jTextField1ActionPerformed(evt);
  88.             }
  89.         });
  90.  
  91.         jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
  92.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  93.                 jPasswordField1ActionPerformed(evt);
  94.             }
  95.         });
  96.  
  97.         jButton1.setText("Login");
  98.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  99.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  100.                 jButton1ActionPerformed(evt);
  101.             }
  102.         });
  103.  
  104.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  105.         jPanel1.setLayout(jPanel1Layout);
  106.         jPanel1Layout.setHorizontalGroup(
  107.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108.             .addGroup(jPanel1Layout.createSequentialGroup()
  109.                 .addGap(23, 23, 23)
  110.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  111.                     .addComponent(jLabel2)
  112.                     .addComponent(jLabel1))
  113.                 .addGap(24, 24, 24)
  114.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  115.                     .addComponent(jTextField1)
  116.                     .addComponent(jPasswordField1))
  117.                 .addContainerGap())
  118.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  119.                 .addContainerGap(73, Short.MAX_VALUE)
  120.                 .addComponent(jButton1)
  121.                 .addGap(66, 66, 66))
  122.         );
  123.         jPanel1Layout.setVerticalGroup(
  124.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  125.             .addGroup(jPanel1Layout.createSequentialGroup()
  126.                 .addGap(27, 27, 27)
  127.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  128.                     .addComponent(jLabel1)
  129.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
  130.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  131.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  132.                     .addComponent(jLabel2)
  133.                     .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  134.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  135.                 .addComponent(jButton1)
  136.                 .addContainerGap(41, Short.MAX_VALUE))
  137.         );
  138.  
  139.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  140.         getContentPane().setLayout(layout);
  141.         layout.setHorizontalGroup(
  142.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  144.                 .addContainerGap(181, Short.MAX_VALUE)
  145.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  146.                     .addComponent(jCheckBox4)
  147.                     .addComponent(jCheckBox3)
  148.                     .addComponent(jCheckBox2)
  149.                     .addComponent(jCheckBox1))
  150.                 .addGap(65, 65, 65)
  151.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  152.                 .addGap(287, 287, 287))
  153.         );
  154.         layout.setVerticalGroup(
  155.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  156.             .addGroup(layout.createSequentialGroup()
  157.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  158.                     .addGroup(layout.createSequentialGroup()
  159.                         .addGap(207, 207, 207)
  160.                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  161.                     .addGroup(layout.createSequentialGroup()
  162.                         .addGap(220, 220, 220)
  163.                         .addComponent(jCheckBox1)
  164.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  165.                         .addComponent(jCheckBox2)
  166.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  167.                         .addComponent(jCheckBox3)
  168.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  169.                         .addComponent(jCheckBox4)))
  170.                 .addContainerGap(57, Short.MAX_VALUE))
  171.         );
  172.  
  173.         pack();
  174.     }// </editor-fold>                        
  175.  
  176.     private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  177.         if(jCheckBox1.isSelected())
  178.         {
  179.             jCheckBox4.setSelected(false);
  180.         }
  181.        
  182.     }                                          
  183.  
  184.     private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  185.         if(jCheckBox4.isSelected())
  186.         {
  187.             jCheckBox1.setSelected(false);
  188.             jCheckBox2.setSelected(false);
  189.             jCheckBox3.setSelected(false);
  190.         }
  191.     }                                          
  192.  
  193.     private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  194.          if(jCheckBox2.isSelected())
  195.         {
  196.             jCheckBox4.setSelected(false);
  197.         }
  198.     }                                          
  199.  
  200.     private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  201.                                              
  202.          if(jCheckBox3.isSelected())
  203.         {
  204.             jCheckBox4.setSelected(false);
  205.         }
  206.    
  207.     }                                          
  208.  
  209.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  210.         // TODO add your handling code here:
  211.     }                                          
  212.  
  213.     private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
  214.         // TODO add your handling code here:
  215.     }                                              
  216.  
  217.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  218.         String username = jTextField1.getText();
  219.         System.out.println(username);
  220.         char[] password = jPasswordField1.getPassword();
  221.         System.out.println(new String(password));
  222.        
  223.         this.setVisible(false);
  224.         Home home = new Home();
  225.         home.setVisible(true);
  226.     }                                        
  227.  
  228.     /**
  229.      * @param args the command line arguments
  230.      */
  231.     public static void main(String args[]) {
  232.         /* Set the Nimbus look and feel */
  233.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  234.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  235.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  236.          */
  237.         try {
  238.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  239.                 if ("Nimbus".equals(info.getName())) {
  240.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  241.                     break;
  242.                 }
  243.             }
  244.         } catch (ClassNotFoundException ex) {
  245.             java.util.logging.Logger.getLogger(FrameExample2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  246.         } catch (InstantiationException ex) {
  247.             java.util.logging.Logger.getLogger(FrameExample2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  248.         } catch (IllegalAccessException ex) {
  249.             java.util.logging.Logger.getLogger(FrameExample2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  250.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  251.             java.util.logging.Logger.getLogger(FrameExample2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  252.         }
  253.         //</editor-fold>
  254.  
  255.         /* Create and display the form */
  256.         java.awt.EventQueue.invokeLater(new Runnable() {
  257.             public void run() {
  258.                 new FrameExample2().setVisible(true);
  259.             }
  260.         });
  261.     }
  262.  
  263.     // Variables declaration - do not modify                    
  264.     private javax.swing.JButton jButton1;
  265.     private javax.swing.JCheckBox jCheckBox1;
  266.     private javax.swing.JCheckBox jCheckBox2;
  267.     private javax.swing.JCheckBox jCheckBox3;
  268.     private javax.swing.JCheckBox jCheckBox4;
  269.     private javax.swing.JLabel jLabel1;
  270.     private javax.swing.JLabel jLabel2;
  271.     private javax.swing.JPanel jPanel1;
  272.     private javax.swing.JPasswordField jPasswordField1;
  273.     private javax.swing.JTextField jTextField1;
  274.     // End of variables declaration                  
  275. }
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. /*
  289.  * To change this license header, choose License Headers in Project Properties.
  290.  * To change this template file, choose Tools | Templates
  291.  * and open the template in the editor.
  292.  */
  293. package lab9;
  294.  
  295. import java.awt.Dimension;
  296. import java.io.IOException;
  297. import java.nio.file.Files;
  298. import java.nio.file.Path;
  299. import javax.swing.JFrame;
  300. import javax.swing.JTextArea;
  301.  
  302. /**
  303.  *
  304.  * @author Student
  305.  */
  306. public class FrameExample3 extends javax.swing.JFrame {
  307.  
  308.     /**
  309.      * Creates new form FrameExample3
  310.      */
  311.     public FrameExample3() {
  312.         initComponents();
  313.     }
  314.  
  315.     /**
  316.      * This method is called from within the constructor to initialize the form.
  317.      * WARNING: Do NOT modify this code. The content of this method is always
  318.      * regenerated by the Form Editor.
  319.      */
  320.     @SuppressWarnings("unchecked")
  321.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  322.     private void initComponents() {
  323.  
  324.         jFileChooser1 = new javax.swing.JFileChooser();
  325.  
  326.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  327.  
  328.         jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
  329.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  330.                 jFileChooser1ActionPerformed(evt);
  331.             }
  332.         });
  333.  
  334.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  335.         getContentPane().setLayout(layout);
  336.         layout.setHorizontalGroup(
  337.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  338.             .addGroup(layout.createSequentialGroup()
  339.                 .addContainerGap()
  340.                 .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 667, javax.swing.GroupLayout.PREFERRED_SIZE)
  341.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  342.         );
  343.         layout.setVerticalGroup(
  344.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  345.             .addGroup(layout.createSequentialGroup()
  346.                 .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)
  347.                 .addGap(0, 0, Short.MAX_VALUE))
  348.         );
  349.  
  350.         pack();
  351.     }// </editor-fold>                        
  352.  
  353.     private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  354.         Path path = jFileChooser1.getSelectedFile().getAbsoluteFile().toPath();
  355.         String text = null;
  356.         try {
  357.             text = new String(Files.readAllBytes(path));
  358.             System.out.print(text);
  359.             this.setVisible(false);
  360.             JFrame myFrame = new JFrame();
  361.             myFrame.setVisible(true);
  362.             myFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  363.             JTextArea textArea = new JTextArea();
  364.             textArea.setVisible(true);
  365.             textArea.setText(text);
  366.             textArea.setPreferredSize(new Dimension(500,500));
  367.            
  368.             myFrame.add(textArea);
  369.             myFrame.pack();
  370.            
  371.         }
  372.         catch(IOException ex) {
  373.              ex.printStackTrace();
  374.         }
  375.        
  376.     }                                            
  377.  
  378.     /**
  379.      * @param args the command line arguments
  380.      */
  381.     public static void main(String args[]) {
  382.         /* Set the Nimbus look and feel */
  383.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  384.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  385.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  386.          */
  387.         try {
  388.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  389.                 if ("Nimbus".equals(info.getName())) {
  390.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  391.                     break;
  392.                 }
  393.             }
  394.         } catch (ClassNotFoundException ex) {
  395.             java.util.logging.Logger.getLogger(FrameExample3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  396.         } catch (InstantiationException ex) {
  397.             java.util.logging.Logger.getLogger(FrameExample3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  398.         } catch (IllegalAccessException ex) {
  399.             java.util.logging.Logger.getLogger(FrameExample3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  400.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  401.             java.util.logging.Logger.getLogger(FrameExample3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  402.         }
  403.         //</editor-fold>
  404.  
  405.         /* Create and display the form */
  406.         java.awt.EventQueue.invokeLater(new Runnable() {
  407.             public void run() {
  408.                 new FrameExample3().setVisible(true);
  409.             }
  410.         });
  411.     }
  412.  
  413.     // Variables declaration - do not modify                    
  414.     private javax.swing.JFileChooser jFileChooser1;
  415.     // End of variables declaration                  
  416. }
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432. ANGAJATI
  433. package altpachet;
  434.  
  435.  
  436. import altpachet.Angajat;
  437. import java.awt.BorderLayout;
  438. import java.awt.GridLayout;
  439. import java.awt.event.ActionEvent;
  440. import java.awt.event.ActionListener;
  441. import javax.swing.JButton;
  442. import javax.swing.JFrame;
  443. import javax.swing.JLabel;
  444. import javax.swing.JTextField;
  445.  
  446. /*
  447.  * To change this license header, choose License Headers in Project Properties.
  448.  * To change this template file, choose Tools | Templates
  449.  * and open the template in the editor.
  450.  */
  451.  
  452. /**
  453.  *
  454.  * @author Student
  455.  */
  456. public class FrameManagementAngajati extends javax.swing.JFrame {
  457.  
  458.     public ContainerAngajati angajati = new ContainerAngajati();
  459.     /**
  460.      * Creates new form FrameManagementAngajati
  461.      */
  462.     public FrameManagementAngajati() {
  463.         initComponents();
  464.         angajati = new ContainerAngajati();
  465.     }
  466.    
  467.     private void showAllEmpl(){
  468.         jPanel1.removeAll();
  469.         int n = angajati.getAngajati().size();
  470.         GridLayout layout = new GridLayout(n,2);
  471.         jPanel1.setLayout(layout);
  472.        
  473.         for(Angajat ang: angajati.getAngajati())
  474.         {
  475.             jPanel1.add(new JLabel(ang.getNume()));
  476.             jPanel1.add(new JLabel(ang.getSalariu().toString()));
  477.         }
  478.         this.setLayout(new BorderLayout());
  479.         jPanel1.setVisible(true);
  480.         this.revalidate();
  481.     }
  482.     /**
  483.      * This method is called from within the constructor to initialize the form.
  484.      * WARNING: Do NOT modify this code. The content of this method is always
  485.      * regenerated by the Form Editor.
  486.      */
  487.     @SuppressWarnings("unchecked")
  488.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  489.     private void initComponents() {
  490.  
  491.         jPanel1 = new javax.swing.JPanel();
  492.         jButton1 = new javax.swing.JButton();
  493.         jButton2 = new javax.swing.JButton();
  494.  
  495.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  496.  
  497.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  498.         jPanel1.setLayout(jPanel1Layout);
  499.         jPanel1Layout.setHorizontalGroup(
  500.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  501.             .addGap(0, 100, Short.MAX_VALUE)
  502.         );
  503.         jPanel1Layout.setVerticalGroup(
  504.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  505.             .addGap(0, 100, Short.MAX_VALUE)
  506.         );
  507.  
  508.         jButton1.setText("jButton1");
  509.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  510.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  511.                 jButton1ActionPerformed(evt);
  512.             }
  513.         });
  514.  
  515.         jButton2.setText("jButton2");
  516.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  517.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  518.                 jButton2ActionPerformed(evt);
  519.             }
  520.         });
  521.  
  522.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  523.         getContentPane().setLayout(layout);
  524.         layout.setHorizontalGroup(
  525.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  526.             .addGroup(layout.createSequentialGroup()
  527.                 .addGap(93, 93, 93)
  528.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  529.                 .addGap(18, 18, 18)
  530.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  531.                     .addComponent(jButton1)
  532.                     .addComponent(jButton2))
  533.                 .addContainerGap(116, Short.MAX_VALUE))
  534.         );
  535.         layout.setVerticalGroup(
  536.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  537.             .addGroup(layout.createSequentialGroup()
  538.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  539.                     .addGroup(layout.createSequentialGroup()
  540.                         .addGap(104, 104, 104)
  541.                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  542.                     .addGroup(layout.createSequentialGroup()
  543.                         .addGap(133, 133, 133)
  544.                         .addComponent(jButton1)
  545.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  546.                         .addComponent(jButton2)))
  547.                 .addContainerGap(96, Short.MAX_VALUE))
  548.         );
  549.  
  550.         pack();
  551.     }// </editor-fold>                        
  552.  
  553.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  554.         JFrame frameAdd = new JFrame();
  555.         frameAdd.setVisible(true);
  556.        
  557.         JLabel LabelNume = new JLabel("nume");
  558.         JLabel LabelSalariu = new JLabel("salariu");
  559.         JTextField numeField = new JTextField("", 3);
  560.         JTextField salariuField = new JTextField("", 3);
  561.        
  562.         frameAdd.add(LabelNume);
  563.         frameAdd.add(numeField);
  564.         frameAdd.add(LabelSalariu);
  565.         frameAdd.add(salariuField);
  566.        
  567.         JButton button = new JButton("add");
  568.        
  569.         button.addActionListener(new ActionListener(){
  570.  
  571.         @Override
  572.           public void actionPerformed(ActionEvent e){
  573.             angajati.add(new Angajat(numeField.getText(), Integer.parseInt(salariuField.getText())));
  574.             System.out.println(angajati);
  575.         }
  576.         });
  577.           frameAdd.add(button);
  578.         GridLayout layout = new GridLayout(3, 2);
  579.         frameAdd.setLayout(layout);
  580.         frameAdd.pack();
  581.     }                                        
  582.  
  583.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  584.         showAllEmpl();
  585.     }                                        
  586.  
  587.     /**
  588.      * @param args the command line arguments
  589.      */
  590.     public static void main(String args[]) {
  591.         /* Set the Nimbus look and feel */
  592.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  593.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  594.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  595.          */
  596.         try {
  597.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  598.                 if ("Nimbus".equals(info.getName())) {
  599.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  600.                     break;
  601.                 }
  602.             }
  603.         } catch (ClassNotFoundException ex) {
  604.             java.util.logging.Logger.getLogger(FrameManagementAngajati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  605.         } catch (InstantiationException ex) {
  606.             java.util.logging.Logger.getLogger(FrameManagementAngajati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  607.         } catch (IllegalAccessException ex) {
  608.             java.util.logging.Logger.getLogger(FrameManagementAngajati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  609.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  610.             java.util.logging.Logger.getLogger(FrameManagementAngajati.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  611.         }
  612.         //</editor-fold>
  613.  
  614.         /* Create and display the form */
  615.         java.awt.EventQueue.invokeLater(new Runnable() {
  616.             public void run() {
  617.                 new FrameManagementAngajati().setVisible(true);
  618.             }
  619.         });
  620.     }
  621.    
  622.    
  623.    
  624.  
  625.     // Variables declaration - do not modify                    
  626.     private javax.swing.JButton jButton1;
  627.     private javax.swing.JButton jButton2;
  628.     private javax.swing.JPanel jPanel1;
  629.     // End of variables declaration                  
  630. }
  631.  
  632. /*
  633.  * To change this license header, choose License Headers in Project Properties.
  634.  * To change this template file, choose Tools | Templates
  635.  * and open the template in the editor.
  636.  */
  637. package altpachet;
  638.  
  639. import java.util.ArrayList;
  640.  
  641. /**
  642.  *
  643.  * @author Student
  644.  */
  645. public class ContainerAngajati {
  646.    
  647.     private ArrayList<Angajat> angajati = new ArrayList<Angajat>();
  648.    
  649.     public void add(Angajat angajat){
  650.         angajati.add(angajat);
  651.     }
  652.  
  653.     @Override
  654.     public String toString() {
  655.         return "ContainerAngajati{" + "angajati=" + angajati + '}';
  656.     }
  657.  
  658.    
  659.    
  660.     public ArrayList<Angajat> getAngajati() {
  661.         return angajati;
  662.     }
  663.  
  664.     public void setAngajati(ArrayList<Angajat> angajati) {
  665.         this.angajati = angajati;
  666.     }
  667.    
  668.    
  669. }
  670. /*
  671.  * To change this license header, choose License Headers in Project Properties.
  672.  * To change this template file, choose Tools | Templates
  673.  * and open the template in the editor.
  674.  */
  675. package altpachet;
  676.  
  677. /**
  678.  *
  679.  * @author Student
  680.  */
  681. public class Angajat {
  682.     private String nume;
  683.     private Integer salariu;
  684.  
  685.     public Angajat(String nume, Integer salariu) {
  686.         this.nume = nume;
  687.         this.salariu = salariu;
  688.     }
  689.  
  690.     public String getNume() {
  691.         return nume;
  692.     }
  693.  
  694.     @Override
  695.     public String toString() {
  696.         return "Angajat{" + "nume=" + nume + ", salariu=" + salariu + '}';
  697.     }
  698.  
  699.     public void setNume(String nume) {
  700.         this.nume = nume;
  701.     }
  702.  
  703.     public Integer getSalariu() {
  704.         return salariu;
  705.     }
  706.  
  707.     public void setSalariu(Integer salariu) {
  708.         this.salariu = salariu;
  709.     }
  710.    
  711.    
  712. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement