Full width home advertisement

Java

Tech News

Ad

  1.  
  2.  
  3. package pkgApplet;
  4.  
  5. import java.applet.Applet;
  6. import java.awt.Button;
  7. import java.awt.GridLayout;
  8. import java.awt.Label;
  9. import java.awt.TextArea;
  10. import java.awt.TextField;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.io.FileReader;
  14. import java.io.FileWriter;
  15. import java.io.IOException;
  16.  
  17. /**
  18.  *
  19.  * @author smit
  20.  */
  21. public class PR27 extends Applet implements ActionListener {
  22. Button b1,b2;
  23. TextField t1,t2,t3,t4;
  24. TextArea ta;
  25. Label l1,l2,l3,l4,l5;
  26. public void init() {
  27. b1=new Button("Write");
  28. b2=new Button("Read");
  29. t1=new TextField();
  30. t2=new TextField();
  31. t3=new TextField();
  32. t4=new TextField();
  33. l1=new Label("Rollno");
  34. l2=new Label("Name");
  35. l3=new Label("Address");
  36. l4=new Label("Result");
  37. l5=new Label("Output");
  38. ta=new TextArea(10,30);
  39. setLayout(new GridLayout(6,1));
  40.  
  41. add(l1); add(t1);
  42. add(l2); add(t2);
  43. add(l3); add(t3);
  44. add(l4); add(t4);
  45. add(b1); add(b2);
  46. add(l5); add(ta);
  47.  
  48. b1.addActionListener(this);
  49. b2.addActionListener(this);
  50. }
  51. public void actionPerformed(ActionEvent e){
  52.  
  53. if(e.getSource()==b1){
  54. try{
  55. FileWriter fw=new FileWriter("D:/Hello.txt");
  56. fw.write(t1.getText()+"\n"+t2.getText()+"\n"+t3.getText()+"\n"+t4.getText());
  57. fw.close();
  58. }catch(IOException ae){
  59. System.out.println(ae);
  60. }
  61. }
  62. if(e.getSource()==b2){
  63. try{
  64. FileReader fr=new FileReader("D:/Hello.txt");
  65. int i;
  66.  
  67. while((i=fr.read())!=-1){
  68. ta.append(""+(char)i);
  69. }
  70. fr.close();
  71. }catch(IOException ax){
  72. System.out.println(ax);
  73. }
  74. }
  75. }
  76.  
  77.  
  78. }
  79.  

No comments:

Post a Comment

Bottom Ad [Post Page]