Full width home advertisement

HTML

Tech News

Ad

  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package pkgApplet;
  7.  
  8. import java.applet.Applet;
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import java.io.FileReader;
  12. import java.io.IOException;
  13.  
  14. /**
  15.  *
  16.  * @author smit
  17.  */
  18. public class pr20 extends Applet implements ActionListener {
  19.  
  20. TextField tf;
  21. TextArea ta;
  22. Button b;
  23.  
  24. /**
  25.   * Initialization method that will be called after the applet is loaded into
  26.   * the browser.
  27.   */
  28. public void init() {
  29. b = new Button("SHOW");
  30. tf = new TextField();
  31. ta = new TextArea(10, 30);
  32. setLayout(new GridLayout(3, 1));
  33. b.addActionListener(this);
  34.  
  35. add(tf);
  36. add(b);
  37. add(ta);
  38. // TODO start asynchronous download of heavy resources
  39. }
  40.  
  41. public void actionPerformed(ActionEvent e) {
  42. try {
  43. int i;
  44. FileReader fr = new FileReader("d:/" + tf.getText());
  45. ta.setText(null);
  46. while ((i = fr.read()) != -1) {
  47. ta.append("" + (char) i);
  48. }
  49. fr.close();
  50. } catch (IOException ae) {
  51. System.out.println(ae);
  52. }
  53. }
  54.  
  55. }
  56.  

No comments:

Post a Comment

Bottom Ad [Post Page]