public class Caixa2 extends Applet
{
Panel p1,p2,p3,p4,p5;
Button bt=new Button("Botão");
Checkbox cb1=new Checkbox("Checkbox");
Choice ch=new Choice();
List lt=new List(5,true);
TextArea ta=new TextArea(5,15);
TextField tf=new TextField(5);
CheckboxGroup cbg=new CheckboxGroup();
Checkbox[] cb2=new Checkbox[5];
groupListener Click = new groupListener(ta);
buttonListener Zap = new buttonListener(ta);
boxListener Check = new boxListener(ta);
choiceListener Choose = new choiceListener(ta);
listListener Zip = new listListener(ta);
textfieldListener Taptap = new textfieldListener(ta);
dblclickListListener Zapzap=new dblclickListListener(ta);
public void init()
{
setLayout(new BorderLayout(5,5));
p1=new Panel();
add("North",p1);
p1.add(cb2[0]=new Checkbox("uva",cbg,true));
p1.add(cb2[1]=new Checkbox("banana",cbg,false));
p1.add(cb2[2]=new Checkbox("maçã",cbg,false));
p1.add(cb2[3]=new Checkbox("laranja",cbg,false));
p1.add(cb2[4]=new Checkbox("mamão",cbg,false));
cb2[0].addItemListener(Click);
cb2[1].addItemListener(Click);
cb2[2].addItemListener(Click);
cb2[3].addItemListener(Click);
cb2[4].addItemListener(Click);
p1.setBackground(Color.red);
p2=new Panel();
bt.addActionListener(Zap);
add("West",p2);
p2.add(bt);
cb1.addItemListener(Check);
p2.add(cb1);
p2.setBackground(Color.green);
p3=new Panel();
add("East",p3);
ch.addItem("papel higiênico");
ch.addItem("sabonete");
ch.addItem("shampoo");
ch.addItem("condicionador");
ch.addItem("creme para barbear");
ch.addItemListener(Choose);
p3.add(ch);
lt.add("pratos");
lt.add("talheres");
lt.add("copos");
lt.add("guardanapo");
lt.add("panelas");
lt.addItemListener(Zip);
lt.addActionListener(Zapzap);
p3.add(lt);
p3.setBackground(Color.blue);
p4=new Panel();
add("Center",p4);
p4.add(tf);
tf.addActionListener(Taptap);
p4.setBackground(Color.yellow);
tf.setBackground(Color.white);
p5=new Panel();
add("South",p5);
p5.add(ta);
ta.setEditable(false);
ta.setBackground(Color.white);
p5.setBackground(Color.cyan);
}
}//fim do Applet
class groupListener implements ItemListener
{
private TextArea outTextArea = new TextArea(5,15);
groupListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange()==ItemEvent.SELECTED)
{
outTextArea.append("Group = " + e.getItem().toString()+".\n");
}
}
}//fim do groupListener
class buttonListener implements ActionListener
{
private TextArea outTextArea = new TextArea(5,15);
buttonListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void actionPerformed(ActionEvent e)
{
outTextArea.append("Button Clicked!\n");
}
}//fim de buttonListener
class boxListener implements ItemListener
{
private TextArea outTextArea = new TextArea(5,15);
boxListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange()==ItemEvent.SELECTED)
{
outTextArea.append("Box Checked!\n");
}
else
{
outTextArea.append("Box Unchecked!\n");
}
}
}//fim de boxListener
class choiceListener implements ItemListener
{
private TextArea outTextArea = new TextArea(5,15);
choiceListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange()==ItemEvent.SELECTED)
{
outTextArea.append("Opção = " + e.getItem().toString()+"\n");
}
}
}//fim de choiceListener
class listListener implements ItemListener
{
private TextArea outTextArea = new TextArea(5,15);
listListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange()==ItemEvent.SELECTED)
{
outTextArea.append("Eu
quero "+e.getItem().toString()+"\n");
}
if (e.getStateChange()==ItemEvent.DESELECTED)
{
outTextArea.append("Eu
não quero mais "+e.getItem().toString()+"\n");
}
}
}//fim de listListener
class textfieldListener implements ActionListener
{
private TextArea outTextArea = new TextArea(5,15);
textfieldListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void actionPerformed(ActionEvent e)
{
outTextArea.append("TextField
diz: "+ e.getActionCommand()+".\n");
}
}//fim de textfieldListener
class dblclickListListener implements ActionListener
{
private TextArea outTextArea = new TextArea(5,15);
dblclickListListener(TextArea outtext)
{
outTextArea
= outtext;
}
public void actionPerformed(ActionEvent e)
{
outTextArea.append("Double
clicked: "+ e.getActionCommand()+".\n");
}
}//fim de dbclickListener