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]
Answers were Sorted based on User's Feedback
Answer / sriharsha gowda
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(ae.getSource()==b1) setBackground(Color.yellow);
if(ae.getSource()==b2) setBackground(Color.blue);
if(ae.getSource()==b3) setBackground(Color.pink);
}
The above code can be used whenever we have different buttons and when any button is clicked its color changes accordingly
Is This Answer Correct ? | 8 Yes | 2 No |
Answer / 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 |
What are the disadvantages of object oriented programming?
what do you understand by synchronization? : Java thread
When object is created and destroyed?
Is there any difference between synchronized methods and synchronized statements?
What does system out println () do?
what is multitherading
What is arraylist e?
what is request dispatcher and how does it work?
JVM responsibility?
What is difference between iterator and enumeration in java?
what is use of session tracking ?with example?
If you are reviewing the code of your team members, what points will you look at, assuming the performance of the application is not so great