gammaman
July 5th, 2009, 03:09 PM
It is me again. The one working on the QuizGame. You have to forgive me for being such a pest.
I would like to pass an Image location to the object when it is being created. If you look at the second parameter of the code below, that is the location of my image.
There is an error because the second parameter is considered a String.
frame[0] = new QuestionsFrame("start","C:\\users\\Matt\\Documents\\smwbullet.jpg");
Here is the constructor
public QuestionsFrame(String b1,ImageIcon icon)
{
this.frame = frame;
this.counter = counter;
theicon = icon;
B1 = b1;
//size the frame
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
cp = getContentPane();
cp.setBackground(Color.white);
//create Icon object and set its location
ImageIcon theIcon = new ImageIcon(icon);
// ImageIcon icon1 = new ImageIcon("C:\\users\\Matt\\Documents\\mario1.gif");
JButton button1 = new JButton(B1); //create button
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
mario1.counter+=1;
}
});
ImagePanel = new JPanel();
ImagePanel.setBackground(Color.white);
QuestionPanel = new JPanel();
QuestionPanel.setBackground(Color.BLUE);
add(ImagePanel,BorderLayout.NORTH);
newLabel = new JLabel();
newLabel1 = new JLabel();
//add the icon to the label
// newLabel.setLocation(29,40);
// newLabel1.setLocation(80,80);
newLabel.setPreferredSize((new Dimension(650,500)));
newLabel.setIcon(theicon);
// newLabel.setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
// newLabel1.setIcon(icon1);
ImagePanel.add(newLabel);
ImagePanel.add(newLabel1);
QuestionPanel.add(button1); // adding button to frame
add(QuestionPanel,BorderLayout.SOUTH);
QuestionLabel = new JLabel(Question,JLabel.CENTER);
add(QuestionLabel,BorderLayout.CENTER);
}//end of QuestionFrame Contstructor
As you can see the second parameter of the constructor is ImageIcon icon, I just don't know how do it.
I would like to pass an Image location to the object when it is being created. If you look at the second parameter of the code below, that is the location of my image.
There is an error because the second parameter is considered a String.
frame[0] = new QuestionsFrame("start","C:\\users\\Matt\\Documents\\smwbullet.jpg");
Here is the constructor
public QuestionsFrame(String b1,ImageIcon icon)
{
this.frame = frame;
this.counter = counter;
theicon = icon;
B1 = b1;
//size the frame
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
cp = getContentPane();
cp.setBackground(Color.white);
//create Icon object and set its location
ImageIcon theIcon = new ImageIcon(icon);
// ImageIcon icon1 = new ImageIcon("C:\\users\\Matt\\Documents\\mario1.gif");
JButton button1 = new JButton(B1); //create button
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
mario1.counter+=1;
}
});
ImagePanel = new JPanel();
ImagePanel.setBackground(Color.white);
QuestionPanel = new JPanel();
QuestionPanel.setBackground(Color.BLUE);
add(ImagePanel,BorderLayout.NORTH);
newLabel = new JLabel();
newLabel1 = new JLabel();
//add the icon to the label
// newLabel.setLocation(29,40);
// newLabel1.setLocation(80,80);
newLabel.setPreferredSize((new Dimension(650,500)));
newLabel.setIcon(theicon);
// newLabel.setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
// newLabel1.setIcon(icon1);
ImagePanel.add(newLabel);
ImagePanel.add(newLabel1);
QuestionPanel.add(button1); // adding button to frame
add(QuestionPanel,BorderLayout.SOUTH);
QuestionLabel = new JLabel(Question,JLabel.CENTER);
add(QuestionLabel,BorderLayout.CENTER);
}//end of QuestionFrame Contstructor
As you can see the second parameter of the constructor is ImageIcon icon, I just don't know how do it.