private void setContents(Quiz quiz) { removeAllContent(); titleTxt.setText(quiz.getTitle()); authorTxt.setText(quiz.getAuthor()); for (Question question : quiz.getQuestionList()) { addQuestion(question); } }
public void setParameters(ProblemDescriptors descriptors) { if (descriptors == null) { problemSizeEdit.setText(""); stockLengthEdit.setText(""); orderLengthLowerBoundEdit.setText(""); orderLengthUpperBoundEdit.setText(""); averageDemandEdit.setText(""); } else { problemSizeEdit.setValue(descriptors.getSize()); stockLengthEdit.setValue(descriptors.getStockLength()); orderLengthLowerBoundEdit.setValue(descriptors.getOrderLengthLowerBound()); orderLengthUpperBoundEdit.setValue(descriptors.getOrderLengthUpperBound()); averageDemandEdit.setValue(descriptors.getAverageDemand()); } }
private JPanel createParametersPanel() { JPanel parametersPanel = new JPanel(); parametersPanel.setBorder(BorderFactory.createTitledBorder(dataLayer.getString("PARAMETERS"))); GridLayout parametersPanelLayout = new GridLayout(0, 3); parametersPanelLayout.setHgap(10); parametersPanelLayout.setVgap(5); parametersPanel.setLayout(parametersPanelLayout); // // -- DELAY ------------------------------------------------------------ JLabel delayName = new JLabel(dataLayer.getString("DELAY") + ":"); delayName.setFont(fontBold); parametersPanel.add(delayName); // create formatter RegexFormatter delayFormatter = new RegexFormatter(Validator.DELAY_PATTERN); delayFormatter.setAllowsInvalid(true); // allow to enter invalid value for short time delayFormatter.setCommitsOnValidEdit(true); // value is immedeatly published to textField delayFormatter.setOverwriteMode(false); // do not overwrite charracters jTextFieldDelay = new JFormattedTextField(delayFormatter); jTextFieldDelay.setText("" + cable.getDelay()); jTextFieldDelay.setToolTipText(dataLayer.getString("REQUIRED_FORMAT_IS") + " 1-99"); // add decorator that paints wrong input icon parametersPanel.add(new JLayer<JFormattedTextField>(jTextFieldDelay, layerUI)); JLabel delayTip = new JLabel("1-99"); parametersPanel.add(delayTip); // -- ------------------------------------------------------------ return parametersPanel; }
@Override public JTextField getUserInputComponent() { inputField = new JFormattedTextField(); if (variable.getValue() != null) { inputField.setText("" + variable.getValue()); } return inputField; }
public void setJob(Job job) { jobNameTextField.setEnabled(false); enabledCheckBox.setEnabled(true); saveButton.setEnabled(true); id = job.getId(); jobNameTextField.setText(job.getName()); enabledCheckBox.setSelected(job.isEnabled()); if (job.getIntervalUnit() == null) { onDemandRadioButton.setSelected(true); } else { scheduledRadioButton.setSelected(true); intervalFormattedTextField.setText(String.valueOf(job.getIntervalPeriod())); int index = 0; String[] units = Job.getUnits(); for (int i = 0; i < units.length; i++) if (job.getIntervalUnit().equals(units[i])) index = i; intervalUnitComboBox.setSelectedIndex(index); } }
public void actionPerformed(ActionEvent event) { // if clear button is pressed, clear all fields if (event.getSource() == clear_button) { // erase all fields taskname_field.setText(""); taskdesc_field.setText(""); priority_checkbox.setSelected(false); numberofdays_field.setText(""); // isallocatedcheckbox.setSelected(false); duedate_field.setText(""); } // if submit button is pressed, save all data onto database if (event.getSource() == submit_button) { try { { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); // set to current date calendar.add( Calendar.DAY_OF_MONTH, Integer.parseInt(this.numberofdays_field.getText()) - 1); // add days required... then: // ^ subtract one day, because if task is created today and allocated tomorrow for one // day, // then it should be done by end of day tomorrow Date date = calendar.getTime(); // (see next *1) use this date to be the earliest // because of expected task duration /*This is a constraint * the date and the length of days that user expected to take * if not feasible then the program will say so * */ // method compares the current date and the date that was entered by the user if (this.task_idfield.getText().length() != 7 // check chars || this.taskname_field.getText().length() > 50 // check chars || this.taskdesc_field.getText().length() > 50 || ((Date) this.duedate_field.getValue()).compareTo(date) < 0 // check that the date is possible (see last *1) || this.numberofdays_field.getText().length() > 2 || this.numberofdays_field.getText().length() == 0 // check number of digits || Integer.parseInt(this.numberofdays_field.getText()) < 1) // check number of days required for task { JOptionPane.showMessageDialog( this, "Task ID has to be 7 chars; " + "\n" + "Description <= 50 chars; " + "\n" + "Because the expected duration of the task is " + Integer.parseInt(this.numberofdays_field.getText()) + " days, the due date cannot be earlier than: " + new StringBuffer(new SimpleDateFormat("dd/MM/yyyy").format(date)).toString() + "; " + "\n" + "Task duration must be 2 digit number maximum and must be an integer greater than 0"); } else // check if taskid_field is equals to any of the fields on the database if (task_idfield.equals("")) { JOptionPane.showMessageDialog( this, "Please insert an identification number for a task"); } else // add constraint and tell customer to enter 7 values if (taskname_field.equals("")) { JOptionPane.showMessageDialog(this, "Please insert a name to identity the task"); } else { // get all inputs from user inputs and store in variables taskid_input = task_idfield.getText(); taskname_input = taskname_field.getText(); taskdesc_input = taskdesc_field.getText(); if (priority_checkbox.isSelected()) { priority_input = 1; } else { priority_input = 0; } // create and store date from user input date = (Date) duedate_field.getValue(); // store number of days input from user numberofdays_input = Integer.parseInt(numberofdays_field.getText()); // String[] column_names = { "Task ID", "Task Name", "Task Description", "Task // Priority", "Due Date", "Number of Days", "Is Allocated" , "Unallocateable" }; task = new Object[8]; task[0] = taskid_input; task[1] = taskname_input; task[2] = taskdesc_input; task[3] = priority_input; task[4] = date; task[5] = numberofdays_input; task[6] = 0; task[7] = 0; try { // SqlConnection.connect(); SqlConnection.ps = SqlConnection.connection.prepareStatement( "INSERT INTO TASK VALUES (?,?,?,?,?,?,?,?)"); SqlConnection.ps.setString(1, taskid_input); SqlConnection.ps.setString(2, taskname_input); SqlConnection.ps.setString(3, taskdesc_input); SqlConnection.ps.setInt(4, priority_input); SqlConnection.ps.setDate(5, new java.sql.Date(date.getTime())); SqlConnection.ps.setInt(6, numberofdays_input); SqlConnection.ps.setInt(7, 0); SqlConnection.ps.setInt(8, 0); SqlConnection.ps.executeUpdate(); // now enter skills into TASK SKILL database for (int i = 0; i < skill_list.size(); i++) { if (skill_list.get(i).isSelected()) { String skillid = skill_list.get(i).getText(); SqlConnection.statement.executeUpdate( "INSERT INTO TASKSKILL VALUES ('" + taskid_input + "', '" + skillid + "')"); } } SqlConnection.ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } // SqlConnection.ps.close(); SqlConnection.closeConnection(); this.setVisible(false); } } } catch (Exception exc) { JOptionPane.showMessageDialog( this, "Check your inputs:" + "\n" + "Priority has to be a 1-digit number;" + "\n" + "Date has to be in the format dd/MM/yyyy;" + "\n" + "Task length has to be 2-digit number"); System.out.println(exc); } } // display dialog box asking task manager if they want to quit, // if task manager does not want to quit, go back to adding more tasks // if customer quits, close the dialog box and the frame // now close the window after saving }
@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Acties")) { controller.add(new Actiescreen()); } if (e.getActionCommand().equals("Editmenu")) { JDialog dialog = new JDialog(); dialog.setBounds(0, 0, 300, 500); dialog.add(new EditScreen(1)); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } if (e.getActionCommand().equals("Kalenderoverzicht")) { controller.add(new Kalenderscreen()); } if (e.getActionCommand().equals("Gedachte toevoegen")) { JDialog dialog = new JDialog(); dialog.setTitle("Gedachte Toevoegen"); dialog.setModal(true); dialog.setBounds(0, 0, 300, 500); dialog.add(new EditScreen(2)); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } if (e.getActionCommand().equals("Edit gedachte")) { final JDialog dialog = new JDialog(); dialog.setTitle("Edit gedachte"); dialog.setModal(true); dialog.setBounds(0, 0, 300, 500); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final JTextField text = new JTextField(); JButton button = new JButton("Toepassen"); panel.add(text, BorderLayout.NORTH); panel.add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { String change = text.getText(); int gedachte = controller.getCurrentThought(); DataLayer.changeThought(gedachte, change); dialog.setVisible(false); controller.updateThouhts(); } }); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } if (e.getActionCommand().equals("Gedachte omzetten naar actie")) { ArrayList<Projectscreen> test = controller.getProjects(); if (test.get(0).getList().getSelectedIndex() == -1) { JOptionPane.showMessageDialog(null, "Selecteer eerst een gedachte", "Error", JOptionPane.ERROR_MESSAGE); } else { final JDialog dialog = new JDialog(); dialog.setPreferredSize(new Dimension(500, 200)); dialog.setTitle("Gedachte omzetten naar actie"); dialog.setModal(true); JPanel master = new JPanel(); dialog.add(master); master.setLayout(new GridLayout(0, 1)); // Project kiezen JPanel projects = new JPanel(); projects.setLayout(new BorderLayout()); JLabel projectnaam = new JLabel("Project"); final JComboBox box = new JComboBox(); final ArrayList<Projectscreen> arraylist = controller.getProjects(); Projectscreen thoughts = arraylist.get(0); for (Projectscreen s : arraylist) { if (!s.getNaam().equals("Gedachten")){ String naam = s.getNaam(); box.addItem(naam); box.validate(); } } projects.add(projectnaam, BorderLayout.WEST); projects.add(box, BorderLayout.CENTER); master.add(projects); //gedachte JPanel gedachten = new JPanel(); gedachten.setLayout(new BorderLayout()); JLabel n = new JLabel("Gedachte: "); final JTextField n1 = new JTextField(); final int id = controller.getCurrentThought(); final JList list = thoughts.getList(); final String s = (String) list.getSelectedValue(); String[] s1 = s.split(" "); String s2 = s1[0]; n1.setText(s.replaceFirst(s2, "")); n1.setText(n1.getText().trim()); gedachten.add(n, BorderLayout.WEST); gedachten.add(n1, BorderLayout.CENTER); master.add(gedachten); // beschrijving JPanel beschrijving = new JPanel(); beschrijving.setLayout(new BorderLayout()); JLabel b = new JLabel("Beschrijving"); final JTextArea b1 = new JTextArea(0, 3); b1.setLineWrap(true); b1.setRows(3); b1.setWrapStyleWord(true); b1.setColumns(0); JScrollPane scroll = new JScrollPane(); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.getViewport().setView(b1); beschrijving.add(b, BorderLayout.WEST); beschrijving.add(scroll, BorderLayout.CENTER); master.add(beschrijving); // context JPanel context = new JPanel(); context.setLayout(new BorderLayout()); JLabel co = new JLabel("Context"); final JComboBox co1 = new JComboBox(); co1.setEditable(true); final ArrayList<String> co2 = DataLayer.getContexts(); if (!co2.isEmpty()){ for (String t : co2){ co1.addItem(t); } } context.add(co, BorderLayout.WEST); context.add(co1, BorderLayout.CENTER); master.add(context); // status JPanel status = new JPanel(); status.setLayout(new BorderLayout()); JLabel st = new JLabel("Status"); final JComboBox box1 = new JComboBox(); ArrayList<String> arrayStatus = DataLayer.getStatuses(); for (String t : arrayStatus) { box1.addItem(t.toString()); box1.validate(); } status.add(st, BorderLayout.WEST); status.add(box1, BorderLayout.CENTER); master.add(status); // datum JPanel datum = new JPanel(); datum.setLayout(new BorderLayout()); JLabel d = new JLabel("Datum"); final JFormattedTextField d1 = new JFormattedTextField(new SimpleDateFormat("yyyy-mm-dd")); d1.setText("yyyy-mm-dd"); datum.add(d, BorderLayout.WEST); datum.add(d1, BorderLayout.CENTER); master.add(datum); // button JButton toepassen = new JButton("Toepassen"); master.add(toepassen); toepassen.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { String description = n1.getText(); String notes = b1.getText(); String co3 = (String) co1.getSelectedItem(); boolean bestaat = false; for (String t : co2){ if (t.equals(co3)){ bestaat = true; } } if (!bestaat){ DataLayer.addContext(co3); } String context = co3; String status = box1.getSelectedItem().toString(); int projectid = arraylist.get(box.getSelectedIndex()).getID() + 1; String datum = d1.getText(); int idGedachte = Integer.parseInt("" + s.charAt(0)) - 1; if (datum.equals("yyyy-mm-dd") | datum.equals("")) { JOptionPane.showMessageDialog(null, "Vul een datum in", "Error", JOptionPane.ERROR_MESSAGE); } else { DataLayer.addAction(description, notes, context, status, projectid, datum); DataLayer.deleteThought(idGedachte); controller.updateThouhts(); controller.updateProjects(); dialog.setVisible(false); ArrayList<Projectscreen> project = controller.getProjects(); Projectscreen t = project.get(0); int i = t.getList().getModel().getSize(); int x = t.getList().getSelectedIndex(); } } }); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } } if (e.getActionCommand().equals("Wis gedachte")) { DataLayer.deleteThought(controller.getCurrentThought()); controller.updateThouhts(); } if (e.getActionCommand().equals("Voeg project toe")) { final JDialog dialog = new JDialog(); dialog.setTitle("Project toevoegen"); dialog.setModal(true); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final JTextField naam = new JTextField(); JPanel projectnaam = new JPanel(); projectnaam.setLayout(new BorderLayout()); projectnaam.add(new JLabel("Projectnaam"), BorderLayout.WEST); projectnaam.add(naam, BorderLayout.CENTER); JButton button = new JButton("Aanmaken"); panel.add(projectnaam, BorderLayout.NORTH); panel.add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { String e = DataLayer.addProject(naam.getText()); controller.updateProjects(e); dialog.setVisible(false); validate(); } }); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } if (e.getActionCommand().equals("Bewerk project")) { final JDialog dialog = new JDialog(); dialog.setTitle("Bewerk project"); dialog.setModal(true); dialog.setBounds(0, 0, 300, 500); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final JTextField naam = new JTextField(); final JComboBox box = new JComboBox(); box.setEditable(false); final ArrayList<Projectscreen> projects = controller.getProjects(); projects.remove(0); for (Projectscreen t : projects) { box.addItem(t.getNaam()); box.validate(); } JPanel projectid = new JPanel(); projectid.setLayout(new BorderLayout()); projectid.add(new JLabel("Kies project"), BorderLayout.WEST); projectid.add(box, BorderLayout.CENTER); JPanel projectnaam = new JPanel(); projectnaam.setLayout(new BorderLayout()); projectnaam.add(new JLabel("Nieuwe projectnaam"), BorderLayout.WEST); projectnaam.add(naam, BorderLayout.CENTER); JButton button = new JButton("Bewerk"); panel.add(projectid, BorderLayout.NORTH); panel.add(projectnaam, BorderLayout.CENTER); panel.add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int d = box.getSelectedIndex(); projects.get(d).changeName(naam.getText()); DataLayer.changeProject(projects.get(d).getID(), naam.getText()); dialog.setVisible(false); validate(); } }); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } if (e.getActionCommand().equals("Verwijder project")) { final JDialog dialog = new JDialog(); dialog.setTitle("Wis project"); dialog.setModal(true); dialog.setBounds(0, 0, 300, 500); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final JTextField naam = new JTextField(); final JComboBox box = new JComboBox(); box.setEditable(false); final ArrayList<Projectscreen> projects = controller.getProjects(); projects.remove(0); for (Projectscreen t : projects) { box.addItem(t.getNaam()); box.validate(); } JPanel projectnaam = new JPanel(); projectnaam.setLayout(new BorderLayout()); projectnaam.add(new JLabel("Project"), BorderLayout.WEST); projectnaam.add(box, BorderLayout.CENTER); JButton button = new JButton("Wissen"); panel.add(projectnaam, BorderLayout.NORTH); panel.add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { //pj.deleteProject(naam.getText(), id.getNumber().intValue()); int d = box.getSelectedIndex(); projects.get(d).changeName(naam.getText()); DataLayer.deleteProject(projects.get(d).getID()); controller.updateIDprojects(d); dialog.setVisible(false); validate(); } }); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } if (e.getActionCommand().equals("Uitloggen")) { controller.logOff(); } if (e.getActionCommand().equals("Afsluiten")) { controller.quit(); } }
public void solution() { bloc.setText(String.valueOf(n)); Utilitaire.score -= juste; juste = 1; Utilitaire.score += juste; }
/** * Donne le texte à la case * * @return */ public void setText(String s) { if (n != 0) bloc.setText(s); }
public JobForm() { final JobForm form = this; this.setContentPane(mainPanel); this.setModal(true); saveButton.setEnabled(false); ButtonGroup group = new ButtonGroup(); group.add(onDemandRadioButton); group.add(scheduledRadioButton); jobNameTextField.addKeyListener( new KeyAdapter() { @Override public void keyTyped(KeyEvent keyEvent) { super.keyTyped(keyEvent); saveButton.setEnabled(!jobNameTextField.getText().isEmpty()); } }); ActionListener radioActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { setEnabledOptions(); } }; scheduledRadioButton.addActionListener(radioActionListener); onDemandRadioButton.addActionListener(radioActionListener); intervalUnitComboBox.setModel(new DefaultComboBoxModel(Job.getUnits())); scheduledRadioButton.setSelected(true); intervalFormattedTextField.setText("15"); setEnabledOptions(); intervalFormattedTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent jComponent) { if (jComponent instanceof JFormattedTextField) { JFormattedTextField field = (JFormattedTextField) jComponent; try { parseInt(field.getText()); } catch (NumberFormatException e) { return false; } return true; } return false; } }); saveButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { try { form.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String jobName = jobNameTextField.getText().trim(); int interval = onDemandRadioButton.isSelected() ? 0 : parseInt(intervalFormattedTextField.getText()); String unit = onDemandRadioButton.isSelected() ? "none" : Job.getUnits()[intervalUnitComboBox.getSelectedIndex()]; SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); String now = ISO8601DATEFORMAT.format(new Date()); if (!jobName.matches("^[A-Za-z][A-Za-z0-9_]+")) { form.setCursor(Cursor.getDefaultCursor()); JOptionPane.showMessageDialog( form, "Invalid service name. Job name must start with a letter, \n" + "contain only letters, numbers, and undercores.", "Error creating the job", JOptionPane.ERROR_MESSAGE); return; } if (existingJobNames == null) { existingJobNames = new ArrayList<String>(); for (Job job : AzureRestAPIManager.getManager().listJobs(subscriptionId, serviceName)) { existingJobNames.add(job.getName().toLowerCase()); } } if (existingJobNames.contains(jobName.toLowerCase())) { form.setCursor(Cursor.getDefaultCursor()); JOptionPane.showMessageDialog( form, "Invalid job name. A job with that name already exists in this service.", "Error creating the job", JOptionPane.ERROR_MESSAGE); return; } if (id == null) AzureRestAPIManager.getManager() .createJob(subscriptionId, serviceName, jobName, interval, unit, now); else { AzureRestAPIManager.getManager() .updateJob( subscriptionId, serviceName, jobName, interval, unit, now, enabledCheckBox.isSelected()); } if (afterSave != null) afterSave.run(); form.setCursor(Cursor.getDefaultCursor()); form.setVisible(false); form.dispose(); } catch (Throwable ex) { form.setCursor(Cursor.getDefaultCursor()); UIHelper.showException("Error trying to save job", ex); } } }); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { form.setVisible(false); form.dispose(); } }); }