-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNoteFunction.java
More file actions
104 lines (82 loc) · 2.61 KB
/
Copy pathNoteFunction.java
File metadata and controls
104 lines (82 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Ira
*/
import java.awt.FileDialog;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
/**
*
* @author ranip
*/
public class NoteFunction {
Notes notes;
String fileName, fileAddress;
FileDialog fd;
public NoteFunction(Notes notes){
this.notes = notes;
}
public void newNote(){
notes.textArea.setText("");
notes.window.setTitle("New Note");
fileName = null;
fileAddress = null;
}
public void saveNote(){
if(fileName == null){
saveAsNote();
}
else{
try{
FileWriter fw = new FileWriter(fileAddress + fileName);
fw.write(notes.textArea.getText());
notes.window.setTitle(fileName);
fw.close();
}catch(Exception e){
System.out.println("Error");
}
}
}
public void saveAsNote(){
fd = new FileDialog(notes.window, "Save", FileDialog.SAVE);
fd.setVisible(true);
if (fd.getFile() != null){
fileName = fd.getFile();
fileAddress = fd.getDirectory();
notes.window.setTitle(fileName);
}
try{
FileWriter fw = new FileWriter(fileAddress + fileName);
fw.write(notes.textArea.getText());
fw.close();
}catch (Exception e){
System.out.println("Error");
}
}
public void openNote(){
fd = new FileDialog(notes.window, "Open", FileDialog.LOAD);
fd.setVisible(true);
if (fd.getFile() != null) {
fileName = fd.getFile();
fileAddress = fd.getDirectory();
notes.window.setTitle(fileName);
}
try {
BufferedReader br = new BufferedReader(new FileReader(fileAddress + fileName));
notes.textArea.setText("");
String line = null;
while((line = br.readLine()) != null){
notes.textArea.append(line + "\n" );
}
br.close();
}catch (Exception e){
System.out.println("File note opened");
}
}
}