-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
153 lines (144 loc) · 5.21 KB
/
Main.java
File metadata and controls
153 lines (144 loc) · 5.21 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.time.*;
import java.io.*;
public class Main extends SuperMain{
private JFrame frame;
private JTextArea notesTextArea;
private JButton createNote;
private JButton TimeSort;
private JButton ImportantTimeSort;
private JButton ImportantSort;
protected JLabel Label;
public Main() {
create();
// create a new note
createNote = new JButton("Create Note");
createNote.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
new NotesApp();
Label = update();
//
}
});
// output the notes in order of Time
TimeSort = new JButton("Time Created Of Note");
TimeSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
TimeSorting();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
// output only important notes in order of time
ImportantSort = new JButton("Important Only");
ImportantSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImportantSorting();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
// output the notes in order of Importance then Time
ImportantTimeSort = new JButton("Important Then Time");
ImportantTimeSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ImportantTimeSorting();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
// add the components to the frame
frame.add(Label,BorderLayout.NORTH);
frame.add(createNote, BorderLayout.SOUTH);
frame.add(TimeSort, BorderLayout.WEST);
frame.add(ImportantSort, BorderLayout.CENTER);
frame.add(ImportantTimeSort, BorderLayout.EAST);
// show the frame
frame.setVisible(true);
}
public void WriteToFile(boolean importantOnly) throws IOException{
File TheNotes = new File("notes.txt");
TheNotes.delete();
FileWriter myWriter = new FileWriter("notes.txt",true);
for(Notes i : NoteList){
int hour = Integer.parseInt(i.getTime().toString().substring(0, 2));
int minute = Integer.parseInt(i.getTime().toString().substring(3, 5));
int second = Integer.parseInt(i.getTime().toString().substring(6, 8));
if(importantOnly){
if(i.getImportance()){
myWriter.write(i.getText()+"\n");
System.out.println(i.getText());
System.out.printf("Hour: %-2d Minute: %-2d Second: %-2d%n",hour,minute,second);
}
}
else{
myWriter.write(i.getText()+"\n");
System.out.println(i.getText());
System.out.printf("Hour: %-2d Minute: %-2d Second: %-2d%n",hour,minute,second);
}
}
myWriter.close();
}
//Sort by Time Created
public void TimeSorting() throws IOException{
Collections.sort(NoteList, new TimeComparator());
WriteToFile(false);
}
public void ImportantSorting() throws IOException{
Collections.sort(NoteList);
WriteToFile(true);
}
public void ImportantTimeSorting() throws IOException{
Collections.sort(NoteList);
WriteToFile(false);
}
public void create(){
// create the frame
frame = new JFrame("Main");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
Label = update();
}
public JLabel update(){
Label = new JLabel();
if(!CharacterFrequency.isEmpty()){
CharacterFrequency = new HashMap<Character, Integer>();
for(Notes Note : NoteList){
for(Character chars : Note.getText().toCharArray() ){
chars = Character.toLowerCase(chars);
try{
CharacterFrequency.put(chars,CharacterFrequency.get(chars)+1);
}catch(Exception e){
CharacterFrequency.put(chars,1);
}
}
}
int frequent = 0;
char thingy = ' ';
for(Character k : CharacterFrequency.keySet()){
if(frequent<CharacterFrequency.get(k)){
thingy = k;
frequent = CharacterFrequency.get(k);
}
}
Label.setText("Most Frequent character is "+thingy+" with "+frequent+" times");
}
else{
Label.setText("No Characters yet");
}
return Label;
}
}