コード例 #1
0
  private Container createReturnPane() {
    // Create return button
    returnButton = new JButton(returnAction);

    // Create text fields
    retISBN = new JTextField(15);
    retCustID = new JTextField(15);

    // Create panel and layout
    JPanel pane = new JPanel();
    pane.setOpaque(false);
    GridBagLayout gb = new GridBagLayout();
    pane.setLayout(gb);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 5, 1, 5);

    // Fill panel
    c.anchor = GridBagConstraints.EAST;
    addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1);

    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    addToGridBag(gb, c, pane, retISBN, 1, 0, 3, 1);
    addToGridBag(gb, c, pane, retCustID, 1, 1, 3, 1);

    c.fill = GridBagConstraints.NONE;
    addToGridBag(gb, c, pane, returnButton, 4, 0, 1, 3);

    // Set up VK_ENTER triggering the return button in this panel
    InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    input.put(getKeyStroke("ENTER"), "returnAction");
    pane.getActionMap().put("returnAction", returnAction);

    return pane;
  }
コード例 #2
0
  private Container createBorrowPane() {
    // Initialise date combo boxes
    borDay = new JComboBox();
    borMonth = new JComboBox();
    borYear = new JComboBox();
    String[] days = new String[31];
    for (int i = 0; i < 31; i++) days[i] = String.valueOf(i + 1);
    String[] months = {
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    };
    String[] years = {
      "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014"
    };
    borDay.setModel(new DefaultComboBoxModel(days));
    borMonth.setModel(new DefaultComboBoxModel(months));
    borYear.setModel(new DefaultComboBoxModel(years));
    Calendar today = Calendar.getInstance();
    borDay.setSelectedIndex(today.get(DAY_OF_MONTH) - 1);
    borMonth.setSelectedIndex(today.get(MONTH));
    borYear.setSelectedIndex(today.get(YEAR) - 2005);

    // Create borrow button
    borrowButton = new JButton(borrowAction);

    // Create text fields
    borISBN = new JTextField(15);
    borCustID = new JTextField(15);

    // Create panel and layout
    JPanel pane = new JPanel();
    pane.setOpaque(false);
    GridBagLayout gb = new GridBagLayout();
    pane.setLayout(gb);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 5, 1, 5);

    // Fill panel
    c.anchor = GridBagConstraints.EAST;
    addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Due Date:"), 0, 2, 1, 1);

    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    addToGridBag(gb, c, pane, borISBN, 1, 0, 3, 1);
    addToGridBag(gb, c, pane, borCustID, 1, 1, 3, 1);

    c.fill = GridBagConstraints.NONE;
    addToGridBag(gb, c, pane, borDay, 1, 2, 1, 1);
    addToGridBag(gb, c, pane, borMonth, 2, 2, 1, 1);
    addToGridBag(gb, c, pane, borYear, 3, 2, 1, 1);

    addToGridBag(gb, c, pane, borrowButton, 4, 0, 1, 3);

    // Set up VK_ENTER triggering the borrow button in this panel
    InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    input.put(getKeyStroke("ENTER"), "borrowAction");
    pane.getActionMap().put("borrowAction", borrowAction);

    return pane;
  }