petrusic
Utente Attivo
- Messaggi
- 229
- Reazioni
- 20
- Punteggio
- 46
Per provare particamente la GUI con le modalità swing ho avviato un nuovo progetto che riporto per intero
Non capisco l'errore che viene segnalato alla riga 64
Codice:
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TstContFam {
private static JButton p2 = null;
private int sw = 0;
public static void main(String[] args) {
// TODO Stub di metodo generato automaticamente
JFrame fMain = new JFrame("Verifica congruità Tabelle del DB.ContabFam");
fMain.setBounds(50, 50, 800, 480); //limiti(bounds): x=, y=, w=800, h=480
Container mainForm = fMain.getContentPane();
mainForm.setLayout(new BoxLayout(mainForm, BoxLayout.Y_AXIS));
// disegno un contenitore 'Panel con sviluppo verticale
// |--------------------------------------------------------------------------
JPanel sup = new JPanel();
sup.setLayout(new BoxLayout(sup, BoxLayout.X_AXIS));
// |------------------------------------------------------------------
JPanel arTb = new JPanel();
arTb.setLayout(new BoxLayout(arTb, BoxLayout.X_AXIS));
// |--------------------------------------------------------------
JPanel col1 = new JPanel();
col1.setLayout(new BoxLayout(col1, BoxLayout.Y_AXIS));
JLabel l1 = new JLabel();
col1.add(l1);
JCheckBox cb2 = new JCheckBox("componfam");
col1.add(cb2);
// |--------------------------------------------------------------
JPanel col2 = new JPanel();
col2.setLayout(new BoxLayout(col2, BoxLayout.Y_AXIS));
JLabel c2l1 = new JLabel("Letti");
col2.add(c2l1);
JLabel c2l2 = new JLabel("etichetta");
col2.add(c2l2);
// |--------------------------------------------------------------
JPanel col3 = new JPanel();
col3.setLayout(new BoxLayout(col3, BoxLayout.Y_AXIS));
JLabel c3l1 = new JLabel("Modificati");
col3.add(c3l1);
JLabel c3l2 = new JLabel("etichetta");
col3.add(c3l2);
// |------------------------------------------------------------------
JPanel arMsg = new JPanel();
// arMsg.setLayout(new BoxLayout(arMsg, BoxLayout.X_AXIS));
// |--------------------------------------------------------------
JLabel lMsg = new JLabel("Messaggistica operativa");
arMsg.add(l1);
// |--------------------------------------------------------------------------
JPanel inf = new JPanel();
inf.setLayout(new BoxLayout(inf, BoxLayout.X_AXIS));
// |--------------------------------------------------------------
JButton p1 = new JButton("E S C I");
arMsg.add(p1);
//riga 64----------------------------------------------------------
p1.addActionListener(new clicPuls1());
//---------------------------------------------------------------------- ERRORE ERRORE ERRORE
// JButton p2
p2.setText(("AVVIA VERIFICA"));
arMsg.add(p2);
p2.addActionListener(new clicPuls2());
}
private class clicPuls1 implements ActionListener { // classe privata interna alla principale
// TODO Stub di costruttore generato automaticamente
public void actionPerformed(ActionEvent ev1) {
}
}
private class clicPuls2 implements ActionListener { // classe privata interna alla principale
// TODO Stub di costruttore generato automaticamente
public void actionPerformed(ActionEvent ev2) {
if (sw == 0) {
sw = 1;
p2.setBackground(Color.YELLOW);
}
else {
sw = 0;
p2.setBackground(Color.CYAN);
}
}
}
}
Ciò anche perchè lo stesso codice è ripetuto sotto, alla riga 68, senza alcuna segnalazione d'errore, ma anche perchè, ripetendo i criteri di utilizzo illustrati nella lez.7 del videocorso, secondo me quello che ho scritto doveva essere corretto.Non è possibile accedere a nessuna istanza di inclusione di tipo TstContFam. È necessario qualificare l'allocazione con un'istanza di inclusione di tipo TstContFam (esempio: x.new A() dove x è un'istanza di TstContFam).
