Full width home advertisement

HTML

Tech News

Ad

  1. package pkgApplet;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9.  
  10.  
  11. public class pr22 extends Applet implements ActionListener {
  12. /*
  13.  * To change this license header, choose License Headers in Project Properties.
  14.  * To change this template file, choose Tools | Templates
  15.  * and open the template in the editor.
  16.  */
  17.  
  18. package pkgApplet;
  19.  
  20. import java.applet.Applet;
  21. import java.awt.Button;
  22. import java.awt.GridLayout;
  23. import java.awt.List;
  24. import java.awt.TextField;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27.  
  28. /**
  29.  *
  30.  * @author smit
  31.  */
  32. public class pr24 extends Applet implements ActionListener{
  33. Button b1,b2;
  34. List li;
  35. TextField tf;
  36. /**
  37.   * Initialization method that will be called after the applet is loaded into
  38.   * the browser.
  39.   */
  40. public void init() {
  41. // TODO start asynchronous download of heavy resources
  42. b1=new Button("ADD");
  43. b2=new Button("REMOVE");
  44. li=new List(10);
  45. tf=new TextField();
  46. setLayout(new GridLayout(0,1));
  47. add(tf);
  48. add(b1);
  49. add(b2);
  50. add(li);
  51.  
  52. b1.addActionListener(this);
  53. b2.addActionListener(this);
  54. }
  55.  
  56. public void actionPerformed(ActionEvent e){
  57. String s;
  58.  
  59. if(e.getSource()==b1){
  60. s=tf.getText();
  61. li.add(s);
  62. }
  63. try{
  64. if(e.getSource()==b2){
  65. s=li.getSelectedItem();
  66. li.remove(s);
  67. }
  68. }catch(IllegalArgumentException err){
  69. System.out.println("Runtime Exception : "+err);
  70. }
  71. }
  72. // TODO overwrite start(), stop() and destroy() methods
  73. }
  74.  
  75. FileReader fr;
  76. FileWriter fw;
  77. TextArea ta;
  78. Button b1, b2;
  79.  
  80. @Override
  81. public void init() {
  82. ta = new TextArea(10, 20);
  83. b1 = new Button("READ");
  84. b2 = new Button("WRITE");
  85.  
  86. b1.addActionListener(this);
  87. b2.addActionListener(this);
  88. add(b1);
  89. add(b2);
  90. add(ta);
  91. }
  92.  
  93. @Override
  94. public void actionPerformed(ActionEvent e) {
  95.  
  96. if (e.getSource() == b1) {
  97. try {
  98. fr = new FileReader("Hello.txt");
  99. char c[] = new char[50];
  100. fr.read(c);
  101. ta.append(new String(c));
  102. } catch (IOException ai) {
  103. System.out.println(ai);
  104. }
  105. }
  106.  
  107. if (e.getSource() == b2) {
  108. try {
  109. fw = new FileWriter("Hello.txt");
  110. fw.write("hello I'm Smit ;) \n");
  111. fw.close();
  112. } catch (IOException is) {
  113. System.out.println(is);
  114. }
  115. }
  116. }
  117.  
  118. }
  119.  

No comments:

Post a Comment

Bottom Ad [Post Page]