Ciao a tutti!![]()
Capperi, non ci capisco più niente!
Devo far chiudere un frame tramite la pressione del tasto "Annulla", ho provato ad usare dispose() e setVisible(false), ma il compiler mi da errore, inoltre mi da errore anche nei ricevitori di evento, voi ci capite qualcosa?
Posto il codice e poi l'errore:
codice:import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Screen { public final static boolean RIGHT_TO_LEFT = false; public static void addComponentsToPane(Container contentPane) { if (RIGHT_TO_LEFT) { contentPane.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT); } //Due colonne e dodici righe: contentPane.setLayout(new GridLayout(12,2)); contentPane.add(new JLabel("Nome:")); contentPane.add(new JTextField("Inserisci il nome.")); contentPane.add(new JLabel("Cognome:")); contentPane.add(new JTextField("Inserisci il cognome.")); contentPane.add(new JLabel("Indirizzo:")); contentPane.add(new JTextField("Inserisci l'indirizzo.")); contentPane.add(new JLabel("Ruolo:")); contentPane.add(new JTextField("Inserisci il ruolo.")); contentPane.add(new JLabel("Matricola:")); contentPane.add(new JTextField("Inserisci la matricola.")); contentPane.add(new JLabel("Paga base:")); contentPane.add(new JTextField("Inserisci la paga base.")); contentPane.add(new JLabel("Paga oraria:")); contentPane.add(new JTextField("Inserisci la paga oraria attuale.")); contentPane.add(new JLabel("Ore giornaliere:")); contentPane.add(new JTextField("Inserisci le ore giornaliere lavorative.")); contentPane.add(new JLabel("Sede:")); contentPane.add(new JTextField("Inserisci la sede dell'ufficio.")); contentPane.add(new JLabel("Numero dipendenti:")); contentPane.add(new JTextField("Inserisci il numero dei dipendenti dell'ufficio.")); contentPane.add(new JLabel("Modifica dipendente:")); Choice theoptions = new Choice(); theoptions.addItem("Aggiungi dipendente"); theoptions.addItem("Aggiorna dipendente"); theoptions.addItem("Annulla dipendente"); contentPane.add(theoptions); //Aggiungo i JButton (con i nomi) JButton fineButton = new JButton("Fine"); contentPane.add(fineButton); JButton annullaButton = new JButton("Annulla"); contentPane.add(annullaButton); //ActionListener(s) da implementare dopo questa classe Receiver1 receiver1 = new Receiver1(); Receiver2 receiver2 = new Receiver2(); // assegnazione ActionListener(s) ai corrispondenti JButton(s) assegnazione ActionListener(s) ai corrispondenti JButton(s) fineButton.addActionListener(receiver1); annullaButton.addActionListener(receiver2); } class Receiver1 implements ActionListener { public void actionPerformed(ActionEvent e) { } } class Receiver2 implements ActionListener { public void actionPerformed(ActionEvent e) { frame.setVisible(false); } } private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Screen"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Aggiungo i componenti al pannello: addComponentsToPane(frame.getContentPane()); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }Vi ringrazio per l'attenzione!codice:Screen.java:52: error: No enclosing instance of type Screen is accessible. Must qualify the allocation with an enclosing instance of type Screen (e.g. x.new A() where x is an instance of Screen). Receiver1 receiver1 = new Receiver1(); ^^^^^^^^^^^^^^^ Screen.java:53: error: No enclosing instance of type Screen is accessible. Must qualify the allocation with an enclosing instance of type Screen (e.g. x.new A() where x is an instance of Screen). Receiver2 receiver2 = new Receiver2(); ^^^^^^^^^^^^^^^![]()

Rispondi quotando

