Full width home advertisement

HTML

Tech News

Ad

  1.  
  2. package pkgApplet;
  3.  
  4. import java.applet.Applet;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.io.FileReader;
  8. import java.io.FileWriter;
  9. import java.io.IOException;
  10.  
  11.  
  12. public class pr22 extends Applet implements ActionListener {
  13.  
  14. FileReader fr;
  15. FileWriter fw;
  16. TextArea ta;
  17. Button b1, b2;
  18.  
  19. @Override
  20. public void init() {
  21. ta = new TextArea(10, 20);
  22. b1 = new Button("READ");
  23. b2 = new Button("WRITE");
  24.  
  25. b1.addActionListener(this);
  26. b2.addActionListener(this);
  27. add(b1);
  28. add(b2);
  29. add(ta);
  30. }
  31.  
  32. @Override
  33. public void actionPerformed(ActionEvent e) {
  34.  
  35. if (e.getSource() == b1) {
  36. try {
  37. fr = new FileReader("Hello.txt");
  38. char c[] = new char[50];
  39. fr.read(c);
  40. ta.append(new String(c));
  41. } catch (IOException ai) {
  42. System.out.println(ai);
  43. }
  44. }
  45.  
  46. if (e.getSource() == b2) {
  47. try {
  48. fw = new FileWriter("Hello.txt");
  49. fw.write("hello I'm Smit ;) \n");
  50. fw.close();
  51. } catch (IOException is) {
  52. System.out.println(is);
  53. }
  54. }
  55. }
  56.  
  57. }
  58.  

No comments:

Post a Comment

Bottom Ad [Post Page]