99 * @license Apache (http://www.apache.org/licenses/LICENSE-2.0)
1010 * @create 2012-05-04
1111 * @update 2015-09-4
12- *
13- *
12+ *
13+ *
1414 * @modifiedby Achintha Gunasekara
1515 * @modweb http://www.achinthagunasekara.com
1616 * @modemail contact@achinthagunasekara.com
2626
2727public class Find extends JFrame implements ActionListener {
2828
29- private static final long serialVersionUID = 1L ;
30- int startIndex =0 ;
29+ private static final long serialVersionUID = 1L ;
30+ int startIndex =0 ;
3131 int select_start =-1 ;
3232 JLabel lab1 , lab2 ;
3333 JTextField textF , textR ;
34- JButton findBtn , findNext , replace , replaceAll , cancel ;
34+ JButton findBtn , findNext , replace , replaceAll , cancel ;
3535 private JTextArea txt ;
36-
37-
38- public Find (JTextArea text ) {
39- this .txt = text ;
40-
36+
37+
38+ public Find (JTextArea text ) {
39+ this .txt = text ;
40+
4141 lab1 = new JLabel ("Find:" );
4242 lab2 = new JLabel ("Replace:" );
4343 textF = new JTextField (30 );
@@ -47,14 +47,14 @@ public Find(JTextArea text) {
4747 replace = new JButton ("Replace" );
4848 replaceAll = new JButton ("Replace All" );
4949 cancel = new JButton ("Cancel" );
50-
50+
5151 // Set Layout NULL
5252 setLayout (null );
53-
53+
5454 // Set the width and height of the label
5555 int labWidth = 80 ;
5656 int labHeight = 20 ;
57-
57+
5858 // Adding labels
5959 lab1 .setBounds (10 ,10 , labWidth , labHeight );
6060 add (lab1 );
@@ -64,45 +64,45 @@ public Find(JTextArea text) {
6464 add (lab2 );
6565 textR .setBounds (10 +labWidth , 10 +labHeight +10 , 120 , 20 );
6666 add (textR );
67-
67+
6868 // Adding buttons
6969 findBtn .setBounds (225 , 6 , 115 , 20 );
7070 add (findBtn );
7171 findBtn .addActionListener (this );
72-
72+
7373 findNext .setBounds (225 , 28 , 115 , 20 );
7474 add (findNext );
7575 findNext .addActionListener (this );
76-
76+
7777 replace .setBounds (225 , 50 , 115 , 20 );
7878 add (replace );
7979 replace .addActionListener (this );
80-
80+
8181 replaceAll .setBounds (225 , 72 , 115 , 20 );
8282 add (replaceAll );
8383 replaceAll .addActionListener (this );
84-
84+
8585 cancel .setBounds (225 , 94 , 115 , 20 );
8686 add (cancel );
8787 cancel .addActionListener (this );
88-
89-
88+
89+
9090 // Set the width and height of the window
9191 int width = 360 ;
9292 int height = 160 ;
93-
93+
9494 // Set size window
9595 setSize (width ,height );
96-
96+
9797 // Set window position
9898 Point center = GraphicsEnvironment .getLocalGraphicsEnvironment ().getCenterPoint ();
9999 setLocation (center .x -width /2 , center .y -height /2 );
100100 setVisible (true );
101- setDefaultCloseOperation (JFrame .HIDE_ON_CLOSE );
101+ setDefaultCloseOperation (JFrame .HIDE_ON_CLOSE );
102102 }
103-
103+
104104 public void find () {
105- select_start = txt .getText ().toLowerCase ().indexOf (textF .getText ().toLowerCase ());
105+ select_start = txt .getText ().toLowerCase ().indexOf (textF .getText ().toLowerCase ());
106106 if (select_start == -1 )
107107 {
108108 startIndex = 0 ;
@@ -112,11 +112,11 @@ public void find() {
112112 if (select_start == txt .getText ().toLowerCase ().lastIndexOf (textF .getText ().toLowerCase ()))
113113 {
114114 startIndex = 0 ;
115- }
115+ }
116116 int select_end = select_start + textF .getText ().length ();
117117 txt .select (select_start , select_end );
118118 }
119-
119+
120120 public void findNext () {
121121 String selection = txt .getSelectedText ();
122122 try
@@ -142,7 +142,7 @@ public void findNext() {
142142 int select_end = select_start +selection .length ();
143143 txt .select (select_start , select_end );
144144 startIndex = select_end +1 ;
145-
145+
146146 if (select_start == txt .getText ().toLowerCase ().lastIndexOf (selection .toLowerCase ()))
147147 {
148148 startIndex = 0 ;
@@ -151,7 +151,7 @@ public void findNext() {
151151 catch (NullPointerException e )
152152 {}
153153 }
154-
154+
155155 public void replace () {
156156 try
157157 {
@@ -162,10 +162,10 @@ public void replace() {
162162 catch (NullPointerException e )
163163 {
164164 System .out .print ("Null Pointer Exception: " +e );
165- }
165+ }
166166 }
167-
168- public void replaceAll () {
167+
168+ public void replaceAll () {
169169 txt .setText (txt .getText ().toLowerCase ().replaceAll (textF .getText ().toLowerCase (), textR .getText ()));
170170 }
171171
@@ -191,5 +191,5 @@ else if(e.getSource() == cancel)
191191 this .setVisible (false );
192192 }
193193 }
194-
194+
195195}
0 commit comments