ciao anto, ti ringrazio della risposta.
Certo, è tutto istanziato, anzi ti mostro la classe grafica (il codice non è per niente ottimizzato) :
codice:
public Grafica (final Controller controlloPassato)
{
//Controller controlInGrafica = new Controller() ;
controlInGrafica = controlloPassato ;
JFrame window = new JFrame("Interfaccia Grafica");
window.setBounds(400,200,LARGHEZZA,ALTEZZA);
window.setVisible(true);
Border border = LineBorder.createBlackLineBorder() ;
window.getContentPane().setLayout(new GridLayout(1,2)) ;
window.getContentPane().setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT ) ;
JButton [] buttonarray = new JButton [4] ;
JLabel []labelarray = new JLabel [6] ;
JLabel []labelarray2 = new JLabel [6] ;
JPanel pannellosecondario = new JPanel() ;
JTextField [] arraytext = new JTextField[3] ;
JPanel [] pannelli = new JPanel [4] ;
for (int i=0 ; i<2 ; i++)
{
pannelli[i] = new JPanel () ;
pannelli[i].setBorder(border) ;
pannelli[i].setLayout(new GridLayout (4,2)) ;
pannelli[i].setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT) ;
pannelli[i].setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)) ;
}
for (int i=0 ; i<6 ; i++)
{
if (i==0)
{
labelarray[i] = new JLabel("NOME");
}
else if (i==2)
{
labelarray[i] = new JLabel("COGNOME") ;
}
else if (i==4)
{
labelarray[i] = new JLabel("INTERESSI") ;
}
else if (i==1 || i==3 || i==5)
{
labelarray[i] = new JLabel ("") ;
}
labelarray[i].setPreferredSize(new Dimension(20, 10)) ;
labelarray[i].setBorder(border) ;
labelarray[i].setBackground(new Color (76)) ;
pannelli[0].add(labelarray[i]) ;
}
window.getContentPane().add(pannelli[0]) ;
for (int i=0 ; i<6 ; i++)
{
if (i==0)
{
labelarray2[i] = new JLabel("NOME");
pannelli[1].add(labelarray2[i]) ;
labelarray2[i].setPreferredSize(new Dimension(20, 10)) ;
labelarray2[i].setBorder(border) ;
}
else if (i==2)
{
labelarray2[i] = new JLabel("COGNOME") ;
pannelli[1].add(labelarray2[i]) ;
labelarray2[i].setPreferredSize(new Dimension(20, 10)) ;
labelarray2[i].setBorder(border) ;
}
else if (i==4)
{
labelarray2[i] = new JLabel("INTERESSI") ;
pannelli[1].add(labelarray2[i]) ;
labelarray2[i].setPreferredSize(new Dimension(20, 10)) ;
labelarray2[i].setBorder(border) ;
}
else if (i==1 )
{
arraytext[0] = new JTextField ("") ;
pannelli[1].add(arraytext[0]) ;
}
else if (i==3 )
{
arraytext[1] = new JTextField ("") ;
pannelli[1].add(arraytext[1]) ;
}
else if (i==5 )
{
arraytext[2] = new JTextField ("") ;
pannelli[1].add(arraytext[2]) ;
}
}
window.getContentPane().add(pannelli[1]) ;
for (int i=0 ; i<4 ; i++)
{
if (i==0)
{
buttonarray[i] = new JButton("LEGGI CON PROXY 1");
buttonarray[i].addActionListener(new ButtonListener()) ;
pannelli[0].add(buttonarray[i]) ;
}
else if (i==1)
{
buttonarray[i] = new JButton("LEGGI CON PROXY 2") ;
buttonarray[i].addActionListener(new ButtonListener()) ;
pannelli[0].add(buttonarray[i]) ;
}
else if (i==2)
{
buttonarray[i] = new JButton("SETTA CON PROXY 1") ;
buttonarray[i].addActionListener(new ButtonListener()) ;
pannelli[1].add(buttonarray[i]) ;
}
else if (i==3)
{
buttonarray[i] = new JButton ("SETTA CON PROXY 2") ;
buttonarray[i].addActionListener(new ButtonListener()) ;
pannelli[1].add(buttonarray[i]) ;
}
}
}
class ButtonListener implements ActionListener
{
public void actionPerformed(final ActionEvent e)
{
//tramite questa variabile identifico il bottone premuto, estraendone il source
//
final JButton tastoPremuto= (JButton)e.getSource();
if ( tastoPremuto.getText()== "LEGGI CON PROXY 1")
controlInGrafica.letturaProxyUno();
/*
else if ( tastoPremuto.getText()== "LEGGI CON PROXY 2")
controlInGrafica.letturaProxyDue();
else if ( tastoPremuto.getText()== "SETTA CON PROXY 1")
controlInGrafica.settaggioProxyUno();
else if ( tastoPremuto.getText() == "SETTA CON PROXY 2")
controlInGrafica.settaggioProxyDue();
*/
}
}
public void aggiornaGrafica (String name, String surname, String interests)
{
System.out.println("ciao ci sono" + name + surname + interests);
nome = name;
cognome = surname ;
interessi = interests;
labelarray[1].setText(nome) ;
labelarray[3].setText(cognome) ;
labelarray[5].setText(interessi) ;
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
ecco... nel metodo aggiornaGrafica (String, String, String), che viene chiamato esternamente dal Controller, alla riga
labelarray[1].setText(nome) ;
dà errore e non riesco a capire perchè....