Esempio n. 1
0
  public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = {
      "dd MMMMM yyyy",
      "dd.MM.yy",
      "MM/dd/yy",
      "yyyy.MM.dd G 'at' hh:mm:ss z",
      "EEE, MMM d, ''yy",
      "h:mm a",
      "H:mm:ss:SSS",
      "K:mm a,z",
      "yyyy.MMMMM.dd GGG hh:mm aaa"
    };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // == LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
  } // constructor
Esempio n. 2
0
  public FindProf() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Search your campus!");
    JLabel patternLabel2 = new JLabel("");

    patternList = new JComboBox<Object>(searchNames);
    patternList.setEditable(true);
    patternList.setMaximumRowCount(5);
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Building Initials & Room Number:", JLabel.LEADING); // == LEFT
    result = new JLabel(" ");
    result.setHorizontalAlignment(SwingConstants.CENTER);
    result.setForeground(Color.black);
    result.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  } // constructor
  private void initPanel() {
    final JLabel qualityLabel = new JLabel("Preferred video quality:");
    final JComboBox<VideoQuality> qualityList =
        new JComboBox<VideoQuality>(VideoQuality.getItems());
    qualityLabel.setLabelFor(qualityList);
    qualityLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    qualityList.setAlignmentX(Component.LEFT_ALIGNMENT);
    qualityList.setSelectedItem(config.getVideoQuality());

    qualityList.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            config.setVideoQuality((VideoQuality) qualityList.getSelectedItem());
          }
        });

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(qualityLabel);
    add(qualityList);
    add(Box.createRigidArea(new Dimension(0, 15)));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
  }
 /**
  * Constructor to setup GUI components and event handling; Pre: name, author and theme should not
  * be null, avg and pop should not be 0; Post: the user will successfully rate the book.
  *
  * @param bookName is the name of the book.
  * @param author is the author of the book.
  * @param genre is the genre of the book.
  * @param avg is the average score of the book.
  * @param pop is the population of people that have rated the book.
  */
 public GUIBookRating(String bookName, String author, String genre, int avg, int pop) {
   frame = new JFrame("Book Rating");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   contentPane = new JPanel();
   contentPane.setLayout(
       new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); // To use BoxLayout to keep items in order
   contentPane.setBorder(
       BorderFactory.createEmptyBorder(10, 10, 10, 10)); // To create an empty border around items
   label = new JLabel("Please give rank to the book " + bookName + ":");
   label.setFont(f); // To keep the font of texts on items the same
   label.setAlignmentX(
       JLabel.CENTER_ALIGNMENT); // To line the items up at the centre of the window
   label.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   submit = new JButton("Submit");
   submit.setFont(f);
   submit.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   submit.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   rankStop = new JButton("Not Now");
   rankStop.setFont(f);
   rankStop.setAlignmentX(JLabel.CENTER_ALIGNMENT);
   rankStop.setBorder(BorderFactory.createEmptyBorder(5, 12, 5, 12));
   String[] list = {
     "1 Awful >_<", "2 Bad T_T", "3 So So -_-", "4 Good ^_^", "5 Perfect ^3^"
   }; // To create a list for user to choose rate from 1 to 5
   ratingList = new JComboBox(list);
   ratingList.setAlignmentX(JComboBox.CENTER_ALIGNMENT);
   ratingList.setSelectedIndex(0); // Set the original rate to be 1
   submit.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           String rankGet = (String) ratingList.getSelectedItem();
           /*To transfer the rate user chosen in the combobox to the number of rankings in the database*/
           if (rankGet.equalsIgnoreCase("1 Awful >_<")) {
             engine.rankGive(bookName, 1);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(1), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("2 Bad T_T")) {
             engine.rankGive(bookName, 2);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(2), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("3 So So -_-")) {
             engine.rankGive(bookName, 3);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(3), String.valueOf(avg), engine.customerBasedRec(bookName));
           } else if (rankGet.equalsIgnoreCase("4 Good ^_^")) {
             engine.rankGive(bookName, 4);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(4), String.valueOf(avg), engine.bookBasedRec(bookName));
           } else {
             engine.rankGive(bookName, 5);
             GUILogOut out =
                 new GUILogOut(
                     String.valueOf(5), String.valueOf(avg), engine.bookBasedRec(bookName));
           }
           frame.setVisible(false); // Close the window after going to the next step
         }
       });
   rankStop.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           GUIBookInfo info =
               new GUIBookInfo(
                   bookName,
                   author,
                   genre,
                   avg,
                   pop,
                   custrating); // To review the information of the book if the user do not want to
                                // rate the book
           frame.setVisible(false);
         }
       });
   contentPane.add(label);
   contentPane.add(ratingList);
   contentPane.add(submit);
   contentPane.add(rankStop);
   frame.setContentPane(contentPane);
   frame.pack();
   frame.setVisible(true); // Open the pop-up window
   frame.setLocationRelativeTo(
       null); // Set the location of the pop-up window at the centre of the window of computer
 }