I've been googling and going round in circles, simply put: when the button is clicked i want an image of a card to appear.

class Actions extends JFrame implements ActionListener
    JTextArea textarea = new JTextArea(2,25);
    JButton twist = new JButton("Twist");
    JButton bust = new JButton("Bust");
    public Actions()
        super("Twist or bust!"); //text in title bar
        setSize(300,200); //size of window
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //when window closed close app
        setVisible(true); //make window appear
        Container content = getContentPane(); //main content area for window
        content.setBackground(Color.BLACK); //colour of area
        FlowLayout flowManager = new FlowLayout();
      /*       CODE FOUND ON SUN SITE //Create a button, attach a listener and put the button in a visible spot
      JButton clicker = new JButton("Press me to execute ActionPerformed");
      clicker.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e)
            //change appearance for a thingie that is in a visible spot
            labelInContainerDisplayingImageWhenActionPerformedExecutes.setIcon(new ImageIcon(getClass().getResource("anImage.jpg")));
      getContentPane().add(clicker, BorderLayout.SOUTH);
        twist.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
        getContentPane().add(twist, BorderLayout.SOUTH);
    public void actionPerformed(ActionEvent e) {
            Actions.setIcon(new ImageIcon(getClass().getResource("nufc.gif")));
   /* public void actionPerformed(ActionEvent e) 
        String str="Damn!";
        if(event.getSource()==bust) str+="You lost";
        Image pic = Toolkit.getDefaultToolkit().getImage("nufc.gif");
            if(pic != null) painter.drawImage(pic,15,5,this); 
// someother coding i found in google

I've got a book which tells how to show an image, how to play music when a button is clicked but not how to do an image when a button is clicked. help appriciated :)

and once thats sorted, then display an image randomly choosen from a deck of cards, which means each card has a value, then the values added and that decides if you get another go or you lose.. what i'm trying in C http://www.daniweb.com/techtalkforums/thread72970.html

but i want to add graphics to it, rather than just the command prompt.

so did that make any sense?

10 Years
Discussion Span
Last Post by Akshay_8

Best to take it one step at a time. Create your class for your cards. I.e. consider what methods you are going to need etc.

Then when you've got that locked down move to the GUI.


check this too..
if you are using netbeans then save your image n package folder...

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
ImageIcon icon = new ImageIcon("YourImageName.gif");

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.