Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. txtArea.addKeyListener(new KeyListener() {
  2.  
  3. @Override
  4. public void keyTyped(KeyEvent e) {
  5. }
  6. @Override
  7. public void keyPressed(KeyEvent e) {
  8. String notThisTxt = txtArea.getText();
  9. String text1 = "Please enter your text in here!";
  10. String text2 = "Text added successfully!";
  11.  
  12. if(!notThisTxt.contentEquals(text1) || !notThisTxt.contentEquals(text2)) {
  13. if ((e.getKeyCode() == KeyEvent.VK_C) && e.isControlDown()) {
  14. try {
  15. file.createNewFile();
  16. } catch (IOException e1) {
  17. // TODO Auto-generated catch block
  18. e1.printStackTrace();
  19. }
  20. FileWriter fw = null;
  21. String someSpace = " ";
  22. BufferedWriter br = null;
  23. try {
  24. fw = new FileWriter(file.getAbsoluteFile(), true);
  25. br = new BufferedWriter(fw);
  26.  
  27. br.write(someSpace);
  28. txtArea.write(br);
  29. }catch (IOException e1) {
  30. // TODO Auto-generated catch block
  31. e1.printStackTrace();
  32. }finally {
  33. }try {
  34. br.close();
  35. fw.close();
  36. }catch(IOException e2) {
  37. System.out.println("The programm doesn't want to close!" + e2);
  38. }
  39. }
  40. txtArea.setText(txtAdded);
  41. }
  42. else{
  43. System.out.println("test");
  44. }
  45. }
  46.  
  47. @Override
  48. public void keyReleased(KeyEvent e) {
  49. }
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement