Ejemplo n.º 1
0
  private static void createAndShowGUI() {
    // Check the SystemTray support
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray is not supported");
      return;
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon =
        new TrayIcon(ImageHelper.loadImage("/images/splash.jpg", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem aboutItem = new MenuItem("About");
    CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
    CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
    Menu displayMenu = new Menu("Display");
    MenuItem errorItem = new MenuItem("Error");
    MenuItem warningItem = new MenuItem("Warning");
    MenuItem infoItem = new MenuItem("Info");
    MenuItem noneItem = new MenuItem("None");
    MenuItem exitItem = new MenuItem("Exit");

    // Add components to popup menu
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(cb1);
    popup.add(cb2);
    popup.addSeparator();
    popup.add(displayMenu);
    displayMenu.add(errorItem);
    displayMenu.add(warningItem);
    displayMenu.add(infoItem);
    displayMenu.add(noneItem);
    popup.add(exitItem);

    trayIcon.setPopupMenu(popup);

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.out.println("TrayIcon could not be added.");
      return;
    }

    trayIcon.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray");
          }
        });

    aboutItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item");
          }
        });

    cb1.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb1Id = e.getStateChange();
            if (cb1Id == ItemEvent.SELECTED) {
              trayIcon.setImageAutoSize(true);
            } else {
              trayIcon.setImageAutoSize(false);
            }
          }
        });

    cb2.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb2Id = e.getStateChange();
            if (cb2Id == ItemEvent.SELECTED) {
              trayIcon.setToolTip("Sun TrayIcon");
            } else {
              trayIcon.setToolTip(null);
            }
          }
        });

    ActionListener listener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            MenuItem item = (MenuItem) e.getSource();
            // TrayIcon.MessageType type = null;
            System.out.println(item.getLabel());
            if ("Error".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.ERROR;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR);

            } else if ("Warning".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.WARNING;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING);

            } else if ("Info".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.INFO;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO);

            } else if ("None".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.NONE;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE);
            }
          }
        };

    errorItem.addActionListener(listener);
    warningItem.addActionListener(listener);
    infoItem.addActionListener(listener);
    noneItem.addActionListener(listener);

    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
          }
        });
  }
Ejemplo n.º 2
0
  public JPanel getContentPane() {

    JPanel defaultPanel = new JPanel();
    defaultPanel.setLayout(
        new MigLayout(
            "",
            "[28.00][403.00,grow][][384.00,grow][][384.00,grow][106.00]",
            "[][40.00][20.00][98.00,grow][285.00][27.00][grow][18.00][]"));

    JLabel lblCreateYourInvitation = new JLabel("Welcome, " + guest.getUserName());
    lblCreateYourInvitation.setFont(new Font("Segoe UI", Font.PLAIN, 22));
    defaultPanel.add(lblCreateYourInvitation, "cell 1 1 5 1,alignx center,aligny bottom");

    JPanel form = new JPanel();
    form.setFont(new Font("Segoe UI Light", Font.PLAIN, 11));
    form.setBorder(
        new TitledBorder(
            UIManager.getBorder("TitledBorder.border"),
            "Personal Details",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    defaultPanel.add(form, "cell 1 3 4 5,grow");
    form.setLayout(
        new MigLayout(
            "", "[][176.00,grow][102.00,grow][grow]", "[][][][][][][][][][128.00,grow][69.00]"));

    JLabel lblFirstName = new JLabel("First name: ");
    form.add(lblFirstName, "cell 0 0,alignx left");

    textField = new JTextField();
    textField.setMinimumSize(new Dimension(100, 20));
    textField.setPreferredSize(new Dimension(100, 20));
    textField.setText(Account.currentUser.getFirstName());
    form.add(textField, "cell 1 0,growx");
    textField.setColumns(10);

    JLabel lblLastName = new JLabel("Last name:");
    form.add(lblLastName, "cell 0 1,alignx left");

    textField_1 = new JTextField();
    form.add(textField_1, "cell 1 1,growx");
    textField_1.setColumns(10);
    textField_1.setText(Account.currentUser.getLastName());

    JLabel lblSchool = new JLabel("School:");
    form.add(lblSchool, "cell 0 2,alignx left");

    textField_4 = new JTextField();
    form.add(textField_4, "cell 1 2,growx");
    textField_4.setColumns(10);
    textField_4.setText(Account.currentUser.getSchool());

    JLabel lblEmailAdress = new JLabel("Email adress:");
    form.add(lblEmailAdress, "cell 0 5,alignx left");

    textField_2 = new JTextField();
    textField_2.setText(Account.currentUser.getEmail());
    form.add(textField_2, "cell 1 5,growx");
    textField_2.setColumns(10);

    JLabel lblHandphoneNumber = new JLabel("Phone number:");
    form.add(lblHandphoneNumber, "cell 0 6,alignx trailing");

    textField_5 = new JTextField();
    textField_5.setText(Account.currentUser.getHandphoneNo());
    form.add(textField_5, "cell 1 6,growx");
    textField_5.setColumns(10);

    JLabel lblDateOfBirth = new JLabel("Date of Birth:");
    form.add(lblDateOfBirth, "cell 0 3,alignx left");

    JComboBox<Integer> comboBox = new JComboBox<Integer>();
    form.add(comboBox, "flowx,cell 1 3,growx");

    JComboBox<Integer> comboBox_1 = new JComboBox<Integer>();
    form.add(comboBox_1, "cell 2 3,growx");

    JComboBox<Integer> comboBox_2 = new JComboBox<Integer>();
    form.add(comboBox_2, "cell 1 3,growx");

    JLabel lblNric = new JLabel("NRIC:");
    form.add(lblNric, "cell 0 7,alignx left");

    textField_3 = new JTextField();
    textField_3.setText(Account.currentUser.getNric());
    form.add(textField_3, "cell 1 7,growx");
    textField_3.setColumns(10);

    JLabel lblAddress = new JLabel("Address:");
    form.add(lblAddress, "cell 0 9,aligny top");

    textArea = new JTextArea();
    textArea.setText(Account.currentUser.getAddress());
    textArea.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    form.add(textArea, "cell 1 9 2 1,grow");

    JButton tglbtnUpdateDetails = new JButton("Update details");
    tglbtnUpdateDetails.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            Guest guest = new Guest();
            guest.setUserName(Account.currentUser.getUserName());
            guest.setFirstName(textField.getText());
            guest.setLastName(textField_1.getText());
            guest.setSchool(textField_4.getText());
            guest.setEmail(textField_2.getText());
            guest.setHandphoneNo(textField_5.getText());
            guest.setNric(textField_3.getText());
            guest.setAddress(textArea.getText());
            if (guest.CREATE_GUEST_ACCOUNT(guest)) {
              JOptionPane.showMessageDialog(null, "Your details have been updated successfully");
            }
          }
        });
    tglbtnUpdateDetails.setPreferredSize(new Dimension(101, 40));
    form.add(tglbtnUpdateDetails, "cell 0 10 4 1,alignx center,aligny bottom");

    final JLabel profilePicture = new JLabel("");
    profilePicture.setBorder(
        new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    defaultPanel.add(profilePicture, "flowy,cell 5 3,alignx center,gapy 5 0");
    profilePicture.setIcon(ImageHelper.loadImageIcon("userIcon.png", "", 215, -1, 5));

    JButton btnSelectPhoto = new JButton("Change profile picture");
    btnSelectPhoto.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            ImageIcon backupIcon = (ImageIcon) profilePicture.getIcon();

            Image image = IOHelper.getImageFile();
            if (image != null) {
              profilePicture.setIcon(
                  ImageHelper.getScaledImageIcon(new ImageIcon(image), 200, -1, 5));
            } else {
              profilePicture.setIcon(backupIcon);
            }
          }
        });
    defaultPanel.add(btnSelectPhoto, "cell 5 4,alignx center,aligny top");

    JLabel cutShadow = new JLabel("");
    cutShadow.setIcon(new ImageIcon(ImageHelper.loadImage("cutShadowBottom.png", "testing")));
    defaultPanel.add(cutShadow, "cell 1 8 5 1,alignx center");

    defaultPanel.add(new GuestActionsFooter(), "south,alignx center");

    JLabel lblNewLabel = new JLabel("");
    defaultPanel.add(lblNewLabel, "cell 5 3");
    lblNewLabel.setIcon(
        new ImageIcon(
            ImageHelper.loadImage("cutShadowTop.png", "testing").getScaledInstance(230, -1, 3)));

    return defaultPanel;
  }