asiavoices
Programmer
Hello all,
I need your help on this one. I've built a very simple application to show new images when a user clicks on a button (like a slide show).
Basically, when a user click on a button it will randomly give you the picture of playing card (Suit and Face)
The images are not stored in array but rather in a directory.
My problem is that when I click on the button, it does not show the random image. No compilation errors where encountered and to check, I've built a small routine to show the results (in text only) and it works. So, its just the images that are not showing up ....
Here's part of my code.
====================================
public class Playcards extends JFrame
implements ActionListener
{
.....
public Playcards()
{
...........
Container contentPane = getContentPane();
...........
hitButton = new JButton("HIT"
hitButton.addActionListener(this);
....................
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(new Color(204,255,204));
buttonPanel.setLayout(new GridLayout(1,6));
.............
imagePanel = new JPanel();
imagePanel.setLayout(new CardLayout(10,10));
imagePanel.add(new JButton(new ImageIcon("../../images/testimage.gif"), "test image"
...........
contentPane.setLayout(new BorderLayout());
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(imagePanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent buttonEvent)
{
Object buttonClicked = buttonEvent.getSource();
if (buttonClicked == hitButton)
{
imagePanel.add(new JButton(new ImageIcon("../../images/newImage.gif"), "New Test image"
validate();
repaint();
......
}
/* ---- This is my main() method ------- */
public static void main (String[] arg)
{
Playcards myApp = new Playcards();
myApp.pack();
myApp.setVisible(true);
}
}
Any ideas why I can't seem to have the picture show up?
Thanks,
Christopher
I need your help on this one. I've built a very simple application to show new images when a user clicks on a button (like a slide show).
Basically, when a user click on a button it will randomly give you the picture of playing card (Suit and Face)
The images are not stored in array but rather in a directory.
My problem is that when I click on the button, it does not show the random image. No compilation errors where encountered and to check, I've built a small routine to show the results (in text only) and it works. So, its just the images that are not showing up ....
Here's part of my code.
====================================
public class Playcards extends JFrame
implements ActionListener
{
.....
public Playcards()
{
...........
Container contentPane = getContentPane();
...........
hitButton = new JButton("HIT"
hitButton.addActionListener(this);
....................
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(new Color(204,255,204));
buttonPanel.setLayout(new GridLayout(1,6));
.............
imagePanel = new JPanel();
imagePanel.setLayout(new CardLayout(10,10));
imagePanel.add(new JButton(new ImageIcon("../../images/testimage.gif"), "test image"
...........
contentPane.setLayout(new BorderLayout());
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(imagePanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent buttonEvent)
{
Object buttonClicked = buttonEvent.getSource();
if (buttonClicked == hitButton)
{
imagePanel.add(new JButton(new ImageIcon("../../images/newImage.gif"), "New Test image"
validate();
repaint();
......
}
/* ---- This is my main() method ------- */
public static void main (String[] arg)
{
Playcards myApp = new Playcards();
myApp.pack();
myApp.setVisible(true);
}
}
Any ideas why I can't seem to have the picture show up?
Thanks,
Christopher