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);
}
}
Panels: import java.applet.*; import java.awt.*; /*<applet code="PanelDemo" width=300 height=300></applet>*/ public class PanelDemo extends Applet { public void init() { setLayout(new BorderLayout()); Panel pn=new Panel(); Button b1=new Button("Button 1"); pn.add(b1); Button b2=new Button("Button 2"); pn.add(b2); add(pn,"North"); Panel pe=new Panel(); Button b3=new Button("Button 3"); pe.add(b3); add(pe,"East"); Panel pw=new Panel(); Button b4=new Button("Button 4"); pw.add(b4); add(pw,"West"); Panel ps=new Panel(); Button b5=new Button("Button 5"); ps.add(b5); Button b6=new Button("Button 6"); ps.add(b6); add(ps,"South"); } }
Comments
Post a Comment