Advertisement
Guest User

Notepad

a guest
Dec 30th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.70 KB | None | 0 0
  1. // Frame.java
  2.  
  3.  
  4. import java.awt.Color;
  5. import java.util.Scanner;
  6. import javax.swing.*;
  7. import java.awt.Event.*;
  8. import java.io.*;
  9. import javax.swing.text.BadLocationException;
  10. import javax.swing.text.DefaultHighlighter;
  11. import javax.swing.text.Document;
  12. import javax.swing.text.Highlighter;
  13. import javax.swing.text.SimpleAttributeSet;
  14. import javax.swing.text.StyleConstants;
  15. import javax.swing.undo.UndoManager;
  16.  
  17. public class Frame extends javax.swing.JFrame {
  18.  
  19.     /**
  20.      * Creates new form Frame
  21.      */
  22.    
  23.     UndoManager um;
  24.     private int pos;
  25.     public Frame() {
  26.         initComponents();
  27.         um = new UndoManager();
  28.         jTextPane1.getDocument().addUndoableEditListener(um);
  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.         jMenuItem12 = new javax.swing.JMenuItem();
  41.         jScrollPane2 = new javax.swing.JScrollPane();
  42.         jTextPane1 = new javax.swing.JTextPane();
  43.         jMenuBar1 = new javax.swing.JMenuBar();
  44.         jMenu1 = new javax.swing.JMenu();
  45.         jMenuItem1 = new javax.swing.JMenuItem();
  46.         jMenuItem2 = new javax.swing.JMenuItem();
  47.         jSeparator2 = new javax.swing.JPopupMenu.Separator();
  48.         jMenuItem3 = new javax.swing.JMenuItem();
  49.         jMenuItem4 = new javax.swing.JMenuItem();
  50.         jSeparator1 = new javax.swing.JPopupMenu.Separator();
  51.         jMenuItem5 = new javax.swing.JMenuItem();
  52.         jMenu2 = new javax.swing.JMenu();
  53.         jMenuItem6 = new javax.swing.JMenuItem();
  54.         jMenuItem7 = new javax.swing.JMenuItem();
  55.         jSeparator3 = new javax.swing.JPopupMenu.Separator();
  56.         jMenuItem8 = new javax.swing.JMenuItem();
  57.         jMenuItem9 = new javax.swing.JMenuItem();
  58.         jMenuItem10 = new javax.swing.JMenuItem();
  59.         jSeparator4 = new javax.swing.JPopupMenu.Separator();
  60.         jMenuItem11 = new javax.swing.JMenuItem();
  61.         jMenu4 = new javax.swing.JMenu();
  62.         jMenuItem14 = new javax.swing.JMenuItem();
  63.         jMenu3 = new javax.swing.JMenu();
  64.         jMenuItem13 = new javax.swing.JMenuItem();
  65.  
  66.         jMenuItem12.setText("jMenuItem12");
  67.  
  68.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  69.  
  70.         jScrollPane2.setViewportView(jTextPane1);
  71.  
  72.         jMenu1.setText("Datoteka");
  73.  
  74.         jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
  75.         jMenuItem1.setText("Novi");
  76.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  77.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  78.                 jMenuItem1ActionPerformed(evt);
  79.             }
  80.         });
  81.         jMenu1.add(jMenuItem1);
  82.  
  83.         jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
  84.         jMenuItem2.setText("Otvori");
  85.         jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
  86.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  87.                 jMenuItem2ActionPerformed(evt);
  88.             }
  89.         });
  90.         jMenu1.add(jMenuItem2);
  91.         jMenu1.add(jSeparator2);
  92.  
  93.         jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
  94.         jMenuItem3.setText("Spremi");
  95.         jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
  96.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  97.                 jMenuItem3ActionPerformed(evt);
  98.             }
  99.         });
  100.         jMenu1.add(jMenuItem3);
  101.  
  102.         jMenuItem4.setText("Spremi kao");
  103.         jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
  104.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  105.                 jMenuItem4ActionPerformed(evt);
  106.             }
  107.         });
  108.         jMenu1.add(jMenuItem4);
  109.         jMenu1.add(jSeparator1);
  110.  
  111.         jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
  112.         jMenuItem5.setText("Izađi");
  113.         jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
  114.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  115.                 jMenuItem5ActionPerformed(evt);
  116.             }
  117.         });
  118.         jMenu1.add(jMenuItem5);
  119.  
  120.         jMenuBar1.add(jMenu1);
  121.  
  122.         jMenu2.setText("Uredi");
  123.  
  124.         jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
  125.         jMenuItem6.setText("Nazad");
  126.         jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
  127.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  128.                 jMenuItem6ActionPerformed(evt);
  129.             }
  130.         });
  131.         jMenu2.add(jMenuItem6);
  132.  
  133.         jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
  134.         jMenuItem7.setText("Naprijed");
  135.         jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
  136.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  137.                 jMenuItem7ActionPerformed(evt);
  138.             }
  139.         });
  140.         jMenu2.add(jMenuItem7);
  141.         jMenu2.add(jSeparator3);
  142.  
  143.         jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
  144.         jMenuItem8.setText("Izreži");
  145.         jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
  146.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  147.                 jMenuItem8ActionPerformed(evt);
  148.             }
  149.         });
  150.         jMenu2.add(jMenuItem8);
  151.  
  152.         jMenuItem9.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
  153.         jMenuItem9.setText("Kopiraj");
  154.         jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
  155.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  156.                 jMenuItem9ActionPerformed(evt);
  157.             }
  158.         });
  159.         jMenu2.add(jMenuItem9);
  160.  
  161.         jMenuItem10.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
  162.         jMenuItem10.setText("Zalijepi");
  163.         jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
  164.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  165.                 jMenuItem10ActionPerformed(evt);
  166.             }
  167.         });
  168.         jMenu2.add(jMenuItem10);
  169.         jMenu2.add(jSeparator4);
  170.  
  171.         jMenuItem11.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
  172.         jMenuItem11.setText("Selektuj sve");
  173.         jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
  174.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  175.                 jMenuItem11ActionPerformed(evt);
  176.             }
  177.         });
  178.         jMenu2.add(jMenuItem11);
  179.  
  180.         jMenuBar1.add(jMenu2);
  181.  
  182.         jMenu4.setText("Pretraga");
  183.  
  184.         jMenuItem14.setText("Traži");
  185.         jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
  186.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  187.                 jMenuItem14ActionPerformed(evt);
  188.             }
  189.         });
  190.         jMenu4.add(jMenuItem14);
  191.  
  192.         jMenuBar1.add(jMenu4);
  193.  
  194.         jMenu3.setText("Pomoć");
  195.  
  196.         jMenuItem13.setText("O programu");
  197.         jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
  198.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  199.                 jMenuItem13ActionPerformed(evt);
  200.             }
  201.         });
  202.         jMenu3.add(jMenuItem13);
  203.  
  204.         jMenuBar1.add(jMenu3);
  205.  
  206.         setJMenuBar(jMenuBar1);
  207.  
  208.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  209.         getContentPane().setLayout(layout);
  210.         layout.setHorizontalGroup(
  211.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  212.             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)
  213.         );
  214.         layout.setVerticalGroup(
  215.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  216.             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
  217.         );
  218.  
  219.         pack();
  220.     }// </editor-fold>                        
  221.     Boolean spremljeno = true;
  222.     BufferedWriter datoteka;
  223.     JFileChooser spremi;
  224.     JFileChooser otvori;
  225.        
  226.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  227.         if(spremljeno == true){
  228.             jTextPane1.setText("");
  229.             spremljeno = false;
  230.         }
  231.         if(spremljeno == false){
  232.             int opcija = JOptionPane.showConfirmDialog(null,
  233.                     "Datoteka nije spremljena, želite li nastaviti?", "Datoteka nije spremljena!",
  234.                     JOptionPane.YES_NO_OPTION);
  235.             if(opcija==JOptionPane.YES_OPTION){
  236.                 jTextPane1.setText("");
  237.                 spremljeno = false;
  238.             }
  239.            
  240.         }
  241.     }                                          
  242.  
  243.     private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  244.         otvori = new JFileChooser();
  245.         int opcija = otvori.showOpenDialog(this);
  246.         izlaz:
  247.         if(opcija == JFileChooser.APPROVE_OPTION){
  248.            
  249.            if(spremljeno == true){
  250.             jTextPane1.setText("");
  251.             spremljeno = false;
  252.         }
  253.         if(spremljeno == false){
  254.             int opcija1 = JOptionPane.showConfirmDialog(null,
  255.                     "Datoteka nije spremljena, želite li nastaviti?", "Datoteka nije spremljena!",
  256.                     JOptionPane.YES_NO_OPTION);
  257.             if(opcija1==JOptionPane.YES_OPTION){
  258.                 jTextPane1.setText("");
  259.                 spremljeno = false;
  260.             }
  261.             else{
  262.                 break izlaz;
  263.             }
  264.            
  265.         }
  266.            try{
  267.            Scanner ulaz = new Scanner(new FileReader(otvori.getSelectedFile().getPath()));
  268.            while(ulaz.hasNext()){
  269.                jTextPane1.setText(ulaz.nextLine()+"\n");
  270.            }
  271.            }
  272.            catch(Exception e){
  273.                System.out.println(e.getMessage());
  274.  
  275.                
  276.            }
  277.            
  278.            
  279.         }
  280.     }                                          
  281.  
  282.     private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  283.         this.dispose();
  284.     }                                          
  285.  
  286.     private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  287.         spremi = new JFileChooser();
  288.         int opcija = spremi.showSaveDialog(this);
  289.         try{
  290.         datoteka = new BufferedWriter(new FileWriter(spremi.getSelectedFile().getAbsoluteFile()));
  291.         String tekst = jTextPane1.getText();
  292.        
  293.         datoteka.write(tekst);
  294.         datoteka.close();
  295.         spremljeno = true;
  296.         }
  297.         catch(Exception e){
  298.             System.out.println(e.getMessage());
  299.         }
  300.     }                                          
  301.  
  302.     private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  303.         if(datoteka == null){
  304.             jMenuItem4ActionPerformed(evt);
  305.         }
  306.         else {
  307.             try{
  308.             datoteka = new BufferedWriter(new FileWriter(spremi.getSelectedFile().getAbsoluteFile()));
  309.         String tekst = jTextPane1.getText();
  310.        
  311.         datoteka.write(tekst);
  312.         datoteka.close();
  313.         spremljeno = true;}
  314.             catch(Exception e){
  315.                 System.out.println(e.getMessage());
  316.             }
  317.         }
  318.     }                                          
  319.  
  320.     private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  321.         if(um.canUndo()){
  322.             um.undo();
  323.         }
  324.        
  325.     }                                          
  326.  
  327.     private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  328.         jTextPane1.copy();
  329.     }                                          
  330.  
  331.     private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  332.         jTextPane1.paste();
  333.     }                                          
  334.  
  335.     private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  336.         jTextPane1.selectAll();
  337.     }                                          
  338.  
  339.     private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  340.         jTextPane1.cut();
  341.     }                                          
  342.  
  343.     private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  344.         if(um.canRedo()){
  345.             um.redo();
  346.         }
  347.     }                                          
  348.  
  349.     private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  350.         About a = new About();
  351.         a.show();
  352.     }                                          
  353.    
  354.     public void traziJedan(String rijec){
  355.        
  356.         try{
  357.         Highlighter h = jTextPane1.getHighlighter();
  358.         h.removeAllHighlights();
  359.         String text = jTextPane1.getText();
  360.         String pattern = rijec;
  361.         int pos = 0;
  362.        
  363.         while ((pos = text.indexOf(pattern, pos)) >= 0) {
  364.                
  365.                 h.addHighlight(pos, pos + pattern.length(), DefaultHighlighter.DefaultPainter);
  366.                 pos += pattern.length();
  367.                 System.out.println(rijec);
  368.             }
  369.        
  370.                
  371.         }
  372.         catch(BadLocationException e){}
  373.     }
  374.    
  375.     private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {                                            
  376.         Trazi t = new Trazi();
  377.         t.show();
  378.     }                                          
  379.  
  380.     /**
  381.      * @param args the command line arguments
  382.      */
  383.     public static void main(String args[]) {
  384.         /* Set the Nimbus look and feel */
  385.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  386.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  387.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  388.          */
  389.         try {
  390.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  391.                 if ("Metal".equals(info.getName())) {
  392.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  393.                     break;
  394.                 }
  395.             }
  396.         } catch (ClassNotFoundException ex) {
  397.             java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  398.         } catch (InstantiationException ex) {
  399.             java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  400.         } catch (IllegalAccessException ex) {
  401.             java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  402.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  403.             java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  404.         }
  405.         //</editor-fold>
  406.  
  407.         /* Create and display the form */
  408.         java.awt.EventQueue.invokeLater(new Runnable() {
  409.             public void run() {
  410.                 new Frame().setVisible(true);
  411.             }
  412.         });
  413.     }
  414.     // Variables declaration - do not modify                    
  415.     private javax.swing.JMenu jMenu1;
  416.     private javax.swing.JMenu jMenu2;
  417.     private javax.swing.JMenu jMenu3;
  418.     private javax.swing.JMenu jMenu4;
  419.     private javax.swing.JMenuBar jMenuBar1;
  420.     private javax.swing.JMenuItem jMenuItem1;
  421.     private javax.swing.JMenuItem jMenuItem10;
  422.     private javax.swing.JMenuItem jMenuItem11;
  423.     private javax.swing.JMenuItem jMenuItem12;
  424.     private javax.swing.JMenuItem jMenuItem13;
  425.     private javax.swing.JMenuItem jMenuItem14;
  426.     private javax.swing.JMenuItem jMenuItem2;
  427.     private javax.swing.JMenuItem jMenuItem3;
  428.     private javax.swing.JMenuItem jMenuItem4;
  429.     private javax.swing.JMenuItem jMenuItem5;
  430.     private javax.swing.JMenuItem jMenuItem6;
  431.     private javax.swing.JMenuItem jMenuItem7;
  432.     private javax.swing.JMenuItem jMenuItem8;
  433.     private javax.swing.JMenuItem jMenuItem9;
  434.     private javax.swing.JScrollPane jScrollPane2;
  435.     private javax.swing.JPopupMenu.Separator jSeparator1;
  436.     private javax.swing.JPopupMenu.Separator jSeparator2;
  437.     private javax.swing.JPopupMenu.Separator jSeparator3;
  438.     private javax.swing.JPopupMenu.Separator jSeparator4;
  439.     private javax.swing.JTextPane jTextPane1;
  440.     // End of variables declaration                  
  441. }
  442.  
  443. // About.java
  444.  
  445.  
  446. /*
  447.  * To change this template, choose Tools | Templates
  448.  * and open the template in the editor.
  449.  */
  450.  
  451. /**
  452.  *
  453.  * @author alen
  454.  */
  455. public class About extends javax.swing.JFrame {
  456.  
  457.     /**
  458.      * Creates new form About
  459.      */
  460.     public About() {
  461.         initComponents();
  462.     }
  463.  
  464.     /**
  465.      * This method is called from within the constructor to initialize the form.
  466.      * WARNING: Do NOT modify this code. The content of this method is always
  467.      * regenerated by the Form Editor.
  468.      */
  469.     @SuppressWarnings("unchecked")
  470.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  471.     private void initComponents() {
  472.  
  473.         jLabel1 = new javax.swing.JLabel();
  474.         jLabel2 = new javax.swing.JLabel();
  475.         jButton1 = new javax.swing.JButton();
  476.  
  477.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  478.  
  479.         jLabel1.setFont(new java.awt.Font("Droid Sans", 1, 24)); // NOI18N
  480.         jLabel1.setText("JavaNotepad v1.3");
  481.  
  482.         jLabel2.setText("Autor: Alen Mašić <alenn.masic@gmail.com>");
  483.  
  484.         jButton1.setText("Zatvori");
  485.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  486.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  487.                 jButton1ActionPerformed(evt);
  488.             }
  489.         });
  490.  
  491.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  492.         getContentPane().setLayout(layout);
  493.         layout.setHorizontalGroup(
  494.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  495.             .addGroup(layout.createSequentialGroup()
  496.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  497.                     .addGroup(layout.createSequentialGroup()
  498.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  499.                             .addGroup(layout.createSequentialGroup()
  500.                                 .addGap(98, 98, 98)
  501.                                 .addComponent(jLabel1))
  502.                             .addGroup(layout.createSequentialGroup()
  503.                                 .addContainerGap()
  504.                                 .addComponent(jLabel2)))
  505.                         .addGap(0, 75, Short.MAX_VALUE))
  506.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  507.                         .addGap(0, 0, Short.MAX_VALUE)
  508.                         .addComponent(jButton1)))
  509.                 .addContainerGap())
  510.         );
  511.         layout.setVerticalGroup(
  512.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  513.             .addGroup(layout.createSequentialGroup()
  514.                 .addContainerGap()
  515.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
  516.                 .addGap(29, 29, 29)
  517.                 .addComponent(jLabel2)
  518.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  519.                 .addComponent(jButton1)
  520.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  521.         );
  522.  
  523.         pack();
  524.     }// </editor-fold>                        
  525.  
  526.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  527.         this.dispose();
  528.     }                                        
  529.  
  530.     /**
  531.      * @param args the command line arguments
  532.      */
  533.     public static void main(String args[]) {
  534.         /* Set the Nimbus look and feel */
  535.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  536.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  537.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  538.          */
  539.         try {
  540.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  541.                 if ("Nimbus".equals(info.getName())) {
  542.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  543.                     break;
  544.                 }
  545.             }
  546.         } catch (ClassNotFoundException ex) {
  547.             java.util.logging.Logger.getLogger(About.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  548.         } catch (InstantiationException ex) {
  549.             java.util.logging.Logger.getLogger(About.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  550.         } catch (IllegalAccessException ex) {
  551.             java.util.logging.Logger.getLogger(About.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  552.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  553.             java.util.logging.Logger.getLogger(About.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  554.         }
  555.         //</editor-fold>
  556.  
  557.         /* Create and display the form */
  558.         java.awt.EventQueue.invokeLater(new Runnable() {
  559.             public void run() {
  560.                 new About().setVisible(true);
  561.             }
  562.         });
  563.     }
  564.     // Variables declaration - do not modify                    
  565.     private javax.swing.JButton jButton1;
  566.     private javax.swing.JLabel jLabel1;
  567.     private javax.swing.JLabel jLabel2;
  568.     // End of variables declaration                  
  569. }
  570.  
  571.  
  572. // Trazi.java
  573.  
  574.  
  575. /*
  576.  * To change this template, choose Tools | Templates
  577.  * and open the template in the editor.
  578.  */
  579.  
  580. /**
  581.  *
  582.  * @author alen
  583.  */
  584. public class Trazi extends javax.swing.JFrame {
  585.  
  586.     /**
  587.      * Creates new form Trazi
  588.      */
  589.     public Trazi() {
  590.         initComponents();
  591.     }
  592.  
  593.     /**
  594.      * This method is called from within the constructor to initialize the form.
  595.      * WARNING: Do NOT modify this code. The content of this method is always
  596.      * regenerated by the Form Editor.
  597.      */
  598.     @SuppressWarnings("unchecked")
  599.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  600.     private void initComponents() {
  601.  
  602.         jTextField1 = new javax.swing.JTextField();
  603.         jTextField2 = new javax.swing.JTextField();
  604.         jButton1 = new javax.swing.JButton();
  605.         jButton2 = new javax.swing.JButton();
  606.         jButton3 = new javax.swing.JButton();
  607.         jButton4 = new javax.swing.JButton();
  608.         jButton5 = new javax.swing.JButton();
  609.         jLabel1 = new javax.swing.JLabel();
  610.         jLabel2 = new javax.swing.JLabel();
  611.  
  612.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  613.  
  614.         jButton1.setText("Traži");
  615.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  616.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  617.                 jButton1ActionPerformed(evt);
  618.             }
  619.         });
  620.  
  621.         jButton2.setText("Traži sve");
  622.  
  623.         jButton3.setText("Zamijeni");
  624.  
  625.         jButton4.setText("Zamijeni sve");
  626.  
  627.         jButton5.setText("Zatvori");
  628.  
  629.         jLabel1.setText("Traži tekst:");
  630.  
  631.         jLabel2.setText("Zamijeni sa:");
  632.  
  633.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  634.         getContentPane().setLayout(layout);
  635.         layout.setHorizontalGroup(
  636.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  637.             .addGroup(layout.createSequentialGroup()
  638.                 .addContainerGap()
  639.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  640.                     .addGroup(layout.createSequentialGroup()
  641.                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
  642.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  643.                         .addComponent(jButton2)
  644.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  645.                         .addComponent(jButton3)
  646.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  647.                         .addComponent(jButton4)
  648.                         .addGap(0, 0, Short.MAX_VALUE))
  649.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  650.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  651.                             .addComponent(jLabel1)
  652.                             .addComponent(jLabel2))
  653.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  654.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  655.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  656.                                 .addGap(0, 0, Short.MAX_VALUE)
  657.                                 .addComponent(jButton5))
  658.                             .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING)
  659.                             .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING))))
  660.                 .addContainerGap())
  661.         );
  662.         layout.setVerticalGroup(
  663.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  664.             .addGroup(layout.createSequentialGroup()
  665.                 .addContainerGap()
  666.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  667.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  668.                     .addComponent(jLabel1))
  669.                 .addGap(18, 18, 18)
  670.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  671.                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  672.                     .addComponent(jLabel2))
  673.                 .addGap(18, 18, 18)
  674.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  675.                     .addComponent(jButton1)
  676.                     .addComponent(jButton2)
  677.                     .addComponent(jButton3)
  678.                     .addComponent(jButton4))
  679.                 .addGap(26, 26, 26)
  680.                 .addComponent(jButton5)
  681.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  682.         );
  683.  
  684.         pack();
  685.     }// </editor-fold>                        
  686.    
  687.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  688.         Frame f = new Frame();
  689.         f.traziJedan(jTextField1.getText());
  690.     }                                        
  691.  
  692.     /**
  693.      * @param args the command line arguments
  694.      */
  695.     public static void main(String args[]) {
  696.         /* Set the Nimbus look and feel */
  697.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  698.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  699.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  700.          */
  701.         try {
  702.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  703.                 if ("Nimbus".equals(info.getName())) {
  704.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  705.                     break;
  706.                 }
  707.             }
  708.         } catch (ClassNotFoundException ex) {
  709.             java.util.logging.Logger.getLogger(Trazi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  710.         } catch (InstantiationException ex) {
  711.             java.util.logging.Logger.getLogger(Trazi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  712.         } catch (IllegalAccessException ex) {
  713.             java.util.logging.Logger.getLogger(Trazi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  714.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  715.             java.util.logging.Logger.getLogger(Trazi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  716.         }
  717.         //</editor-fold>
  718.  
  719.         /* Create and display the form */
  720.         java.awt.EventQueue.invokeLater(new Runnable() {
  721.             public void run() {
  722.                 new Trazi().setVisible(true);
  723.             }
  724.         });
  725.     }
  726.     // Variables declaration - do not modify                    
  727.     private javax.swing.JButton jButton1;
  728.     private javax.swing.JButton jButton2;
  729.     private javax.swing.JButton jButton3;
  730.     private javax.swing.JButton jButton4;
  731.     private javax.swing.JButton jButton5;
  732.     private javax.swing.JLabel jLabel1;
  733.     private javax.swing.JLabel jLabel2;
  734.     private javax.swing.JTextField jTextField1;
  735.     private javax.swing.JTextField jTextField2;
  736.     // End of variables declaration                  
  737. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement