-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNoteApp.java
More file actions
129 lines (118 loc) · 2.63 KB
/
NoteApp.java
File metadata and controls
129 lines (118 loc) · 2.63 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
class NoteApp extends JFrame implements ActionListener
{
JTextArea ta;
JMenuBar mb;
JMenu file,edit;
JMenuItem new1,open,cut,copy,paste,save,close;
JFileChooser jfc;
DataInputStream take;
File SelectedFile;
Scanner s;
JScrollPane jsp;
NoteApp()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
take=new DataInputStream(System.in);
//selectedFile=new File();
jfc=new JFileChooser();
ta=new JTextArea();
//ta.setBounds(0,40,800,780);
mb=new JMenuBar();
//mb.setBounds(0,0,800,20);
file=new JMenu("File");
edit=new JMenu("Edit");
new1=new JMenuItem("new1");
open=new JMenuItem("open");
save=new JMenuItem("save");
cut=new JMenuItem("cut");
copy=new JMenuItem("copy");
paste=new JMenuItem("paste");
close=new JMenuItem("close");
file.add(new1);
file.add(open);
file.add(save);
file.add(close);
//file.addSeparator();
edit.add(cut);
edit.add(copy);
edit.add(paste);
mb.add(file);
mb.add(edit);
add(mb, new BorderLayout().NORTH);
add(ta, new BorderLayout().CENTER);
cut.addActionListener(this);
copy.addActionListener(this);
paste.addActionListener(this);
new1.addActionListener(this);
open.addActionListener(this);
save.addActionListener(this);
close.addActionListener(this);
file.addActionListener(this);
edit.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==new1)
{
ta.setText("");
}
if(ae.getSource()==close)
{
System.exit(0);
}
if(ae.getSource()==open)
{
ta.setText("");
int n=jfc.showOpenDialog(this);
if(n== JFileChooser.APPROVE_OPTION)
{
try
{
s=new Scanner(jfc.getSelectedFile());
while(s.hasNext())
{
String str=s.nextLine();
ta.setText(str+"\n"+ta.getText());
//jsp=new JScrollPane(ta);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
if(ae.getSource()==save)
{
try
{
BufferedWriter br=new BufferedWriter(new FileWriter("TextDocument.text"));
Scanner sc=new Scanner(ta.getText());
while(sc.hasNext())
{
br.write(sc.nextLine());
br.newLine();
}
br.close();
}
catch(IOException ie)
{
System.out.println(ie);
}
//jfc.showSaveDailog(null);
}
}
public static void main(String x[])
{
NoteApp np=new NoteApp();
np.setSize(500,500);
np.setVisible(true);
np.setTitle("ak notes");
}
}