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
Explain the difference between jdk, jre, and jvm?
What is enhanced loop in java?
What is starvation?
How to sort an array in java without using sort method?
State the main difference between c++ and java?
Is string is a data type?
Is java 1.7 the same as java 7?
I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?
What do you mean by compiler?
What is meant by memory leak?
What are the topics in core java?
What is static and final keyword in java?
What do you understand by classes in java?
Can you instantiate the math class?
What is a line break?