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



What is the code inside the public void actionPerformed(ActionEvent ae) override method in Applet ..

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

What is the code inside the public void actionPerformed(ActionEvent ae) override method in Applet ..

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

Post New Answer

More Core Java Interview Questions

Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result? 1 Compilation fails because of an error in line 25. 2 The code runs with no output. 3 An exception is thrown at runtime. 4 Compilation fails because of an error in line 20.

3 Answers  


What is the final keyword in java?

0 Answers  


What is a java string?

0 Answers  


Do I need java on my computer?

0 Answers  


How is hashcode calculated in java?

0 Answers  






Can list contain null in java?

0 Answers  


What are the escape sequences in java?

0 Answers  


What is persistence ?

2 Answers  


Are maps ordered java?

0 Answers  


What happens when I use / and % with a negative numerator?

0 Answers  


What are thread groups?

0 Answers  


give an example for encapsulation?

0 Answers   Aspire,


Categories