Full width home advertisement

Java

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.  
  7. package pkgApplet;
  8.  
  9. import java.applet.Applet;
  10. import java.awt.Button;
  11. import java.awt.TextArea;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.io.IOException;
  15. import java.io.RandomAccessFile;
  16.  
  17. /**
  18.  *
  19.  * @author smit
  20.  */
  21. public class PR29 extends Applet implements ActionListener {
  22. Button b1,b2;
  23. TextArea ta;
  24. public void init() {
  25. b1=new Button("Read");
  26. b2=new Button("Write");
  27. ta=new TextArea(10,30);
  28.  
  29. add(b1); add(b2);
  30. add(ta);
  31.  
  32. b1.addActionListener(this);
  33. b2.addActionListener(this);
  34. }
  35.  
  36. public void actionPerformed(ActionEvent e){
  37. if(e.getSource()==b1) {
  38. try{
  39. RandomAccessFile rf=new RandomAccessFile("D:/Hello.txt","r");
  40.  
  41. int i;
  42. while((i=rf.read())!=-1){
  43. ta.append(""+(char)i);
  44. }
  45. }catch(IOException ae){
  46. System.out.println(ae);
  47. }
  48. }
  49. if(e.getSource()==b2){
  50. try{
  51. RandomAccessFile rw=new RandomAccessFile("D:/Hello.txt","rw");
  52. rw.writeBytes("Department of Computer Science");
  53. rw.writeBytes("\nHemchandraChayra North Gujarat University");
  54. }catch(IOException ex){
  55. System.out.println(ex);
  56. }
  57. }
  58. }
  59. }
  60.  

No comments:

Post a Comment

Bottom Ad [Post Page]