-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathReverseStringEx1.java
More file actions
58 lines (48 loc) · 1.29 KB
/
ReverseStringEx1.java
File metadata and controls
58 lines (48 loc) · 1.29 KB
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
// GUI Program to reverse a string.
package src.college.understanding_GUI;
import java.awt.*;
import java.awt.event.*;
class ReverseStringEx1 extends Frame implements ActionListener {
Label l;
Label l1;
TextField tf;
TextField tf1;
Button b;
ReverseStringEx1(String s) {
super(s);
}
void createWindow() {
l = new Label("enter number");
tf = new TextField(12);
l1 = new Label("output");
tf1 = new TextField(12);
b = new Button("SHOW");
setLayout(new FlowLayout());
add(l);
add(tf);
add(l1);
add(tf1);
add(b);
setSize(200, 400);
setVisible(true);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String str = "";
char ch;
String input = tf.getText();
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
System.out.println(ch);
str = ch + str;
System.out.println(str);
}
System.out.println("H"+"E");
System.out.print("E"+"H");
tf1.setText(str);
}
public static void main(String[] args) {
ReverseStringEx1 p = new ReverseStringEx1("Reverse String");
p.createWindow();
}
}