-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ19.java
47 lines (46 loc) · 1.42 KB
/
Q19.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
/*
* 19. Design an applet to do the following tasks:
* a) To output the question “WHO IS THE PRIME MINISTER OF INDIA?”
* b) To accept the answer and print “CORRECT” and then stop if the answer is correct.
* c) To print “TRY AGAIN” and if the answer is not correct.
* d) To display the correct answer, if the answer is wrong even after third attempt.
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/* <applet code=Q19 width=400 height=100></applet> */
public class Q19 extends Applet implements ActionListener {
String ans="";
Button sub;
TextField tf1;
int count=0;
public void init() {
Label f=new Label("ENTER PRIME MINISTER NAME", Label.RIGHT);
tf1=new TextField(10);
add(f);
add(tf1);
sub=new Button("SUBMIT");
add(sub);
sub.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String name=tf1.getText();
if(ae.getSource()==sub) {
if(name.equals("Narendra Modi")) {
ans="CORRECT";
sub.setEnabled(false);
}
else {
ans="INCORRECT";
count++;
if(count==3) {
ans="NAME OF PRIME MINISTER IS Sh. NARENDRA MODI";
}
}
}
repaint();
}
public void paint(Graphics g) {
g.drawString(ans,10,100);
}
}