| | |
display image when button clicked
![]() |
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.
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?
Java Syntax (Toggle Plain Text)
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(); content.setLayout(flowManager); /* 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) { getImage(getCodeBase(),"nufc.gif"); } }); getContentPane().add(twist, BorderLayout.SOUTH); bust.addActionListener(this); content.add(twist); content.add(bust); content.add(textarea); setContentPane(content); } 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?
![]() |
Similar Threads
- Passes variable when button is clicked...HELP! (ASP)
- Java image programming question (Java)
- how to display one image per day from an array? (JSP)
- Get visual basic to bring up another form when a button is clicked (Visual Basic 4 / 5 / 6)
- Display image from a database get me ascii codes (ASP)
- Preview Upload Image Problem (PHP)
- Display image for background (Java)
- How to display a HTML file (in browser window) from Java Program...? (Java)
Other Threads in the Java Forum
- Previous Thread: Java Applet MouseDragged Event
- Next Thread: Magic Square
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield jtree julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source oracle plazmic print problem program project property recursion ria scanner search server set sharepoint smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree unlimited webservices windows






