public void createControlPanel() {
    pnTitle.setLayout(new FlowLayout());
    pnTitle.setBorder(BorderFactory.createEtchedBorder());
    lblTitle.setFont(new Font("Arial", Font.BOLD, 25));
    pnTitle.add(lblTitle);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    pnCenter.setBorder(BorderFactory.createEtchedBorder());
    pnCenter.setLayout(gridbag);

    c.gridx = 0;
    c.gridy = 1;
    c.gridheight = 1;
    c.insets = new Insets(5, 3, 3, 3);
    c.anchor = GridBagConstraints.SOUTHWEST;
    pnCenter.add(lblCourierId, c);

    c.gridx = 1;
    c.gridy = 1;
    c.gridheight = 1;
    c.insets = new Insets(5, 3, 0, 3);
    c.anchor = GridBagConstraints.SOUTHWEST;
    txtCourierId.setEditable(false);
    txtCourierId.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtCourierId, c);

    c.gridx = 0;
    c.gridy = 2;
    pnCenter.add(lblCourierName, c);

    c.gridx = 1;
    c.gridy = 2;
    txtCourierName.setEditable(false);
    txtCourierName.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtCourierName, c);

    c.gridx = 0;
    c.gridy = 3;
    pnCenter.add(lblCustomerName, c);

    c.gridx = 1;
    c.gridy = 3;
    txtCustomerName.setEditable(false);
    txtCustomerName.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtCustomerName, c);

    c.gridx = 0;
    c.gridy = 4;
    pnCenter.add(lblPhone, c);

    c.gridx = 1;
    c.gridy = 4;
    txtPhone.setEditable(false);
    txtPhone.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtPhone, c);

    c.gridx = 0;
    c.gridy = 5;
    pnCenter.add(lblWeight, c);

    c.gridx = 1;
    c.gridy = 5;
    txtWeight.setEditable(false);
    txtWeight.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtWeight, c);

    c.gridx = 0;
    c.gridy = 6;
    pnCenter.add(lblDepartLocation, c);

    c.gridx = 1;
    c.gridy = 6;
    txtDepartLocation.setEditable(false);
    txtDepartLocation.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtDepartLocation, c);

    c.gridx = 0;
    c.gridy = 7;
    pnCenter.add(lblDestination, c);

    c.gridx = 1;
    c.gridy = 7;
    txtDestination.setEditable(false);
    txtDestination.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtDestination, c);

    c.gridx = 0;
    c.gridy = 8;
    pnCenter.add(lblDistance, c);

    c.gridx = 1;
    c.gridy = 8;
    txtDistance.setEditable(false);
    txtDistance.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtDistance, c);

    c.gridx = 0;
    c.gridy = 9;
    pnCenter.add(lblSender, c);
    c.gridx = 1;
    c.gridy = 9;
    txtSenderShow.setEditable(false);
    txtSenderShow.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtSenderShow, c);

    c.gridx = 0;
    c.gridy = 10;
    pnCenter.add(lblReceiver, c);
    c.gridx = 1;
    c.gridy = 10;
    txtReceiverShow.setEditable(false);
    txtReceiverShow.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtReceiverShow, c);

    c.gridx = 1;
    c.gridy = 11;
    txtSender.setVisible(false);
    txtSender.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtSender, c);

    c.gridx = 1;
    c.gridy = 12;
    txtReceiver.setVisible(false);
    txtReceiver.setPreferredSize(new Dimension(300, 30));
    pnCenter.add(txtReceiver, c);

    pnButton.setLayout(new FlowLayout());
    pnButton.setBorder(BorderFactory.createEtchedBorder());
    pnButton.add(btnConfirm);

    pnMain.setLayout(new BorderLayout());
    pnMain.setBackground(Color.LIGHT_GRAY);
    pnMain.setBorder(BorderFactory.createRaisedSoftBevelBorder());
    pnMain.add(pnTitle, BorderLayout.NORTH);
    pnMain.add(pnCenter, BorderLayout.CENTER);
    pnMain.add(pnButton, BorderLayout.SOUTH);

    getContentPane().add(pnMain, BorderLayout.CENTER);
  }
Exemplo n.º 2
0
  /** @param parent Parent Frame of this panel */
  public AdminView(tester parent) {
    padre = parent;
    try { // Start Setting the look and feel to nimbus
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception e) {
      // If Nimbus is not available, set gui to CrossPlatform
      try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
      } catch (ClassNotFoundException a) {
        // TODO Auto-generated catch block
      } catch (InstantiationException b) {
        // TODO Auto-generated catch block
      } catch (IllegalAccessException c) {
        // TODO Auto-generated catch block
      } catch (UnsupportedLookAndFeelException d) {
        // TODO Auto-generated catch block
      }
    }
    try { // start up the controller
      control = new Controller();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
    } catch (IOException e) {
      // TODO Auto-generated catch block
    }
    // make the panels
    JPanel total = new JPanel(new BorderLayout());
    JPanel test = new JPanel();
    JPanel users = new JPanel();
    JPanel info = new JPanel();
    // set any gaps i want
    Buttons.setVgap(10);
    Info.setHgap(20);
    // set layouts for the panels
    users.setLayout(List);
    test.setLayout(Buttons);
    info.setLayout(Info);
    // Set up the list
    listModel = new DefaultListModel<String>();
    userList = new JList<String>(listModel);
    userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // only one thing at a time
    userList.setVisibleRowCount(10);
    populateUsers();
    // userList.setPreferredSize(new Dimension(200,200));

    userList.setLayoutOrientation(JList.VERTICAL); // lists items vertically
    // put a scroll pane all up in
    JScrollPane userscroller =
        new JScrollPane(
            userList,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    userscroller.setPreferredSize(new Dimension(200, 200));

    // Initialize buttons
    add_user = new JButton("Add User");
    add_user.setPreferredSize(new Dimension(100, 20));
    delete_user = new JButton("Delete User");
    delete_user.setPreferredSize(new Dimension(100, 20));
    logout = new JButton("Logout");
    logout.setPreferredSize(new Dimension(100, 20));
    // add listeners
    add_user.addActionListener(this);
    add_user.setActionCommand("Add");
    delete_user.addActionListener(this);
    delete_user.setActionCommand("Delete");
    logout.addActionListener(this);
    logout.setActionCommand("Logout");
    // add to panels
    test.add(add_user);
    test.add(delete_user);
    test.add(logout);
    test.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10)); // spacing!
    users.add(userscroller);
    users.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 10)); // spacing!

    total.add(users); // everything is contained in total
    total.add(test, BorderLayout.WEST);
    total.setBorder(BorderFactory.createRaisedSoftBevelBorder()); // nice border
    total.setBorder(BorderFactory.createTitledBorder("Welcome Admin"));
    add(total);
  }