JFrame disaperes after creation.
Hello guys. what am I doing wrong here ?? Im trying to create a
JFrame from a controler class with
View v = new view(this);
which should create a View as follows
package sspclient;
import javax.swing.*;
import javax.swing.Icon.*;
import java.awt.*;
/**
*
* @author mohed
*/
public class View extends JFrame{
private final String[] type = {"P=C5SE","SAX","STEN"};
// String[] iconAdress = {"Images/paperroundsm.gif","Images/
Scissorsroundsm.gif",
// "Images/Rockroundsm.gif"};
Player[] p = new Player[2];
MFrame[] frames = new MFrame[2];
public class MFrame extends JPanel{
JLabel name = new JLabel();
JTextField msg = new JTextField("msg");
JPanel buttons = new JPanel();
JButton[] sSP = new JButton[3];
JLabel status = new JLabel("Score");
JTextField score = new JTextField();
}
public View(SSPClient ssp){
p[0] = ssp.p[0]; p[1] = ssp.p[1];
FlowLayout fLayout = new FlowLayout();
setLayout(fLayout);
for (MFrame mF : frames) {
mF = new MFrame();
mF.setLayout(new BoxLayout(mF, BoxLayout.PAGE_AXIS));
mF.add(mF.name);
mF.add(mF.msg);
mF.buttons.setLayout(new BoxLayout(mF.buttons,
BoxLayout.LINE_AXIS));
int i = 0;
for (JButton jB : mF.sSP) {
jB = new JButton(type[i]);
// ImageIcon iI = new ImageIcon();
//jB.setIcon(iI);
mF.buttons.add(jB);
jB.addActionListener(ssp);
jB.setActionCommand(type[i]);
i++;
}
mF.add(mF.buttons);
mF.add(mF.status);
mF.add(mF.score);
add(mF);
}
// frames[1].name.setText("Datorn");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void doRefresh(){
int i = 0;
for (MFrame mF : frames){
mF.msg.setText(p[i].moveString);
mF.score.setText(Integer.toString(p[i].getPoints()));
i++;
}
pack();
repaint();
}
}
then when i try to call
v.frames[0].msg.setText("Hello");
I get a nullpointerexception. Now why is that. I just dont get it.
Also if you have any crueteque about my way of coding then that would
be verry verry helpful and thx in advance.
Mohamed Haidar