Jeroen96 10 vuotta sitten
vanhempi
commit
d85a2b014e

+ 3 - 1
src/agenda/Act.java

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

+ 3 - 1
src/agenda/ActTime.java

@@ -1,12 +1,14 @@
 package agenda;
 
+import java.io.Serializable;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class ActTime {
+@SuppressWarnings("serial")
+public class ActTime implements Serializable {
     
 	private GregorianCalendar beginTime, endTime;
     

+ 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;
     

+ 24 - 25
src/agenda/Io.java

@@ -10,51 +10,50 @@ import javax.swing.JFileChooser;
 
 
 public class Io {
-	
+
 	public static void main(String [] args) throws IOException{
 		Io io = new Io();
 	}
-	
+
 	public Io() throws IOException
 	{
 		writeIo();
 	}
-	
-	public void writeIo() throws IOException
+
+	public static void writeIo() throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showSaveDialog(null)
 				== fileChooser.APPROVE_OPTION) {
 			java.io.File file = fileChooser.getSelectedFile();
-		
-		ObjectOutputStream output = null;
-		try{
-			output = new ObjectOutputStream(new FileOutputStream(file));
-		}catch(IOException e){ 
-			System.out.println("Could not open file." + e);
-			System.exit(0);
-		}
-		try{
-			output.writeObject(new Agenda());
 
-			output.close();
-		}catch(IOException e){
-			System.out.println("Writing error.  " + e);
-			System.exit(0); 
-		}
+			ObjectOutputStream output = null;
+			try{
+				output = new ObjectOutputStream(new FileOutputStream(file));
+			}catch(IOException e){ 
+				System.out.println("Could not open file." + e);
+				System.exit(0);
+			}
+			try{
+				output.writeObject(new Agenda());
+
+				output.close();
+			}catch(IOException e){
+				System.out.println("Writing error.  " + e);
+				System.exit(0); 
+			}
 		}
 
 	}
-
-	public void readIo() throws IOException
+	public static void readIo() throws IOException
 	{
 		JFileChooser fileChooser = new JFileChooser();
 		if(fileChooser.showOpenDialog(null)
 				== fileChooser.APPROVE_OPTION) {
 			java.io.File file = fileChooser.getSelectedFile();
-			
+
 			ObjectInputStream input = null;
-			
+
 			try{
 				input = new ObjectInputStream(new FileInputStream(file));
 			}catch(IOException e){
@@ -71,8 +70,8 @@ public class Io {
 				System.exit(0);
 			}
 			System.out.println("agenda's stuff is : " + agenda.getActs());
-	}
-			
+		}
+
 	}
 }
 

+ 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;
     

+ 33 - 14
src/gui/menubar/MenuBar.java

@@ -1,18 +1,19 @@
 package gui.menubar;
 
 import gui.frames.MainFrame;
-import gui.main.Main;
-import javafx.stage.*;
 
-import java.awt.*;
-import java.awt.Window;
+import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.io.IOException;
 
-import javax.swing.*;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
+
+import agenda.Io;
 
 @SuppressWarnings("serial")
 public class MenuBar extends JMenuBar{
@@ -41,7 +42,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 +55,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 +63,29 @@ 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() {