Write an Applet that ha, 1 text area and 4 options: Message 1 Message 2 Message
ID: 3789369 • Letter: W
Question
Write an Applet that ha, 1 text area and 4 options: Message 1 Message 2 Message 3 Message 4 Radio button, "Message 1" will print to the text area: Hello. Radio button, "Message 2" will print to the text area: How are you. Radio button, "Message 3" will print to the text area: Thus is a test. Radio button, "Message 4" will print to the text area: Any message. Radio Buttons can be replaced by Combo Box. Text area can be replaced by text field by losing 10 points. Each Radio button can be replaced by button by losing 10 points.Explanation / Answer
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RadioApplet extends Applet {
JRadioButton r1,r2,r3,r4;
Container con;
JComboBox jc1;
JTextField tf1,tf2,tf3,tf4;
JTextArea jt;
JButton jb1,jb2,jb3,jb4;
RadioApplet(){
r1 = new JRadioButton("Message1");
r2 = new JRadioButton("Message2");
r3 = new JRadioButton("Mesage3");
r4 = new JRadioButton("Message4");
jt = new JTextArea();
con.add(r1);
con.add(r2);
con.add(r3);
con.add(r4);
con.add(tf1);
con.add(tf2);
con.add(tf3);
con.add(tf4);
con.add(jt);
con.add(jb1);
con.add(jb2);
con.add(jb3);
con.add(jb4);
}
class MyAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource()==r1){
jt.setText("hello");
}else if(e.getSource()==r2){
jt.setText("How are you");
}else if(e.getSource()==r3){
jt.setText("This is a test");
}else if(e.getSource()==r4){
jt.setText("AnyMesage");
}
}
}
public void init(){
RadioApplet rd = new RadioApplet();
}
public void start(){
System.out.println("started");
}
}/*
<applet code="RadioApplet.class" width="350" height="400">
</applet>
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.