From e0b9c991c8358f7af11e705694f1bf2a42481e6a Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Thu, 26 Feb 2015 10:27:24 +0100 Subject: [PATCH] Fixed loading and saving not showing agenda. Added new Agenda button --- Agenda.java | 2 ++ Main.java | 12 ++++++++---- MenuBar.java | 19 ++++++++++++++++++- Window.java | 5 +++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Agenda.java b/Agenda.java index a47981d..7cd4f35 100644 --- a/Agenda.java +++ b/Agenda.java @@ -128,6 +128,7 @@ public class Agenda implements Serializable { { clearAgenda(); fillAgenda(file); + JOptionPane.showMessageDialog(null, "Loaded succesfully"); } } } @@ -201,6 +202,7 @@ public class Agenda implements Serializable { oos.writeObject(event); } oos.close(); + JOptionPane.showMessageDialog(null, "Saved succesfully"); } catch (IOException e) { e.printStackTrace(); } diff --git a/Main.java b/Main.java index 261df5e..161993e 100644 --- a/Main.java +++ b/Main.java @@ -19,15 +19,19 @@ public class Main { Event e2 = new Event("Coldplay Live", 2015, 2, 25, 20, 00, 2015, 2, 25, 22, 00, a1, s1, "A concert from a very famous band", 1); Event e3 = new Event("Nirvana in memory", 2015, 2, 24, 16, 30, 2015, 2, 24, 20, 45, a2, s1, "A concert in memory of a once very famous band", 4); Event e4 = new Event("Epic Rap Battles of History", 2015, 3, 3, 12, 30, 2015, 3, 12, 18, 45, a3, s2, "Rap battle with Eminem and ERP", 3); - - //TabbedPane tab = new TabbedPane(e1, true); - //TabbedPane tab2 = new TabbedPane(e3, false); - //TabbedPane tab3 = new TabbedPane(e4, true); + Event e5 = new Event("Coldplay Live", 2015, 2, 26, 21, 00, 2015, 2, 24, 23, 00, a1, s1, "A concert from a very famous band", 2); + Event e6 = new Event("Coldplay Live", 2015, 2, 27, 20, 00, 2015, 2, 25, 22, 00, a1, s1, "A concert from a very famous band", 1); + Event e7 = new Event("Nirvana in memory", 2015, 2, 28, 16, 30, 2015, 2, 24, 20, 45, a2, s1, "A concert in memory of a once very famous band", 4); + Event e8 = new Event("Epic Rap Battles of History", 2015, 3, 2, 12, 30, 2015, 3, 12, 18, 45, a3, s2, "Rap battle with Eminem and ERP", 3); agn.addEvent(e1); agn.addEvent(e2); agn.addEvent(e3); agn.addEvent(e4); + agn.addEvent(e5); + agn.addEvent(e6); + agn.addEvent(e7); + agn.addEvent(e8); agn.fillArtists(); agn.fillStages(); diff --git a/MenuBar.java b/MenuBar.java index 757a3dd..80f4198 100644 --- a/MenuBar.java +++ b/MenuBar.java @@ -5,6 +5,7 @@ import java.awt.event.KeyEvent; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.KeyStroke; @@ -44,11 +45,21 @@ public class MenuBar extends JMenuBar { } }); + JMenuItem newAgenda = new JMenuItem("New Agenda"); + newAgenda.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Agenda a = new Agenda(); + w.setAgenda(a); + Window.updatePanel("table"); + } + }); + JMenuItem open = new JMenuItem("Open"); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { w.getAgenda().loadAgenda(); + Window.updatePanel("table"); } }); @@ -57,13 +68,17 @@ public class MenuBar extends JMenuBar { save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { w.getAgenda().saveAgenda(); + Window.updatePanel("table"); } }); JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - System.exit(0); + if(JOptionPane.showConfirmDialog(null, "Are you sure you want to close this program?", "Close Agenda", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) + { + System.exit(0); + } } }); @@ -71,6 +86,8 @@ public class MenuBar extends JMenuBar { file.add(newArtist); file.add(newStage); file.addSeparator(); + file.add(newAgenda); + file.addSeparator(); file.add(open); file.add(save); file.addSeparator(); diff --git a/Window.java b/Window.java index 59d11a3..ba52e59 100644 --- a/Window.java +++ b/Window.java @@ -210,5 +210,10 @@ public class Window extends JFrame { return agenda; } + public void setAgenda(Agenda a) + { + agenda = a; + } + }