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); } }); }
public JPanel getStep2() { JPanel step2 = new JPanel(); step2.setLayout( new MigLayout( "", "[][609.00,grow][][369.00,grow][]", "[22.00,center][255.00,grow][277.00,grow][-90.00][-15.00][]")); JLabel lblAlmostThere = new JLabel("Please confirm your invitation, and upload photos for the event."); lblAlmostThere.setFont(new Font("Segoe UI", Font.PLAIN, 20)); step2.add(lblAlmostThere, "cell 1 0,alignx left,gapx 10 0"); JLabel lblUploadPhotos = new JLabel("Upload photos"); lblUploadPhotos.setFont(new Font("Segoe UI", Font.PLAIN, 18)); step2.add(lblUploadPhotos, "flowx,cell 3 0,alignx center,aligny center"); JPanel panel = new JPanel(); panel.setBorder( new TitledBorder( null, "Event details", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.setLayout(new MigLayout("", "[][]", "[][][][][]")); JLabel lblEventTitle = new JLabel("Title"); panel.add(lblEventTitle, "cell 0 0"); JLabel label = new JLabel(""); panel.add(label, "cell 1 0"); JLabel lblDescription = new JLabel("Description:"); panel.add(lblDescription, "cell 0 4"); ImageUploader uploader = new ImageUploader(); uploader.setBorder(null); step2.add(uploader, "cell 3 1 1 2,gapy 6 0,grow"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(null); scrollPane.setViewportView(panel); step2.add(scrollPane, "cell 1 1,grow"); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBorder( new TitledBorder(null, "Your message", TitledBorder.LEADING, TitledBorder.TOP, null, null)); scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); dtrpnYourMessageHere = new JEditorPane(); dtrpnYourMessageHere.setPreferredSize(new Dimension(200, 20)); dtrpnYourMessageHere.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); dtrpnYourMessageHere.setMargin(new Insets(10, 10, 3, 3)); dtrpnYourMessageHere.setFont(new Font("Segoe Script", Font.PLAIN, 16)); dtrpnYourMessageHere.setText("I look forward to seeing you at the event, I hope you attend..."); scrollPane_1.setViewportView(dtrpnYourMessageHere); step2.add(scrollPane_1, "cell 1 2,grow"); NavigationFooter navigationFooter = new NavigationFooter("step2") { @Override public void navigationButtonClicked() { switchPanels(); } @Override public void sendButtonClicked() { // String subject = "You are invited by "+Account.currentUser.getFirstName() + // Account.currentUser.getLastName(); String subject = "You are invited"; String message = dtrpnYourMessageHere.getText() + "<br/><br/><b>Following are the details for the event:</b> <br/><br/>" + "<b>Title:</b> " + event.getEventName() + "<br/>" + "<b>Description:</b> " + event.getEventDescription() + "<br/>" + "<b>Date and Time:</b> " + event.getEventDate() + " at " + event.getEventTime() + "<br/><br/>" + "<b>Please login to know more about this event.</b><br/>"; if (controller.sendInvitation(event.getID(), subject, message)) { dispose(); } } }; step2.add(navigationFooter, "south,growx,aligny bottom"); JLabel uploadIcon = new JLabel(""); uploadIcon.setIcon(ImageHelper.loadImageIcon("uploadImagesIcon.png", "", -1, 50, 5)); step2.add(uploadIcon, "cell 3 0,aligny bottom,gapy 10 0"); return step2; }
public JPanel getStep1() { JPanel step1 = new JPanel(); step1.setLayout(new MigLayout("", "[403.00,grow]", "[52.00][3.00][341.00,grow,bottom]")); // The heading panel JPanel headerPanel = new JPanel(); headerPanel.setLayout(new MigLayout("", "[-20.00px][284px][]", "[125px]")); JLabel headingLabel = new JLabel("Please specify your contacts..."); headingLabel.setFont(new Font("Segoe UI", Font.PLAIN, 22)); headerPanel.add(headingLabel, "cell 1 0,alignx center,aligny center"); step1.add(headerPanel, "cell 0 0,alignx center,growy"); JLabel headerIcon = new JLabel(""); headerIcon.setIcon(ImageHelper.loadImageIcon("selectContacts.png", "background", -1, 50, 5)); headerPanel.add(headerIcon, "cell 2 0,aligny top"); JPanel actionPanel = new JPanel(); actionPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); step1.add(actionPanel, "flowx,cell 0 1,alignx center,aligny bottom"); actionPanel.setBackground(new Color(255, 204, 51)); actionPanel.setLayout(new MigLayout("", "[119px]", "[33px][]")); JButton plusButton = new JButton(""); plusButton.setIcon(new ImageIcon(ImageHelper.class.getResource("plus.png"))); plusButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { controller.addRow(); } }); actionPanel.add(plusButton, "flowx,cell 0 0,alignx center,aligny bottom"); JButton minusButton = new JButton(""); minusButton.setIcon(new ImageIcon(ImageHelper.class.getResource("minus.png"))); minusButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { controller.deleteRow(table.getSelectedRows()); } }); actionPanel.add(minusButton, "cell 0 0,alignx center,aligny top"); JButton button = new JButton(""); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { controller.searchUsers(); } }); button.setIcon(ImageHelper.loadImageIcon("browseIcon.png", "", -1, 24, 5)); actionPanel.add(button, "cell 0 0"); JLabel lblOrImportFrom = new JLabel(" or import from: "); lblOrImportFrom.setFont(new Font("Segoe UI", Font.PLAIN, 14)); actionPanel.add(lblOrImportFrom, "cell 0 0,alignx left,aligny center"); JButton hotmailImportButton = new JButton("Hotmail"); hotmailImportButton.setIcon( ImageHelper.loadImageIcon("hotmailIcon.png", "Import from Hotmail", -1, 24, 5)); hotmailImportButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { ArrayList<Guest> tempList = new ContactImporter("Hotmail").getContacts(); controller.addRows(tempList); } }); actionPanel.add(hotmailImportButton, "cell 0 0,alignx center,aligny top"); JScrollPane tableScrollPane = new JScrollPane(); tableScrollPane.setViewportView(prepareTable()); step1.add(tableScrollPane, "cell 0 2,grow"); NavigationFooter navigationFooter = new NavigationFooter("step1") { @Override public void navigationButtonClicked() { ArrayList<Integer> invalidRows = controller.validateData(); if (invalidRows.size() == 0) { switchPanels(); } else { String message = "Please fill out all the compulsary fields\nsuch as First name, Last name and Email\n\nPlease check the following rows: \n"; for (Integer row : invalidRows) { message += "Row " + row + "\n"; } JOptionPane.showMessageDialog( this, message, "Please check your contacts' information", JOptionPane.WARNING_MESSAGE); } } }; step1.add(navigationFooter, "south,growx,aligny bottom"); return step1; }
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; }