Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- txtArea.addKeyListener(new KeyListener() {
- @Override
- public void keyTyped(KeyEvent e) {
- }
- @Override
- public void keyPressed(KeyEvent e) {
- String notThisTxt = txtArea.getText();
- String text1 = "Please enter your text in here!";
- String text2 = "Text added successfully!";
- if(!notThisTxt.contentEquals(text1) || !notThisTxt.contentEquals(text2)) {
- if ((e.getKeyCode() == KeyEvent.VK_C) && e.isControlDown()) {
- try {
- file.createNewFile();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- FileWriter fw = null;
- String someSpace = " ";
- BufferedWriter br = null;
- try {
- fw = new FileWriter(file.getAbsoluteFile(), true);
- br = new BufferedWriter(fw);
- br.write(someSpace);
- txtArea.write(br);
- }catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }finally {
- }try {
- br.close();
- fw.close();
- }catch(IOException e2) {
- System.out.println("The programm doesn't want to close!" + e2);
- }
- }
- txtArea.setText(txtAdded);
- }
- else{
- System.out.println("test");
- }
- }
- @Override
- public void keyReleased(KeyEvent e) {
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement