Beispiel #1
0
  public MainWindow() {
    try {
      LoginWindow loginDlg = new LoginWindow(this);
      loginDlg.setVisible(true);

      final User user;
      // if logon fail
      if (!loginDlg.ResultLogin()) {
        System.exit(0);
      } else {
        user = loginDlg.getUser();
        sessionController.setUser(user);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    }

    this.initComponents();
    this.setJMenuBar(mb);
    this.add(mainBar, BorderLayout.NORTH);
    this.add(imgPanel, BorderLayout.CENTER);
    this.setSize(800, 535);
    this.setTitle("Diagnosis Helper");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);

    // Check if User logged is Administrator
    if (sessionController.isAdministrator()) {
      mnuMaintenance.setVisible(true);
    } else {
      mnuMaintenance.setVisible(false);
    }

    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            safeExit();
          }
        });
  }
Beispiel #2
0
  private void initComponents() {
    mnuUtilities = new JMenu("Utilities");
    mnuMaintenance = new JMenu("Maintenance");
    mnuHelp = new JMenu("Help");

    mnuUtilities.setMnemonic('U');
    mnuMaintenance.setMnemonic('M');
    mnuHelp.setMnemonic('H');

    miSearch = new JMenuItem("Search");
    miSearch.setMnemonic('S');
    miObstetCalc = new JMenuItem("Obstet Calculator");
    miObstetCalc.setMnemonic('O');
    miExit = new JMenuItem("Exit");
    miExit.setMnemonic('x');

    mnuUtilities.add(miSearch);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miObstetCalc);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miExit);

    miBaseMalformation = new JMenuItem("Malformation");
    miBaseMalformation.setMnemonic('M');
    miBaseSindrom = new JMenuItem("Syndrome");
    miBaseSindrom.setMnemonic('y');
    miBaseTeratogen = new JMenuItem("Teratogen");
    miBaseTeratogen.setMnemonic('T');
    miBaseBiologic = new JMenuItem("Biological Agent");
    miBaseBiologic.setMnemonic('A');
    miFetalWeight = new JMenuItem("Import Fetal Weight Table");
    miFetalWeight.setMnemonic('F');
    miUserAdmin = new JMenuItem("Users Admin");
    miUserAdmin.setMnemonic('U');

    mnuMaintenance.add(miBaseMalformation);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miBaseSindrom);
    mnuMaintenance.add(miBaseTeratogen);
    mnuMaintenance.add(miBaseBiologic);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miFetalWeight);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miUserAdmin);

    miDisclaimer = new JMenuItem("Disclaimer");
    miAbout = new JMenuItem("About");

    mnuHelp.add(miDisclaimer);
    mnuHelp.addSeparator();
    mnuHelp.add(miAbout);

    mb = new JMenuBar();
    mb.add(mnuUtilities);
    mb.add(mnuMaintenance);
    mb.add(mnuHelp);
    mb.add(Box.createGlue());
    JLabel lblUser = new JLabel();
    lblUser.setText(
        "Active User: "******" ");
    mb.add(lblUser);

    mainBar = new JToolBar();
    btnSearch = new JButton();
    btnCalc = new JButton();
    btnExit = new JButton();
    btnSearch.setIcon(new ImageIcon(getClass().getResource("/icons/search.png"))); // NOI18N
    btnSearch.setToolTipText("Search");
    btnSearch.setFocusable(false);
    btnSearch.setBorderPainted(false);
    btnCalc.setIcon(new ImageIcon(getClass().getResource("/icons/calculator.png"))); // NOI18N
    btnCalc.setToolTipText("Obstet Calculations");
    btnCalc.setFocusable(false);
    btnCalc.setBorderPainted(false);
    btnExit.setIcon(new ImageIcon(getClass().getResource("/icons/exit.png"))); // NOI18N
    btnExit.setToolTipText("Exit");
    btnExit.setFocusable(false);
    btnExit.setBorderPainted(false);

    mainBar.add(btnSearch);
    mainBar.add(btnCalc);
    mainBar.add(btnExit);
    mainBar.setFloatable(false);
    mainBar.setRollover(true);

    imgPanel = new JPanel();
    img = new ImageIcon(getClass().getResource("/Images/logo_title.png"));
    lblImage = new JLabel(img);
    imgPanel.add(lblImage);

    miSearch.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MFSearchWindow();
          }
        });
    miExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            safeExit();
          }
        });
    miBaseMalformation.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MalformationWindow();
          }
        });
    miBaseSindrom.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new SyndromeBaseWindow();
          }
        });
    miBaseTeratogen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new TeratogenBaseWindow();
          }
        });
    miBaseBiologic.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new BiologicAgentWindow();
          }
        });
    miUserAdmin.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new UserWindow();
          }
        });
    miDisclaimer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DisclaimerWindow dis = new DisclaimerWindow();
            dis.btnAgree.setVisible(false);
            dis.btnDisagree.setVisible(false);
            dis.btnClose.setVisible(true);
            dis.setVisible(true);
          }
        });
    miAbout.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new AboutWindow();
          }
        });
    miFetalWeight.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              FileRandomTool rand = new FileRandomTool("TbGOWeight");
              rand.RandomCreate(null);
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(
                  MainWindow.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              ex.printStackTrace(System.err);
            }
          }
        });
    miObstetCalc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
    btnExit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            safeExit();
          }
        });
    btnSearch.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            new MFSearchWindow();
          }
        });
    btnCalc.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
  }
Beispiel #3
0
/**
 * ITS 5201B - Database Pgm Using Java
 *
 * @author Eduardo Quadrado
 * @author Eduardo Pinto
 */
public class MainWindow extends JFrame {
  private SessionController sessionController = SessionController.getInstance();

  // Declaring Variables
  private JMenuBar mb;
  private JMenu mnuUtilities, mnuMaintenance, mnuHelp;
  private JMenuItem miSearch, miExit, miObstetCalc;
  private JMenuItem miBaseMalformation,
      miBaseSindrom,
      miBaseTeratogen,
      miBaseBiologic,
      miFetalWeight,
      miUserAdmin;
  private JMenuItem miDisclaimer, miAbout;
  private ImageIcon img;
  private JLabel lblImage;
  private JPanel imgPanel;
  private JToolBar mainBar;
  private JButton btnSearch, btnCalc, btnExit;

  public MainWindow() {
    try {
      LoginWindow loginDlg = new LoginWindow(this);
      loginDlg.setVisible(true);

      final User user;
      // if logon fail
      if (!loginDlg.ResultLogin()) {
        System.exit(0);
      } else {
        user = loginDlg.getUser();
        sessionController.setUser(user);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    }

    this.initComponents();
    this.setJMenuBar(mb);
    this.add(mainBar, BorderLayout.NORTH);
    this.add(imgPanel, BorderLayout.CENTER);
    this.setSize(800, 535);
    this.setTitle("Diagnosis Helper");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);

    // Check if User logged is Administrator
    if (sessionController.isAdministrator()) {
      mnuMaintenance.setVisible(true);
    } else {
      mnuMaintenance.setVisible(false);
    }

    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            safeExit();
          }
        });
  }

  private void initComponents() {
    mnuUtilities = new JMenu("Utilities");
    mnuMaintenance = new JMenu("Maintenance");
    mnuHelp = new JMenu("Help");

    mnuUtilities.setMnemonic('U');
    mnuMaintenance.setMnemonic('M');
    mnuHelp.setMnemonic('H');

    miSearch = new JMenuItem("Search");
    miSearch.setMnemonic('S');
    miObstetCalc = new JMenuItem("Obstet Calculator");
    miObstetCalc.setMnemonic('O');
    miExit = new JMenuItem("Exit");
    miExit.setMnemonic('x');

    mnuUtilities.add(miSearch);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miObstetCalc);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miExit);

    miBaseMalformation = new JMenuItem("Malformation");
    miBaseMalformation.setMnemonic('M');
    miBaseSindrom = new JMenuItem("Syndrome");
    miBaseSindrom.setMnemonic('y');
    miBaseTeratogen = new JMenuItem("Teratogen");
    miBaseTeratogen.setMnemonic('T');
    miBaseBiologic = new JMenuItem("Biological Agent");
    miBaseBiologic.setMnemonic('A');
    miFetalWeight = new JMenuItem("Import Fetal Weight Table");
    miFetalWeight.setMnemonic('F');
    miUserAdmin = new JMenuItem("Users Admin");
    miUserAdmin.setMnemonic('U');

    mnuMaintenance.add(miBaseMalformation);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miBaseSindrom);
    mnuMaintenance.add(miBaseTeratogen);
    mnuMaintenance.add(miBaseBiologic);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miFetalWeight);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miUserAdmin);

    miDisclaimer = new JMenuItem("Disclaimer");
    miAbout = new JMenuItem("About");

    mnuHelp.add(miDisclaimer);
    mnuHelp.addSeparator();
    mnuHelp.add(miAbout);

    mb = new JMenuBar();
    mb.add(mnuUtilities);
    mb.add(mnuMaintenance);
    mb.add(mnuHelp);
    mb.add(Box.createGlue());
    JLabel lblUser = new JLabel();
    lblUser.setText(
        "Active User: "******" ");
    mb.add(lblUser);

    mainBar = new JToolBar();
    btnSearch = new JButton();
    btnCalc = new JButton();
    btnExit = new JButton();
    btnSearch.setIcon(new ImageIcon(getClass().getResource("/icons/search.png"))); // NOI18N
    btnSearch.setToolTipText("Search");
    btnSearch.setFocusable(false);
    btnSearch.setBorderPainted(false);
    btnCalc.setIcon(new ImageIcon(getClass().getResource("/icons/calculator.png"))); // NOI18N
    btnCalc.setToolTipText("Obstet Calculations");
    btnCalc.setFocusable(false);
    btnCalc.setBorderPainted(false);
    btnExit.setIcon(new ImageIcon(getClass().getResource("/icons/exit.png"))); // NOI18N
    btnExit.setToolTipText("Exit");
    btnExit.setFocusable(false);
    btnExit.setBorderPainted(false);

    mainBar.add(btnSearch);
    mainBar.add(btnCalc);
    mainBar.add(btnExit);
    mainBar.setFloatable(false);
    mainBar.setRollover(true);

    imgPanel = new JPanel();
    img = new ImageIcon(getClass().getResource("/Images/logo_title.png"));
    lblImage = new JLabel(img);
    imgPanel.add(lblImage);

    miSearch.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MFSearchWindow();
          }
        });
    miExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            safeExit();
          }
        });
    miBaseMalformation.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MalformationWindow();
          }
        });
    miBaseSindrom.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new SyndromeBaseWindow();
          }
        });
    miBaseTeratogen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new TeratogenBaseWindow();
          }
        });
    miBaseBiologic.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new BiologicAgentWindow();
          }
        });
    miUserAdmin.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new UserWindow();
          }
        });
    miDisclaimer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DisclaimerWindow dis = new DisclaimerWindow();
            dis.btnAgree.setVisible(false);
            dis.btnDisagree.setVisible(false);
            dis.btnClose.setVisible(true);
            dis.setVisible(true);
          }
        });
    miAbout.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new AboutWindow();
          }
        });
    miFetalWeight.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              FileRandomTool rand = new FileRandomTool("TbGOWeight");
              rand.RandomCreate(null);
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(
                  MainWindow.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              ex.printStackTrace(System.err);
            }
          }
        });
    miObstetCalc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
    btnExit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            safeExit();
          }
        });
    btnSearch.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            new MFSearchWindow();
          }
        });
    btnCalc.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
  }

  private void safeExit() {
    int res = JOptionPane.YES_OPTION;
    res =
        JOptionPane.showOptionDialog(
            null,
            "Finalize Diagnosis Helper ?",
            "Atention",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (res == JOptionPane.YES_OPTION) {
      try {
        ServerController serverController = ServerController.getInstance();
        serverController.close();
      } catch (Exception ex) {
        System.err.println(ex.getMessage());
      }
      System.exit(0);
    }
  }
}