Full width home advertisement

HTML

Tech News

Ad

  1. package pkgApplet;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.Button;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.Color;
  8.  
  9. public class pr10 extends Applet implements ActionListener {
  10.  
  11. Button b1, b2, b3, b4, b5;
  12.  
  13. public void init() {
  14. b1 = new Button("Red");
  15. b2 = new Button("Blue");
  16. b3 = new Button("Green");
  17. b4 = new Button("Yellow");
  18. b5 = new Button("Black");
  19.  
  20. add(b1);
  21. add(b2);
  22. add(b3);
  23. add(b4);
  24. add(b5);
  25.  
  26. b1.addActionListener(this);
  27. b2.addActionListener(this);
  28. b3.addActionListener(this);
  29. b4.addActionListener(this);
  30. b5.addActionListener(this);
  31. // TODO start asynchronous download of heavy resources
  32. }
  33.  
  34. public void actionPerformed(ActionEvent e) {
  35. if (e.getSource() == b1) {
  36. setBackground(Color.red);
  37. }
  38. if (e.getSource() == b2) {
  39. setBackground(Color.blue);
  40. }
  41. if (e.getSource() == b3) {
  42. setBackground(Color.green);
  43. }
  44. if (e.getSource() == b4) {
  45. setBackground(Color.yellow);
  46. }
  47. if (e.getSource() == b5) {
  48. setBackground(Color.black);
  49. }
  50. // TODO overwrite start(), stop() and destroy() methods
  51. }
  52. }
  53.  

No comments:

Post a Comment

Bottom Ad [Post Page]