-
Notifications
You must be signed in to change notification settings - Fork 4
/
Reverse.java
66 lines (54 loc) · 1.62 KB
/
Reverse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Frame extends JFrame implements ActionListener {
JButton b1;
JTextField tx, tx1;
JLabel l1, l2;
Container c;
Frame() {
c = getContentPane();
c.setLayout(null);
l1 = new JLabel("Enter the String");
l1.setBounds(50, 100, 200, 50);
c.add(l1);
tx = new JTextField();
tx.setBounds(200, 100, 150, 30);
c.add(tx);
l2 = new JLabel("Reversed");
l2.setBounds(50, 150, 150, 50);
c.add(l2);
tx1 = new JTextField();
tx1.setBounds(200, 150, 150, 30);
c.add(tx1);
b1 = new JButton("REVERSE");
b1.addActionListener(this);
b1.setBounds(150, 200, 100, 50);
c.add(b1);
}
public void actionPerformed(ActionEvent ae) {
String str = ae.getActionCommand();
if (str == "REVERSE") {
String s = tx.getText();
String[] words = s.split(" ");
String reverseString = "";
for (int i = 0; i < words.length; i++) {
String word = words[i];
String reverseWord = "";
for (int j = word.length() - 1; j >= 0; j--) {
reverseWord = reverseWord + word.charAt(j);
}
reverseString = reverseString + reverseWord + " ";
}
tx1.setText(reverseString);
}
}
}
class Reverse {
public static void main(String args[]) {
Frame f = new Frame();
f.setTitle("REVERSE");
f.setSize(400, 400);
f.setVisible(true);
}
}