/** Connect the vector of QV's into the main View */ public void installQVs() { Exam thisExam = theTD.curX; Vector qv = thisExam.getListData(); for (int i = 0; i < qv.size(); i++) { // Use question number (1-origin) as string name. // System.out.println("Add question " +i +" to " + questionsPanel); questionsPanel.add(Integer.toString(i + 1), new QView((Q) qv.elementAt(i))); } myCardLayout.first(questionsPanel); }
/** Change the view to display a given question number (1-origin) */ protected void setQNumber(int nn) { String userShowNumber = Integer.toString(nn); System.out.println("setQNumber(" + userShowNumber + ");"); // notify the model // TODO -- if necessary! // update the view numTF.setText(userShowNumber); numSlider.setValue(nn); // show the right question myCardLayout.show(questionsPanel, userShowNumber); }
/** * Réagit au clique de la souris sur un bouton * * @param e L'ActionEvent généré */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JButton) { JButton b = (JButton) e.getSource(); if (b.getName() == "statTab") { // Si on clique sur l'onglet statistiques cartes.show(panneau, "statistiques"); } else if (b.getName() == "payTab") { // Si on clique sur l'onglet de paiement cartes.show(panneau, "paiement"); } else if (b.getName() == "loginButton") { // Si on clique sur le bonton de login char[] input = passTextField.getPassword(); String pass = new String("root"); // Le mot de passe if (pass.equals(new String(input))) { cartes.show(panneau, "paiement"); loginLabel.setText(""); } else loginLabel.setText("Mot de passe incorrect"); Arrays.fill(input, '0'); passTextField.selectAll(); } else if (b.getName() == "annuler") { // Si clique sur annuler // On réserte la sélection et on déselectionne les tables ControleurTables.deleteSelection(); this.tableCounter = 0; this.payTextField.setText(""); this.valider.setEnabled(false); this.valider.setBackground(Color.GRAY); } else if (b.getName() == "valider") { // Si on clique sur valider // On récupère la date Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, (int) this.difTemps); // On récupère le mode de paiement sélectionné String type = new String("carte bleue"); if (especes.isSelected()) { type = "especes"; } else if (cheque.isSelected()) { type = "cheque"; } try { // On verifie que le prix rentré est correct // On met tout dans le meme try pour annuler l'insertion de la commande dans la bdd en cas // d'erreur float prix = Float.parseFloat(payTextField.getText()); ModelePaiement mP = new ModelePaiement(); mP.insert(cal, prix, type); // On recupère la selection ArrayList<Table> tab = ControleurTables.getSelection(); // On met toutes les tables à laver for (int i = 0; i < tab.size(); i++) { tab.get(i).setStatut(Table.ALAVER); tab.get(i).setNom(null); } // On déselectionne les tables ControleurTables.deleteSelection(); this.tableCounter = 0; this.payTextField.setText(""); this.valider.setEnabled(false); this.valider.setBackground(Color.GRAY); // On insère le paiement dans la bdd modeleTable.updateTables(this.tables); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog( null, "Veuillez entrez un rpix valide.", "Erreur prix", JOptionPane.ERROR_MESSAGE); } } else if (b.getName() == "trier") { // Si on appuie sur trier float ca = -1; ModelePaiement mP = new ModelePaiement(); if (service.isSelected()) { // Si on selection le chiffre d'affaire par service ca = mP.getCAService( (String) serviceComboBox .getSelectedItem()); // On sélectonne le chiffre d'affaire en focntion du // service } else if (date.isSelected()) { // Si on selection le chiffre d'affaire par date try { // On verifie que la date est bien valide Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); cal.setTime(sdf.parse(dateTextField.getText())); ca = mP.getCADate(cal); // On va chercher le chiffre d'affaire en fonction de la date } catch (Exception npe) { JOptionPane.showMessageDialog( null, "Veuillez entrez une date de la forme 03/06/2012.", "Erreur date", JOptionPane.ERROR_MESSAGE); } } if (ca > -1) { // Si on a récupérer un chiffre d'affaire chiffreAffaire.setText("Chiffre d'affaire : " + Float.toString(ca)); } } else if (b.getName() == "option") { // Si on clique sur option String strDate = JOptionPane.showInputDialog(null, "Réglage de temps (ex: 03/06/1996 15:06) ", null); try { Calendar cal = Calendar.getInstance(); Calendar now = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); cal.setTime(sdf.parse(strDate)); difTemps = (int) ((cal.getTimeInMillis() - now.getTimeInMillis()) / 1000); // Transformation en secondes if ((cal.getTimeInMillis() - now.getTimeInMillis()) % 1000 > 0) { difTemps++; } } catch (Exception exep) { JOptionPane.showMessageDialog( null, "Vous devez entrer une date valide (ex: 03/06/1996 15:06).", "Date invalide", JOptionPane.ERROR_MESSAGE); } } } }
public SyntaxTab() { super(new BorderLayout(), "Syntax highlighting"); /* * upper checkboxes */ JPanel upper = new JPanel(new GridLayout(2, 1, 0, 0)); upper.setOpaque(false); upper.add(MyPanel.wrap(highlightSyntax)); upper.add(MyPanel.wrap(matchBracket)); highlightSyntax.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { SyntaxTab.this.updateComponentStatus(); } }); this.add(upper, BorderLayout.PAGE_START); /* * upper panel (painters) */ painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getCurrentInstance()); painterComboBox.setFont(f13); if (isMetal) painterComboBox.setBackground(Color.WHITE); painterComboBox.addItemListener(this.painterChangeListener); JButton addPainter = new MyButton("+") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { String name; do { name = JOptionPane.showInputDialog( SyntaxTab.this, "Enter a name:", "Name", JOptionPane.QUESTION_MESSAGE); } while (!myjava.gui.syntax.Painter.isValidPrompt(name, SyntaxTab.this)); if ((name != null) && (!name.isEmpty())) { // name is valid, neither cancelled nor pressed enter directly myjava.gui.syntax.Painter newPainter = ((myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem())) .newInstance(name); addPainter(newPainter); System.out.println("now set, should call listener"); painterComboBox.setSelectedItem(newPainter); // auto-call ItemListener(s) } } }; JButton removePainter = new MyButton("-") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { myjava.gui.syntax.Painter painter = (myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem()); if (painter.equals(myjava.gui.syntax.Painter.getDefaultInstance())) { JOptionPane.showMessageDialog( SyntaxTab.this, "The default painter cannot be removed.", "Error", JOptionPane.ERROR_MESSAGE); } else { int option = JOptionPane.showConfirmDialog( SyntaxTab.this, "Remove painter \"" + painter.getName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { // remove "painter" removedPainters.add(painter); painterComboBox.removeItemListener(painterChangeListener); painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getDefaultInstance()); painterComboBox.removeItem(painter); for (Iterator<EntryListPanel> it = listPanelSet.iterator(); it.hasNext(); ) { EntryListPanel panel = it.next(); if (panel.getPainter().getName().equals(painter.getName())) { System.out.println("removing, then break"); it.remove(); centerPanel.remove(panel); break; } } painterComboBox.addItemListener(painterChangeListener); cardLayout.show( centerPanel, myjava.gui.syntax.Painter.getDefaultInstance().getName()); } } } }; // lower part JPanel center = new JPanel(new BorderLayout()); JLabel selectLabel = new MyLabel("Selected painter:"); center.add( MyPanel.wrap(MyPanel.CENTER, selectLabel, painterComboBox, addPainter, removePainter), BorderLayout.PAGE_START); componentSet.addAll(Arrays.asList(selectLabel, addPainter, removePainter)); center.add(centerPanel, BorderLayout.CENTER); this.add(center, BorderLayout.CENTER); cardLayout.show(centerPanel, myjava.gui.syntax.Painter.getCurrentInstance().getName()); }
public void actionPerformed(ActionEvent e) { String a, b, c, f, g, h, j, k, l, m, n, o, p, tol = ""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:db2"); stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (Exception error) { System.out.println(error); } if (e.getSource() == student) { name = "Student"; cl.show(pnc, "cstu"); try { rs = stm.executeQuery("Select * from Student"); rs.next(); t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == teacher) { name = "Teacher"; cl.show(pnc, "ctea"); try { rs = stm.executeQuery("Select * from Teacher"); rs.next(); t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == course) { name = "Course"; cl.show(pnc, "ccou"); try { rs = stm.executeQuery("Select * from Course"); rs.next(); t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == result) { name = "Result"; cl.show(pnc, "cres"); try { rs = stm.executeQuery("Select * from Result"); rs.next(); t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b6) { Vector cols = new Vector(); Vector rows = new Vector(); if (z == 1) { String sql = "Select * from " + co; try { rs = stm.executeQuery(sql); meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) cols.addElement(meta.getColumnName(i)); while (rs.next()) { Vector currow = new Vector(); for (int i = 1; i <= meta.getColumnCount(); i++) currow.addElement(rs.getString(i)); rows.addElement(currow); } } catch (Exception ex) { System.out.print(ex); } tb = new JTable(rows, cols); js = new JScrollPane(tb); pne2.remove(js); pne2.add(blk, "bb"); cl2.show(pne2, "bb"); pne2.add(js, "jjs"); cl2.show(pne2, "jjs"); pne2.remove(blk); z = 0; } } if (e.getSource() == b1) // **** ADD BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Insert into Student values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "')"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Insert into Teacher values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Insert into Course values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Insert into Result values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "','" + j + "','" + k + "','" + l + "','" + m + "','" + n + "','" + o + "','" + p + "')"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b2) // **** DELETE BUTTON ****// { if (name == "Student") { b = t2.getText(); tol = "Delete from Student where Id = '" + b + "'"; } if (name == "Teacher") { b = t12.getText(); tol = "Delete from Teacher where Id = '" + b + "'"; } if (name == "Course") { b = t8.getText(); tol = "Delete from Course where Id = '" + b + "'"; } if (name == "Result") { b = t16.getText(); tol = "Delete from Result where Code = '" + b + "'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b3) // **** UPDATE BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Update Student set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', CGPA = '" + f + "', Address = '" + g + "', Cell = '" + h + "' where ID = '" + b + "'"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Update Teacher set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', Course = '" + f + "' where ID = '" + b + "'"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Update Course set Name = '" + a + "', Code = '" + b + "', Credit = '" + c + "', Prerecusite = '" + f + "' where Code = '" + b + "'"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Update Result set Course = '" + a + "', Code = '" + b + "', Credit = '" + c + "', A = '" + f + "', B+ = '" + g + "', B = '" + h + "', C+ = '" + j + "', C = '" + k + "', D+ = '" + l + "', D = '" + m + "', F = '" + n + "', I = '" + o + "', W = '" + p + "' where Code = '" + b + "'"; // JOptionPane.showMessageDialog(null,tol,null,JOptionPane.PLAIN_MESSAGE); // tol = "Update Result set Course = '"+a+"', Code = '"+b+"', Credit = '"+c+"' where Code = // '"+b+"'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b4) // **** NEXT BUTTON ****// { if (name == "Student") { try { if (rs.next()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.next()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.next()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.next()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } if (e.getSource() == b5) // **** PREVIOUS BUTTON ****// { if (name == "Student") { try { if (rs.previous()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.previous()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.previous()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.previous()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } }