public NewTaskFrame() throws SQLException { this.setModal(true); this.setTitle("Create Task"); // title of frame this.setSize(400, 350); this.setLayout(new BorderLayout()); // layout of frame JLabel task_id = new JLabel("ID:"); JLabel task_name = new JLabel("Name:"); JLabel task_desc = new JLabel("Description:"); JLabel priority = new JLabel("Level of Priority:"); JLabel duedate = new JLabel("Due Date (yyyy-mm-dd)"); JLabel numberofdays = new JLabel("Number of days required:"); JLabel skills_required = new JLabel("Skills Required:"); Object[] id_possibilities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; StringBuffer generated_name = new StringBuffer("t"); for (int i = 0; i < 6; ++i) { generated_name.append( id_possibilities[new java.util.Random().nextInt(id_possibilities.length)]); } task_idfield = new JTextField(generated_name.toString()); taskname_field = new JTextField(); taskdesc_field = new JTextArea(); priority_checkbox = new JCheckBox("High", false); numberofdays_field = new JTextField(); format = new SimpleDateFormat("dd-MM-yyyy"); // set format duedate_field = new JFormattedTextField(format); // set the duedatefield to tomorrow (since minimum task length = 1) java.util.Calendar cal = java.util.Calendar.getInstance(); cal.setTime(new Date()); // get current date cal.add(Calendar.DAY_OF_MONTH, 1); // add 1 to current date Date date = cal.getTime(); // get this date duedate_field.setValue(date); // set this date to the field // panel to hold labels and text fields JPanel labeltextpanel = new JPanel(); labeltextpanel.setLayout(new GridLayout(7, 2)); labeltextpanel.add(task_id); labeltextpanel.add(task_idfield); labeltextpanel.add(task_name); labeltextpanel.add(taskname_field); labeltextpanel.add(task_desc); labeltextpanel.add(taskdesc_field); labeltextpanel.add(priority); labeltextpanel.add(priority_checkbox); labeltextpanel.add(numberofdays); labeltextpanel.add(numberofdays_field); labeltextpanel.add(duedate); labeltextpanel.add(duedate_field); labeltextpanel.add(skills_required); this.getSkills(); // main panel for frame including its layout JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); mainPanel.add(labeltextpanel, BorderLayout.CENTER); // buttons clear_button = new JButton("Clear"); submit_button = new JButton("Submit"); // add listeners to buttons clear_button.addActionListener(this); submit_button.addActionListener(this); // create panel for buttons and add buttons JPanel buttonpanel = new JPanel(); buttonpanel.setLayout(new FlowLayout()); buttonpanel.add(clear_button); buttonpanel.add(submit_button); JPanel checkbox_panel = new JPanel(); checkbox_panel.setLayout(new FlowLayout()); for (int i = 0; i < skill_list.size(); i++) { checkbox_panel.add(skill_list.get(i)); // make this panel flowlayout } scrollpane = new JScrollPane(checkbox_panel); scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(mainPanel, BorderLayout.CENTER); panel.add(scrollpane, BorderLayout.SOUTH); // add the main panel to main frame add(panel, BorderLayout.CENTER); add(buttonpanel, BorderLayout.SOUTH); this.setVisible(true); }
public MakeReservation() { new BorderLayout(); standardRoom.setMnemonic(KeyEvent.VK_K); standardRoom.setActionCommand("Standard Room"); standardRoom.setSelected(true); familyRoom.setMnemonic(KeyEvent.VK_F); familyRoom.setActionCommand("Family Room"); suiteRoom.setMnemonic(KeyEvent.VK_S); suiteRoom.setActionCommand("Suite"); // Add Booking Button ImageIcon bookRoomIcon = createImageIcon("images/book.png"); bookRoom = new JButton("Book Room", bookRoomIcon); bookRoom.setVerticalTextPosition(AbstractButton.BOTTOM); bookRoom.setHorizontalTextPosition(AbstractButton.CENTER); bookRoom.setMnemonic(KeyEvent.VK_M); bookRoom.addActionListener(this); bookRoom.setActionCommand("book"); // Group the radio buttons. group.add(standardRoom); group.add(familyRoom); group.add(suiteRoom); // Create the labels. nameLabel = new JLabel("Name: "); amountroomsLabel = new JLabel("How many rooms? "); checkoutdateLabel = new JLabel("Check-Out Date: "); checkindateLabel = new JLabel("Check-In Date: "); // Create the text fields and set them up. nameField = new JFormattedTextField(); nameField.setColumns(10); amountroomsField = new JFormattedTextField(new Integer(1)); amountroomsField.setValue(new Integer(1)); amountroomsField.setColumns(10); // java.util.Date dt_checkin = new java.util.Date(); LocalDate today = LocalDate.now(); // java.text.SimpleDateFormat sdf_checkin = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkin = today.toString(); checkindateField = new JFormattedTextField(currentDate_checkin); checkindateField.setColumns(10); // java.util.Date dt_checkout = new java.util.Date(); LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS); // java.text.SimpleDateFormat sdf_checkout = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkout = tomorrow.toString(); checkoutdateField = new JFormattedTextField(currentDate_checkout); checkoutdateField.setColumns(10); // Tell accessibility tools about label/textfield pairs. nameLabel.setLabelFor(nameField); amountroomsLabel.setLabelFor(amountroomsField); checkoutdateLabel.setLabelFor(checkoutdateField); checkindateLabel.setLabelFor(checkindateField); // Lay out the labels in a panel. JPanel labelPane1 = new JPanel(new GridLayout(0, 1)); labelPane1.add(amountroomsLabel); JPanel labelPane3 = new JPanel(new GridLayout(0, 1)); labelPane3.add(checkindateLabel); JPanel labelPane2 = new JPanel(new GridLayout(0, 1)); labelPane2.add(checkoutdateLabel); JPanel labelPane4 = new JPanel(new GridLayout(0, 1)); labelPane4.add(nameLabel); // Layout the text fields in a panel. JPanel fieldPane1 = new JPanel(new GridLayout(0, 1)); fieldPane1.add(amountroomsField); JPanel fieldPane3 = new JPanel(new GridLayout(0, 1)); fieldPane3.add(checkindateField); JPanel fieldPane2 = new JPanel(new GridLayout(0, 1)); fieldPane2.add(checkoutdateField); JPanel fieldPane4 = new JPanel(new GridLayout(0, 1)); fieldPane4.add(nameField); // Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(standardRoom); radioPanel.add(familyRoom); radioPanel.add(suiteRoom); // Put the panels in this panel, labels on left, // text fields on right. setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); add(labelPane1, BorderLayout.LINE_START); add(fieldPane1, BorderLayout.LINE_END); add(labelPane3, BorderLayout.LINE_START); add(fieldPane3, BorderLayout.LINE_END); add(labelPane2, BorderLayout.LINE_START); add(fieldPane2, BorderLayout.LINE_END); add(labelPane4, BorderLayout.LINE_START); add(fieldPane4, BorderLayout.LINE_END); add(radioPanel, BorderLayout.LINE_END); add(bookRoom); }