+31
-3
@@ -1,7 +1,13 @@
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Week9 {
|
public class Week9 {
|
||||||
private static ArrayList<Task> tasks;
|
private static ArrayList<Task> tasks;
|
||||||
@@ -29,10 +35,21 @@ public class Week9 {
|
|||||||
gui.update(tasks);
|
gui.update(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parse(File f) {
|
//addBtn Method
|
||||||
|
private static void addBtn() {
|
||||||
|
String[] strs = new String[3];
|
||||||
|
strs[0] = JOptionPane.showInputDialog("Please Enter A Title:");
|
||||||
|
strs[1] = JOptionPane.showInputDialog("Please Enter A Discription:");
|
||||||
|
strs[2] = JOptionPane.showInputDialog("Please Enter A Due Date:");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parse(File f) throws IOException {
|
||||||
// TODO: Need to open the file and get each line.
|
// TODO: Need to open the file and get each line.
|
||||||
// TODO: Parse the format ("TITLE, DESCRIPTION, DUE DATE, COMPLETED"),
|
// TODO: Parse the format ("TITLE, DESCRIPTION, DUE DATE, COMPLETED"),
|
||||||
// TODO: Create a new Task object and add it to the ArrayList.
|
// TODO: Create a new Task object and add it to the ArrayList.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes each task to the file after a change.
|
// Writes each task to the file after a change.
|
||||||
@@ -72,7 +89,12 @@ public class Week9 {
|
|||||||
|
|
||||||
if(f.isFile()) {
|
if(f.isFile()) {
|
||||||
System.out.println("loading tasks from " + filepath);
|
System.out.println("loading tasks from " + filepath);
|
||||||
parse(f);
|
try {
|
||||||
|
parse(f);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
f.createNewFile();
|
f.createNewFile();
|
||||||
@@ -109,7 +131,13 @@ public class Week9 {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
gui = new Week9Gui(tasks, sortByTitle, sortByDueDate, filterByCompleted);
|
ActionListener addBtn = new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
addBtn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gui = new Week9Gui(tasks, sortByTitle, sortByDueDate, filterByCompleted, addBtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-10
@@ -9,6 +9,7 @@ import javax.swing.UIManager;
|
|||||||
|
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
|
|
||||||
public class Week9Gui {
|
public class Week9Gui {
|
||||||
@@ -17,29 +18,31 @@ public class Week9Gui {
|
|||||||
private ActionListener titleSort;
|
private ActionListener titleSort;
|
||||||
private ActionListener dueDateSort;
|
private ActionListener dueDateSort;
|
||||||
private ActionListener completeFilter;
|
private ActionListener completeFilter;
|
||||||
|
private ActionListener addBtn;
|
||||||
|
|
||||||
public Week9Gui(ArrayList<Task> tasks, ActionListener titleSort, ActionListener dueDateSort, ActionListener completeFilter) {
|
public Week9Gui(ArrayList<Task> tasks, ActionListener titleSort, ActionListener dueDateSort, ActionListener completeFilter, ActionListener addBtn) {
|
||||||
this.titleSort = titleSort;
|
this.titleSort = titleSort;
|
||||||
this.dueDateSort = dueDateSort;
|
this.dueDateSort = dueDateSort;
|
||||||
this.completeFilter = completeFilter;
|
this.completeFilter = completeFilter;
|
||||||
|
this.addBtn = addBtn;
|
||||||
initGui(tasks);
|
initGui(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the basic GUI layout.
|
// Setup the basic GUI layout.
|
||||||
private void initGui(ArrayList<Task> tasks) {
|
private void initGui(ArrayList<Task> tasks) {
|
||||||
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLayout(new BorderLayout());
|
frame.getContentPane().setLayout(new BorderLayout());
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.setPreferredSize(new Dimension(600, 450));
|
||||||
|
frame.setSize(frame.getPreferredSize());
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error with cross platform look & feel.");
|
System.out.println("Error with cross platform look & feel.");
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.add(buttonsView(), BorderLayout.PAGE_END);
|
frame.getContentPane().add(buttonsView(), BorderLayout.PAGE_END);
|
||||||
frame.add(view(tasks));
|
frame.getContentPane().add(view(tasks));
|
||||||
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -55,13 +58,20 @@ public class Week9Gui {
|
|||||||
JButton filterByComplete = new JButton("Complete");
|
JButton filterByComplete = new JButton("Complete");
|
||||||
filterByComplete.addActionListener(completeFilter);
|
filterByComplete.addActionListener(completeFilter);
|
||||||
|
|
||||||
JPanel p = new JPanel(new GridLayout(2, 3));
|
JButton addBtn = new JButton("Add");
|
||||||
|
addBtn.addActionListener(this.addBtn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JPanel p = new JPanel(new GridLayout(0, 4));
|
||||||
p.add(new JLabel("Sort by:"));
|
p.add(new JLabel("Sort by:"));
|
||||||
p.add(new JLabel("Sort by:"));
|
p.add(new JLabel("Sort by:"));
|
||||||
p.add(new JLabel("Filter by:"));
|
p.add(new JLabel("Filter by:"));
|
||||||
|
p.add(new JLabel("Add to:"));
|
||||||
p.add(sortByTitle);
|
p.add(sortByTitle);
|
||||||
p.add(sortByDueDate);
|
p.add(sortByDueDate);
|
||||||
p.add(filterByComplete);
|
p.add(filterByComplete);
|
||||||
|
p.add(addBtn);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -87,8 +97,8 @@ public class Week9Gui {
|
|||||||
// Clear everything and refresh the JFrame to update information.
|
// Clear everything and refresh the JFrame to update information.
|
||||||
public void update(ArrayList<Task> tasks) {
|
public void update(ArrayList<Task> tasks) {
|
||||||
frame.getContentPane().removeAll();
|
frame.getContentPane().removeAll();
|
||||||
frame.add(buttonsView(), BorderLayout.PAGE_END);
|
frame.getContentPane().add(buttonsView(), BorderLayout.PAGE_END);
|
||||||
frame.add(view(tasks));
|
frame.getContentPane().add(view(tasks));
|
||||||
frame.repaint();
|
frame.repaint();
|
||||||
frame.revalidate();
|
frame.revalidate();
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
|||||||
Reference in New Issue
Block a user