Advertisement
Kirabo

javagui

Jan 24th, 2017
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.53 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 prophet;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.BufferedWriter;
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.FileNotFoundException;
  13. import java.io.FileWriter;
  14. import java.io.IOException;
  15. import java.io.InputStreamReader;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. import javax.swing.JFileChooser;
  19. import javax.swing.table.DefaultTableModel;
  20.  
  21. /**
  22.  *
  23.  * @author Vanja
  24.  */
  25. public class GUIIspit extends javax.swing.JFrame {
  26.  
  27.     /**
  28.      * Creates new form GUIIspit
  29.      */
  30.    
  31.     File input;
  32.     File output;
  33.    
  34.     public GUIIspit() {
  35.         initComponents();
  36.         tred tred = new tred(this.jLabel1);
  37.         Thread t1 = new Thread(tred);
  38.         t1.start();
  39.     }
  40.  
  41.     /**
  42.      * This method is called from within the constructor to initialize the form.
  43.      * WARNING: Do NOT modify this code. The content of this method is always
  44.      * regenerated by the Form Editor.
  45.      */
  46.     @SuppressWarnings("unchecked")
  47.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  48.     private void initComponents() {
  49.  
  50.         jScrollPane1 = new javax.swing.JScrollPane();
  51.         jTable1 = new javax.swing.JTable();
  52.         buttonGroup1 = new javax.swing.ButtonGroup();
  53.         jTextField1 = new javax.swing.JTextField();
  54.         jTextField2 = new javax.swing.JTextField();
  55.         jTextField3 = new javax.swing.JTextField();
  56.         jScrollPane2 = new javax.swing.JScrollPane();
  57.         jTable2 = new javax.swing.JTable();
  58.         jButton1 = new javax.swing.JButton();
  59.         jButton2 = new javax.swing.JButton();
  60.         jButton3 = new javax.swing.JButton();
  61.         jButton4 = new javax.swing.JButton();
  62.         jRadioButton1 = new javax.swing.JRadioButton();
  63.         jLabel1 = new javax.swing.JLabel();
  64.  
  65.         jTable1.setModel(new javax.swing.table.DefaultTableModel(
  66.             new Object [][] {
  67.                 {null, null, null, null},
  68.                 {null, null, null, null},
  69.                 {null, null, null, null},
  70.                 {null, null, null, null}
  71.             },
  72.             new String [] {
  73.                 "Title 1", "Title 2", "Title 3", "Title 4"
  74.             }
  75.         ));
  76.         jScrollPane1.setViewportView(jTable1);
  77.  
  78.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  79.  
  80.         jTextField1.addActionListener(new java.awt.event.ActionListener() {
  81.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  82.                 jTextField1ActionPerformed(evt);
  83.             }
  84.         });
  85.  
  86.         jTable2.setModel(new javax.swing.table.DefaultTableModel(
  87.             new Object [][] {
  88.  
  89.             },
  90.             new String [] {
  91.                 "Broj nogu", "Gorivo", "Lep"
  92.             }
  93.         ));
  94.         jScrollPane2.setViewportView(jTable2);
  95.  
  96.         jButton1.setText("F1");
  97.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  98.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  99.                 jButton1ActionPerformed(evt);
  100.             }
  101.         });
  102.  
  103.         jButton2.setText("F2");
  104.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  105.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  106.                 jButton2ActionPerformed(evt);
  107.             }
  108.         });
  109.  
  110.         jButton3.setText("Save");
  111.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  112.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  113.                 jButton3ActionPerformed(evt);
  114.             }
  115.         });
  116.  
  117.         jButton4.setText("Read");
  118.         jButton4.addActionListener(new java.awt.event.ActionListener() {
  119.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  120.                 jButton4ActionPerformed(evt);
  121.             }
  122.         });
  123.  
  124.         buttonGroup1.add(jRadioButton1);
  125.         jRadioButton1.setSelected(true);
  126.         jRadioButton1.setText("jRadioButton1");
  127.  
  128.         jLabel1.setFont(new java.awt.Font("Trebuchet MS", 3, 36)); // NOI18N
  129.  
  130.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  131.         getContentPane().setLayout(layout);
  132.         layout.setHorizontalGroup(
  133.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  134.             .addGroup(layout.createSequentialGroup()
  135.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  136.                     .addGroup(layout.createSequentialGroup()
  137.                         .addGap(102, 102, 102)
  138.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  139.                             .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
  140.                             .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
  141.                             .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
  142.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143.                             .addGroup(layout.createSequentialGroup()
  144.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 225, Short.MAX_VALUE)
  145.                                 .addComponent(jButton3))
  146.                             .addGroup(layout.createSequentialGroup()
  147.                                 .addGap(63, 63, 63)
  148.                                 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  149.                     .addGroup(layout.createSequentialGroup()
  150.                         .addGap(0, 0, Short.MAX_VALUE)
  151.                         .addComponent(jButton1)))
  152.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153.                     .addGroup(layout.createSequentialGroup()
  154.                         .addGap(131, 131, 131)
  155.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  156.                             .addComponent(jButton2)
  157.                             .addComponent(jButton4))
  158.                         .addGap(48, 48, 48))
  159.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  160.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  161.                         .addComponent(jRadioButton1)
  162.                         .addGap(39, 39, 39))))
  163.             .addGroup(layout.createSequentialGroup()
  164.                 .addGap(49, 49, 49)
  165.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
  166.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  167.         );
  168.         layout.setVerticalGroup(
  169.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170.             .addGroup(layout.createSequentialGroup()
  171.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  172.                     .addGroup(layout.createSequentialGroup()
  173.                         .addContainerGap()
  174.                         .addComponent(jButton1)
  175.                         .addGap(8, 8, 8)
  176.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  177.                             .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  178.                             .addComponent(jButton3))
  179.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  180.                             .addGroup(layout.createSequentialGroup()
  181.                                 .addGap(18, 18, 18)
  182.                                 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  183.                                 .addGap(30, 30, 30)
  184.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  185.                                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  186.                                     .addComponent(jRadioButton1)))
  187.                             .addGroup(layout.createSequentialGroup()
  188.                                 .addGap(26, 26, 26)
  189.                                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))))
  190.                     .addGroup(layout.createSequentialGroup()
  191.                         .addGap(20, 20, 20)
  192.                         .addComponent(jButton2)
  193.                         .addGap(9, 9, 9)
  194.                         .addComponent(jButton4)))
  195.                 .addGap(18, 18, 18)
  196.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
  197.                 .addContainerGap(44, Short.MAX_VALUE))
  198.         );
  199.  
  200.         pack();
  201.     }// </editor-fold>                        
  202.  
  203.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  204.  
  205.     }                                          
  206.  
  207.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  208.         JFileChooser jfk = new JFileChooser();
  209.         jfk.showSaveDialog(this);
  210.         input = jfk.getSelectedFile();
  211.     }                                        
  212.  
  213.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  214.         JFileChooser jfk = new JFileChooser();
  215.         jfk.showOpenDialog(this);
  216.         output = jfk.getSelectedFile();
  217.        
  218.     }                                        
  219.  
  220.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  221.         Zirafa pas1 = null;
  222.         Pas zirafa1 = null;
  223.        
  224.         if(jRadioButton1.isSelected()){
  225.             pas1 = new Zirafa(jTextField1.getText(), jTextField2.getText(), jTextField3.getText());
  226.         }
  227.         else{
  228.             zirafa1 = new Pas();
  229.         }
  230.        
  231.         try {
  232.             FileWriter fw = new FileWriter(input, true);
  233.             BufferedWriter bw = new BufferedWriter(fw);
  234.            
  235.             bw.append(pas1.stampaj());
  236.             bw.newLine();
  237.             bw.close();
  238.            
  239.         } catch (IOException ex) {
  240.             Logger.getLogger(GUIIspit.class.getName()).log(Level.SEVERE, null, ex);
  241.         }
  242.  
  243.     }                                        
  244.  
  245.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  246.          DefaultTableModel dtm = new DefaultTableModel();
  247.          dtm.addColumn("Broj nogu");
  248.          dtm.addColumn("Gorivo");
  249.          dtm.addColumn("Lyijep");
  250.          
  251.         try {
  252.             FileInputStream fis = new FileInputStream(output);
  253.             BufferedReader br = new BufferedReader(new InputStreamReader(fis));
  254.            
  255.             String red = "";
  256.            
  257.             while((red = br.readLine()) != null){
  258.                 dtm.addRow(red.split("/"));
  259.             }
  260.            
  261.             br.close();
  262.            
  263.         } catch (FileNotFoundException ex) {
  264.             Logger.getLogger(GUIIspit.class.getName()).log(Level.SEVERE, null, ex);
  265.         } catch (IOException ex) {
  266.             Logger.getLogger(GUIIspit.class.getName()).log(Level.SEVERE, null, ex);
  267.         }
  268.         this.jTable2.setModel(dtm);
  269.     }                                        
  270.  
  271.     /**
  272.      * @param args the command line arguments
  273.      */
  274.     public static void main(String args[]) {
  275.         /* Set the Nimbus look and feel */
  276.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  277.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  278.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  279.          */
  280.         try {
  281.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  282.                 if ("Nimbus".equals(info.getName())) {
  283.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  284.                     break;
  285.                 }
  286.             }
  287.         } catch (ClassNotFoundException ex) {
  288.             java.util.logging.Logger.getLogger(GUIIspit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  289.         } catch (InstantiationException ex) {
  290.             java.util.logging.Logger.getLogger(GUIIspit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  291.         } catch (IllegalAccessException ex) {
  292.             java.util.logging.Logger.getLogger(GUIIspit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  293.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  294.             java.util.logging.Logger.getLogger(GUIIspit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  295.         }
  296.         //</editor-fold>
  297.  
  298.         /* Create and display the form */
  299.         java.awt.EventQueue.invokeLater(new Runnable() {
  300.             public void run() {
  301.                 new GUIIspit().setVisible(true);
  302.             }
  303.         });
  304.     }
  305.  
  306.     // Variables declaration - do not modify                    
  307.     private javax.swing.ButtonGroup buttonGroup1;
  308.     private javax.swing.JButton jButton1;
  309.     private javax.swing.JButton jButton2;
  310.     private javax.swing.JButton jButton3;
  311.     private javax.swing.JButton jButton4;
  312.     private javax.swing.JLabel jLabel1;
  313.     private javax.swing.JRadioButton jRadioButton1;
  314.     private javax.swing.JScrollPane jScrollPane1;
  315.     private javax.swing.JScrollPane jScrollPane2;
  316.     private javax.swing.JTable jTable1;
  317.     private javax.swing.JTable jTable2;
  318.     private javax.swing.JTextField jTextField1;
  319.     private javax.swing.JTextField jTextField2;
  320.     private javax.swing.JTextField jTextField3;
  321.     // End of variables declaration                  
  322. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement