Choices:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="ChoiceDemo" width=300 height=300></applet>*/
public class ChoiceDemo extends Applet implements ItemListener
{
Label l1;
public void init()
{
Choice c1=new Choice();
c1.addItem("Red");
c1.addItem("Green");
c1.addItem("Blue");
c1.addItem("Yellow");
c1.addItem("Orange");
c1.addItem("Gray");
c1.addItem("Pink");
c1.addItemListener(this);
add(c1);
}
public void itemStateChanged(ItemEvent ie)
{
Choice c=(Choice)ie.getItemSelectable();
String s=c.getSelectedItem();
if(s.equals("Red"))
setBackground(Color.red);
else if(s.equals("Green"))
setBackground(Color.green);
else if(s.equals("Blue"))
setBackground(Color.blue);
else if(s.equals("Yellow"))
setBackground(Color.yellow);
else if(s.equals("Orange"))
setBackground(Color.orange);
else if(s.equals("Gray"))
setBackground(Color.gray);
else if(s.equals("Pink"))
setBackground(Color.pink);
}
}
46. What is Constructor? A constructor is a special method whose task is to initialize the object of its class. It is special because its name is the same as the class name. They do not have return types, not even void and therefore they cannot return values. They cannot be inherited, though a derived class can call the base class constructor. Constructor is invoked whenever an object of its associated class is created. 47. What is an Iterator ? The Iterator interface is used to step through the elements of a Collection. Iterators let you process each element of a Collection. Iterators are a generic way to go through all the elements of a Collection no matter how it is organized. Iterator is an Interface implemented a different way for every Collection. 48. What is the List interface? The List interface provides support for ordered collections of objects. Lists may contain duplicate elements. 49. What is memory leak? A memory leak is where an unreferenced object that will ne...
Comments
Post a Comment