import java.awt.*; import java.awt.event.*; import java.applet.*; /*
*/ public class s9 extends Applet implements ItemListener {
Choice Ch; Label L1; { Ch=new Choice(); L1=new Label(" "); Ch.add("pen"); Ch.add("pencil"); Ch.add("Eraser"); Ch.add("Notebook"); Ch.addItemListener(this); add(Ch); add(L1); } public void itemStateChanged(ItemEvent ie) { if(Ch.getSelectedItem()=="pencil") {
L1.setText("price is Rs 10"); } else if(Ch.getSelectedItem()=="pen") { L1.setText("price is Rs 20"); } else if(Ch.getSelectedItem()=="eraser") { L1.setText("price is Rs 5"); } else if(Ch.getSelectedItem()=="Notebook") { L1.setText("price is Rs 30"); } }
}
import java.awt.*; import java.applet.*; /*
*/ public class s5 extends Applet { public void init() { setLayout(new FlowLayout(FlowLayout.RIGHT)); Button b1=new Button("1st"); Button b2=new Button("2nd"); add(b1);
add(b2); } }
import java.awt.*; import java.applet.*; /*
*/ public class s6 extends Applet { public void init() { setLayout(new BorderLayout()); Button b1=new Button("1st"); Button b2=new Button("2nd"); add(b1,BorderLayout.NORTH);
add(b2,BorderLayout.SOUTH); } }
import java.awt.*; import java.applet.*; /*
*/ public class s7 extends Applet { public void init() { setLayout(new GridLayout(4,4)); for(int i=0;i<4;++i) { for(int j=0;j<4;++j) { int k=i*4+j; if(k>0) { add(new Button(" "+k)); } } } } }
import java.awt.*; import java.awt.event.*; import java.applet.*; /*
*/ public class s8 extends Applet implements MouseListener,MouseMotionListener { String msg=""; public void init() { addMouseListener(this); addMouseMotionListener(this); }
public void mouseClicked(MouseEvent e) { msg="Mouse Clicked"; repaint(); } public void mouseEntered(MouseEvent e) { msg="Mouse Entered"; repaint(); } public void mouseExited(MouseEvent e) { msg="Mouse exited"; repaint(); } public void mousePressed(MouseEvent e) { msg="Mouse pressed"; repaint(); } public void mouseReleased(MouseEvent e) { msg="Mouse released"; repaint(); } public void mouseDragged(MouseEvent e) { msg="Mouse dragged";
repaint(); } public void mouseMoved(MouseEvent e) { msg="Mouse moved"; repaint(); } public void paint(Graphics g) { g.drawString(msg,100,50); }
}