codice:
package video.client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import oracle.jdeveloper.layout.XYConstraints;
import oracle.jdeveloper.layout.XYLayout;
public class HelpAboutPanel extends JFrame {
private XYLayout xyLayout = new XYLayout();
private String jver = System.getProperty("java.version");
private JButton jButton;
private JFrame window;
public static final int LARGHEZZA = 250;
public static final int ALTEZZA = 250;
public HelpAboutPanel() {
window = new JFrame("About");
window.setLayout( xyLayout );
window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
window.setBounds(0,0,LARGHEZZA,ALTEZZA);
JLabel jLabel1 = new JLabel("Progetto sviluppato da:");
JLabel jLabel2 = new JLabel("aaa");
JLabel jLabel3 = new JLabel("bbb");
JLabel jLabel4 = new JLabel("ccc");
JLabel jLabel5 = new JLabel("Java Version: " + jver);
window.add(jLabel1, new XYConstraints(20, 20, -1, -1));
window.add(jLabel2, new XYConstraints(20, 55, -1, -1));
window.add(jLabel3, new XYConstraints(20, 75, -1, -1));
window.add(jLabel4, new XYConstraints(20, 95, -1, -1));
window.add(jLabel5, new XYConstraints(20, 135, -1, -1));
jButton = new JButton("OK");
jButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent ae ) { AboutExit_ActionPerformed( ae ); } } );
window.add(jButton, new XYConstraints(95, 170, -1, -1));
window.setLocationRelativeTo(null);
window.setVisible(true);
}
void AboutExit_ActionPerformed(ActionEvent e) {
if (e.getSource() == jButton)
window.dispose();
}
}
se elimino il metodo AboutExit_ActionPerformed, cambio la dichiarazione di window, da private a final, e sostituisco questa riga:
codice:
jButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent ae ) { AboutExit_ActionPerformed( ae ); } } );
con questa
codice:
jButton.addActionListener( new ActionListener() {
public void actionPerformed() { window.dispose; } } );
non funziona.. mi da i seguenti errori:
Error(37,57): anonymous class should be declared abstract; it does not define method actionPerformed(java.awt.event.ActionEvent) of interface java.awt.event.ActionListener
Error(38,44): not an expression statement
e a parte questo.. volevo farlo con JDialog ma non ci sono riuscito, perciò ho optato per JFrame.. come dovrei modificare il codice di cui sopra per usare una dialog, invece di un frame?