ho scritto così:
ma, in compilazione, dà questo errore (la linea interessata è quella boldata):codice:public class pdv implements ActionListener { public static void createAndShowGUI() { ... JLabel l_usr = new JLabel("Username:"); l_usr.setBounds(5, 35, 70, 20); frame.getContentPane().add(l_usr); JButton b_OK = new JButton("Login"); b_OK.addActionListener(this); b_OK.setBounds(100, 90, 80, 20); b_OK.setToolTipText("Clicca per effettuare il login"); frame.getContentPane().add(b_OK); frame.setVisible(true); } } ... public void actionPerformed(ActionEvent ae) { System.out.println("TESTO DI PROVA"); }
ho allora provato a dichiarare non static la void createAndShowGUI() così:pdv.java:68: non-static variable this cannot be referenced from a static context
b_OK.addActionListener(this);
^
1 error
ma dà quest'altro errore:codice:public class pdv implements ActionListener { public void createAndShowGUI() { ... } }
allora ho eliminato la dichiarazione static del metodo main, ed ora compila, ma in esecuxzione dice Exception in thread "main" java.lang.NoSuchMethodError: mainpdv.java:78: non-static method createAndShowGUI() cannot be referenced from a st
atic context
javax.swing.SwingUtilities.invokeLater(new Runnable() { public v
oid run() { createAndShowGUI(); } });
^
1 error

Rispondi quotando