What is the code inside the public void
actionPerformed(ActionEvent ae) override method in Applet
[ Condition:- you have one TextField and One Button , you
have to enter any color name inside the TextField, when you
click on Button Your background will change according to
your input color name]

Answer Posted / santoshi

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.Color.*;
import java.event.*;
class Mypro
{
JFrame jf;
JPanel jp;
Jlabel jl;
JTextField tf;
JButton jb;
public static void main(String n[])
{
Mypro m=new Mypro();
}
public Mypro()
{
jf=new JFrame("MY own");
jp=new JPanel();
jf.add(jp);
jl=new JLabel("enter the color");
jp.add(jl);
tf=new JTextField(8);
jp.add(jf);
jb= new JButton("clikc");
jp.add(jb);
jf.setVisible(true);
jf.setSize(500,500);
}
public void actionPerformed(actionEvent ae)
{
Object o=ae.getSource();
String gt=tf.getText();
if(o==jb)
{
if(gt=="red")
setBackground(Color.red);
if(gt=="yellow")
setBackground(Color.yellow);
}
}
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we execute a program without main?

746


What is oop principle in java?

738


Why are there no global variables in java?

785


Is it possible to override the main method?

726


What is boolean query?

746


what is the use of bean managed and container managed with example?

1731


What are the main differences between the java platform and other platforms?

751


What are autoboxing and unboxing? When does it occur?

700


What is a ternary operator in java? What is an interface?

760


What is difference between add() and addelement() in vector?

1294


In case of inheritance what is the execution order of constructor and destructor?

868


What does a method signature consist of?

713


What is arrays fill in java?

743


Is array passed by reference in java?

790


What are static variables and functions?

823