ho scritto così:
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");
}
ma, in compilazione, dà questo errore (la linea interessata è quella boldata):
pdv.java:68: non-static variable this cannot be referenced from a static context
b_OK.addActionListener(this);
^
1 error
ho allora provato a dichiarare non static la void createAndShowGUI() così:
codice:
public class pdv implements ActionListener
{
public void createAndShowGUI() {
...
}
}
ma dà quest'altro errore:
pdv.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
allora ho eliminato la dichiarazione static del metodo main, ed ora compila, ma in esecuxzione dice Exception in thread "main" java.lang.NoSuchMethodError: main