From 246286ba39198e1907c124fea4ffa40bdef49196 Mon Sep 17 00:00:00 2001 From: socrates Date: Wed, 29 Oct 2014 00:00:07 +0100 Subject: [PATCH] =?UTF-8?q?Exceptions,=20die=20nicht=20anders=20verarbeite?= =?UTF-8?q?t=20werden=20k=C3=B6nnen,=20werden=20jetzt=20mit=20einem=20Mess?= =?UTF-8?q?age-Dialog=20abgefangen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/katho/kBorrow/Main.java | 48 -------------------- src/de/katho/kBorrow/gui/MainWindow.java | 58 ++++++++++++++---------- 2 files changed, 35 insertions(+), 71 deletions(-) delete mode 100644 src/de/katho/kBorrow/Main.java diff --git a/src/de/katho/kBorrow/Main.java b/src/de/katho/kBorrow/Main.java deleted file mode 100644 index 3e3c9c8..0000000 --- a/src/de/katho/kBorrow/Main.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.katho.kBorrow; - -import java.io.IOException; -import java.sql.SQLException; - -import javax.swing.UnsupportedLookAndFeelException; - -import de.katho.kBorrow.db.DbConnector; -import de.katho.kBorrow.db.SqlConnector; -import de.katho.kBorrow.db.SqliteConnector; -import de.katho.kBorrow.gui.MainWindow; - -public class Main { - private DbConnector dbCon; - private Settings set; - - public static void main(String[] args){ - new Main(); - } - - public Main(){ - /* - * Create the apps main window. - */ - this.set = new Settings(); - - if(set.getProperty("dBType").equals("sqlite")){ - try { - this.dbCon = new SqliteConnector(set.getProperty("sqlitePath")); - } catch (ClassNotFoundException | SQLException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - System.exit(1); - } - - } - else if(set.getProperty("dBType").equals("mysql")) { - this.dbCon = new SqlConnector(); - } - try { - new MainWindow(this.dbCon); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - System.exit(1); - } - } -} diff --git a/src/de/katho/kBorrow/gui/MainWindow.java b/src/de/katho/kBorrow/gui/MainWindow.java index e4804a1..a458c7f 100644 --- a/src/de/katho/kBorrow/gui/MainWindow.java +++ b/src/de/katho/kBorrow/gui/MainWindow.java @@ -1,14 +1,19 @@ package de.katho.kBorrow.gui; import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import java.awt.BorderLayout; import java.io.IOException; +import java.sql.SQLException; +import de.katho.kBorrow.Settings; import de.katho.kBorrow.db.DbConnector; +import de.katho.kBorrow.db.SqlConnector; +import de.katho.kBorrow.db.SqliteConnector; public class MainWindow { @@ -19,7 +24,8 @@ public class MainWindow { private JFrame frame; private JTabbedPane tabbedPane; - + + private Settings set; /** * Create the application. @@ -29,33 +35,39 @@ public class MainWindow { * @throws ClassNotFoundException * @throws IOException */ - public MainWindow(DbConnector pDbCon) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, IOException { - this.dbCon = pDbCon; - initialize(); - this.frame.setVisible(true); - } - - /** - * Initialize the contents of the frame. - * @throws UnsupportedLookAndFeelException - * @throws IllegalAccessException - * @throws InstantiationException - * @throws ClassNotFoundException - * @throws IOException - */ - private void initialize() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, IOException { + public MainWindow() { + this.set = new Settings(); this.frame = new JFrame(); this.frame.setResizable(false); this.frame.setBounds(100, 100, 600, 500); this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - this.tabbedPane = new JTabbedPane(JTabbedPane.TOP); - this.frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER); + try { + if(set.getProperty("dBType").equals("sqlite")){ + this.dbCon = new SqliteConnector(set.getProperty("sqlitePath")); + } + else if(set.getProperty("dBType").equals("mysql")) { + this.dbCon = new SqlConnector(); + } + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + + this.tabbedPane = new JTabbedPane(JTabbedPane.TOP); + this.frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER); + this.tabbedPane.addTab("Neue Ausleihe", new NewLendingTab(this.dbCon)); + this.tabbedPane.addTab("Ausleihen verwalten", new ManageLendingTab(this.dbCon)); + this.tabbedPane.addTab("Artikel verwalten", new ArticleTab(this.dbCon)); + this.tabbedPane.addTab("Benutzer verwalten", new UserTab(this.dbCon)); + + } + catch(ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException | SQLException e) { + JOptionPane.showMessageDialog(this.frame, e.getStackTrace(), "Fatal error", JOptionPane.ERROR_MESSAGE); + System.exit(1); + } - this.tabbedPane.addTab("Neue Ausleihe", new NewLendingTab(this.dbCon)); - this.tabbedPane.addTab("Ausleihen verwalten", new ManageLendingTab(this.dbCon)); - this.tabbedPane.addTab("Artikel verwalten", new ArticleTab(this.dbCon)); - this.tabbedPane.addTab("Benutzer verwalten", new UserTab(this.dbCon)); + this.frame.setVisible(true); + } + + public static void main(String[] args){ + new MainWindow(); } }