-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab24.java
More file actions
78 lines (72 loc) · 2.09 KB
/
Copy pathjavalab24.java
File metadata and controls
78 lines (72 loc) · 2.09 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Scanner;
class guiDemo extends JFrame implements ActionListener{
private JTextField t1;
private JTextField t2;
private JButton b1;
private JButton b2;
private JButton b3;
public guiDemo(){
createView();
setTitle("Vowel COunter");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 150);
setLocationRelativeTo(null);
setResizable(true);
setVisible(true);
}
private void createView(){
JPanel panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(new FlowLayout());
JLabel l1 = new JLabel("Enter a String: ");
t1 = new JTextField(100);
JLabel l2 = new JLabel("Number of vowels: ");
t2 = new JTextField(100);
t2.setEditable(false);
b1 = new JButton("countButton");
// b1.addActionListener(new CountVowel());
b2 = new JButton("resetButton");
b3 = new JButton("Exit");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
panel.add(l1);
panel.add(t1);
panel.add(l2);
panel.add(t2);
panel.add(b1);
panel.add(b2);
panel.add(b3);
add(panel);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==b1){
System.out.println("Count button clicked");
String st = t1.getText().toLowerCase();
int count=0;
for(char c : st.toCharArray()){
if("aeiou".indexOf(c)!=-1){
count++;
}
}
t2.setText(count + "");
}
else if(ae.getSource()==b2){
t1.setText("");
t2.setText("");
t1.requestFocus();
}
else if(ae.getSource()==b3){
System.exit(0);
}
}
}
public class javalab24 {
public static void main(String[] args) {
guiDemo ob = new guiDemo();
}
}