public void init () {
// The Container
container = getContentPane();
// The update panel
JPanel updatePanel = new JPanel ();
updateTextField = new JTextField
("UPDATE COFFEES SET SALES = 75 WHERE COF_NAME LIKE 'Espresso'",45);
updatePanel.add(updateTextField, BorderLayout.NORTH);
// The query panel (label + select field)
queryPanel = new JPanel ();
queryTextField = new JTextField("SELECT * FROM COFFEES", 45);
queryPanel.add(queryTextField, BorderLayout.NORTH );
// In the heart a JTable with and instance of our tableModel
tableModel = new QueryTableModel ();
JTable table=new JTable (tableModel);
table.setPreferredScrollableViewportSize(new Dimension(500, 200));
JScrollPane queryScrollPane = new JScrollPane(table);
queryPanel.add(queryScrollPane, BorderLayout.CENTER);
// The tabbed Pane and the whole container
JTabbedPane tabbedPane = new JTabbedPane ();
tabbedPane.addTab("Update", null, updatePanel, "Simple Update Window");
tabbedPane.addTab("Query", null, queryPanel, "Simple Query Window");
container.add(tabbedPane, BorderLayout.CENTER);
// Text in the bottom panel
textArea = new JTextArea("HELLO",4,45);
textArea.setEditable(false);
JScrollPane textScrollPane = new JScrollPane(textArea);
JPanel bottomPanel = new JPanel();
bottomPanel.add(textScrollPane,BorderLayout.CENTER);
container.add(bottomPanel, BorderLayout.SOUTH);
//Add a Listener for the queryTextField
queryTextField.addActionListener(this);
updateTextField.addActionListener(this);
public void actionPerformed(ActionEvent evt) {
String text;
Object TheWidget = evt.getSource();
// user hit return in query Text Field
if (TheWidget == queryTextField) {
text = queryTextField.getText();
//activate the setQuery method of the tableModel
tableModel.setQuery (text);
queryTextField.selectAll();
}
// must have hit return in the other field
else if (TheWidget == updateTextField) {
text = updateTextField.getText();
update (text);
updateTextField.selectAll();
Il contient plusieurs éléments:
public int getColumnCount () {
return noCols; }
public String getColumnName (int i) {
return resColNames[i]; }
public int getRowCount () {
return nRows; ; }
public Object getValueAt (int row, int col) {
return ((String []) cachedData.elementAt(row))[col];
Attention: il faire tourner cela en local:
Installer Java 1.2 (pas testé avec 1.1 + Swing)
Mettre xerces.jar dans votre classpath
Soit: Copier les fichiers FicheModel2.* + FicheFrame2.* + FichePanel2.* + Fiches2.xml
(à Tecfa) monter le drive /comm/ sur PC et y aller