浏览代码

Save io/ open io added

Jeroen96 10 年之前
父节点
当前提交
dc35f173e0

+ 2 - 1
src/agenda/Act.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Act {
+public class Act implements Serializable {
     
     private List<Artist> artists;
     private Stage stage;

+ 2 - 1
src/agenda/ActTime.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class ActTime {
+public class ActTime implements Serializable {
     
 	private GregorianCalendar beginTime, endTime;
     private String beginString, endString;

+ 2 - 1
src/agenda/Agenda.java

@@ -1,12 +1,13 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Agenda {
+public class Agenda implements Serializable {
     
     private List<Stage> stages;
     private List<Artist> artists;

+ 3 - 1
src/agenda/Artist.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Artist {
+public class Artist implements Serializable {
     
     private String name, genre;
     

+ 2 - 2
src/agenda/Io.java

@@ -20,7 +20,7 @@ public class Io {
 		writeIo();
 	}
 	
-	public void writeIo() throws IOException
+	public static void writeIo() throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showSaveDialog(null)
@@ -46,7 +46,7 @@ public class Io {
 
 	}
 
-	public void readIo() throws IOException
+	public static void readIo() throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showOpenDialog(null)

+ 3 - 1
src/agenda/Stage.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class Stage {
+public class Stage implements Serializable {
     
     private String name;
     

+ 3 - 1
src/agenda/Time.java

@@ -1,9 +1,11 @@
 package agenda;
 
+import java.io.Serializable;
+
 /**
  * Created by gjoosen on 07/02/15.
  */
-public class Time {
+public class Time implements Serializable {
     
     private int hours, minutes;
     

+ 25 - 7
src/gui/menubar/MenuBar.java

@@ -9,11 +9,14 @@ import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import javax.swing.*;
 
+import agenda.Io;
+
 @SuppressWarnings("serial")
 public class MenuBar extends JMenuBar{
 
@@ -41,7 +44,7 @@ public class MenuBar extends JMenuBar{
         JMenuItem cutAction = new JMenuItem("Cut");
         JMenuItem copyAction = new JMenuItem("Copy");
         JMenuItem pasteAction = new JMenuItem("Paste");
-        
+        JMenuItem saveAction = new JMenuItem("Save");
         //view 
         JMenuItem editorView = new JMenuItem("Editor");
         JMenuItem agendaView = new JMenuItem("Agenda");
@@ -54,6 +57,7 @@ public class MenuBar extends JMenuBar{
         cutAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
         copyAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
         pasteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
+        saveAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK));
         
         fileMenu.add(newAction);
         newAction.addActionListener(new ActionListener() {
@@ -61,12 +65,26 @@ public class MenuBar extends JMenuBar{
                 System.out.println("You have clicked on the new action");
             }
         });
-        fileMenu.add(openAction);
-        openAction.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent arg0) {
-                System.out.println("You have clicked on the open action");
-            }
-        });
+        fileMenu.add(saveAction);
+		saveAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				try {
+					Io.writeIo();
+				} catch (IOException e1) {
+					e1.printStackTrace();
+				}
+			}
+		});
+		fileMenu.add(openAction);
+		openAction.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+				try {
+					Io.readIo();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		});
         fileMenu.addSeparator();
         fileMenu.add(exitAction);
         exitAction.addActionListener(new ActionListener() {