Applet Form

  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.awt.event.*;
  4. public class appform extends Applet implements ActionListener,ItemListener
  5. {
  6. Label lh,la,ln,lc,lsw,lf,e1,e2,e3,e4,e5,e6,e7,e8;
  7. TextField tn,ta;
  8. Button b1,b2;
  9. String msg="";
  10. CheckboxGroup cbg,cbg1;
  11. Checkbox c1,c2,s1,s2,s3,s4;
  12. @Override
  13. public void init()
  14. {
  15. e1=new Label();
  16. e2=new Label();
  17. e3=new Label();
  18. e4=new Label();
  19. e5=new Label();
  20. e6=new Label();
  21. e7=new Label();
  22. e8=new Label();
  23. setLayout(new GridLayout(8,3));
  24. lf=new Label();
  25. lh=new Label("Course Registration");
  26. ln=new Label("Enter your Name");
  27. la=new Label("Enter your age");
  28. lc=new Label("Select the city");
  29. lsw=new Label("Select Software");
  30. tn=new TextField(25);
  31. ta=new TextField(5);
  32. cbg=new CheckboxGroup();
  33. cbg1=new CheckboxGroup();
  34. c1=new Checkbox("DELHI",cbg,false);
  35. c2=new Checkbox("MADRAS",cbg,false);
  36. s1=new Checkbox("ORACLE",cbg1,false);
  37. s2=new Checkbox("VB",cbg1,false);
  38. s3=new Checkbox("Java",cbg1,false);
  39. s4=new Checkbox("C/C++",cbg1,false);
  40. b1=new Button("OK");
  41. b2=new Button("Cancel");
  42. b1.addActionListener(this);
  43. b2.addActionListener(this);
  44. c1.addItemListener(this);
  45. c2.addItemListener(this);
  46. s1.addItemListener(this);
  47. s2.addItemListener(this);
  48. s3.addItemListener(this);
  49. s4.addItemListener(this);
  50.  
  51. add(e1);
  52. add(lh);
  53. add(e2);
  54.  
  55. add(ln);
  56. add(tn);
  57. add(e3);
  58.  
  59. add(la);
  60. add(ta);
  61. add(e4);
  62.  
  63. add(lc);
  64. add(c1);
  65. add(c2);
  66.  
  67. add(lsw);
  68. add(s1);
  69. add(s2);
  70.  
  71. add(e5);
  72. add(s3);
  73. add(s4);
  74.  
  75. add(b1);
  76. add(b2);
  77. add(lf);
  78. add(e7);
  79. add(e8);
  80. }
  81. public void itemStateChanged (ItemEvent ie)
  82. {
  83. repaint();
  84. }
  85. public void actionPerformed(ActionEvent ae)
  86. {
  87. String str=ae.getActionCommand();
  88. if(str.equals("OK"))
  89. {
  90. String s=tn.getText();
  91. if(s.length()>25)
  92. {
  93. e7.setText("Name Should be within 25 characters");
  94. tn.setText("");
  95. }
  96. else
  97. e7.setText("Thank YOU");
  98. repaint();
  99. String age=ta.getText();
  100. char t=age.charAt(0);
  101. for(int v=0;v<age.length();v++)
  102. {
  103. if(Character.isLetter(t)==true)
  104. {
  105. ta.setText(" ");
  106. e8.setText("Age Should be Numeric");
  107. break;
  108. }
  109. else
  110. {
  111. e8.setText(" ");
  112. }
  113. }
  114. }
  115. if(str.equalsIgnoreCase("CANCEL"))
  116. {
  117. ta.setText(" ");
  118. tn.setText(" ");
  119. lf.setText(" ");
  120. }
  121. }
  122. public void paint(Graphics g)
  123. {
  124. if(s1.getState()==true)
  125. lf.setText("FEES : 3000");
  126. if(s2.getState()==true)
  127. lf.setText("FEES : 2400");
  128. if(s3.getState()==true)
  129. lf.setText("FEES : 3500");
  130. if(s4.getState()==true)
  131. lf.setText("FEES : 4000");
  132. }
  133.  
  134.  
  135. }
  1. <applet code="appform"width=800 height=600></applet>