IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

probleme dans ActionListener


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Mai 2008
    Messages
    29
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 29
    Par défaut probleme dans ActionListener
    bonjour j ai un tout petit probleme
    j ai developpe une interface qui charge un fichier dbf en jtable
    et je veux maintenant develooper un menu
    mai le probleme c est au niveau de listner il me donne cette erreur


    non-static variable this cannot be referenced from a static context
    ouvrir.addActionListener(this);
    addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (TableDemo)
    ouvrir.addActionListener(this);


    et voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    class MyTableModel extends AbstractTableModel implements ActionListener {
     public void actionPerformed(ActionEvent e){
    }
            private String[] columnNames = {"Ref",
                                            "Code",
                                            "Libellé",
                                            "Qté","Qté","date"};
           private Object[][] data ;
     
           public MyTableModel (){
     
            try {
     
          InputStream inputStream  = new FileInputStream("C:\\INVRIMP0.DBF"); // take dbf file as program argument
          DBFReader reader = new DBFReader( inputStream);
     
        Object []rowObjects;
        rowObjects = reader.nextRecord();
           data = new Object[321][6];
     
          //while( (rowObjects = reader.nextRecord() ) != null) {
           int tab[]={0,1,2,10,11,37};
             for(int j=0;j<320;j++){
            System.out.println("Nouvel enregistrement trouvé, j=" + j);
     
           for( int i=0; i<6; i++) 
            this.data[j][i]=rowObjects[tab[i]]; 
            rowObjects = reader.nextRecord();
     
     
          }
    System.out.println();
          // By now, we have itereated through all of the rows
     
          inputStream.close();
        }
        catch( DBFException e) {
     
          System.out.println( e.getMessage());
        }
        catch( IOException e) {
     
          System.out.println( e.getMessage());
        }
     
     
           }
     
           /*public void addNewRow(int ligne) {
    int addline = getRowCount();
    if (ligne != -1)
    addline = ligne +1;
    colonneName.add(addline, "Name");
    colonneLastName.add(addline, "First Name");
     
    this.fireTableStructureChanged();
    }*/
    /*public void addRow()
    	{
    		Vector row = new Vector();
    		row.add("data");
    		row.add(true);
     
     
    		model.addRows(row);}*/
     
     
            public int getColumnCount() {//retourne le nom de colonne
                return columnNames.length;
            }
     
            public int getRowCount() {//
                return data.length;
            }
     
            public String getColumnName(int col) {
                return columnNames[col];
            }
     
            public Object getValueAt(int row, int col) {
                return data[row][col];
            }
     
            /*
             * JTable uses this method to determine the default renderer/
             * editor for each cell.  If we didn't implement this method,
             * then the last column would contain text ("true"/"false"),
             * rather than a check box.
             */
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
            }
     
            /*
             * Don't need to implement this method unless your table's
             * editable.
             */
            public boolean isCellEditable(int row, int col) {
                //Note that the data/cell address is constant,
                //no matter where the cell appears onscreen.
                if (col < 2) {
                    return false;
                } else {
                    return true;
                }
            }
     
            /*
             * Don't need to implement this method unless your table's
             * data can change.
             */
            public void setValueAt(Object value, int row, int col) {
                if (DEBUG) {
                    System.out.println("Setting value at " + row + "," + col
                                       + " to " + value
                                       + " (an instance of "
                                       + value.getClass() + ")");
                }
     
                data[row][col] = value;
                fireTableCellUpdated(row, col);
     
                if (DEBUG) {
                    System.out.println("New value of data:");
                    printDebugData();
                }
            }
     
            private void printDebugData() {
                int numRows = getRowCount();
                int numCols = getColumnCount();
     
                for (int i=0; i < numRows; i++) {
                    System.out.print("    row " + i + ":");
                    for (int j=0; j < numCols; j++) {
                        System.out.print("  " + data[i][j]);
                    }
                    System.out.println();
                }
                System.out.println("--------------------------");
            }
        }
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        public static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("INVENTAIRE");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setExtendedState(JFrame.MAXIMIZED_BOTH );
            JMenuBar menubar=new JMenuBar();
            frame.setJMenuBar(menubar);
            JMenu fichier=new JMenu("fichier");
            menubar.add(fichier);
            JMenuItem ouvrir=new JMenuItem("ouvrir");
            fichier.add(ouvrir);
     
            ouvrir.addActionListener(this);
            //Create and set up the content pane.
            TableDemo newContentPane = new TableDemo();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
     
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
     
    }
    et merci

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Par défaut
    Au niveau de ton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       ouvrir.addActionListener(this);
    il n'y a pas d'objet, juste une classe.

    A remplacer par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
       MyTableModel  Mtm = new MyTableModel ();
       ouvrir.addActionListener(Mtm );
    Nicolas

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme dans request.QueryString("chaine")
    Par soufienne dans le forum ASP
    Réponses: 8
    Dernier message: 24/08/2004, 14h49
  2. Probleme dans une procedure stockée
    Par malbaladejo dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 07/07/2004, 14h08
  3. petit probleme dans une requte POSTGRE SQL
    Par ghis le fou dans le forum Requêtes
    Réponses: 5
    Dernier message: 08/09/2003, 13h51
  4. Probleme dans une clause like !
    Par adil dans le forum Langage SQL
    Réponses: 6
    Dernier message: 15/07/2003, 16h47
  5. Probleme dans ma requete
    Par Kuroro dans le forum Requêtes
    Réponses: 2
    Dernier message: 11/07/2003, 11h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo