| | |
passing values and displaying images in a GUI
![]() |
Card game (again, or still). This one's got a GUI. Problem is, the draw and stick method need the total value that is made in start. So when call draw() or stick() from the actionPerformed method it needs a value or it won't compile (stick(int) in game1 cannot be applied to () ) (which makes sense)
how do i get round that?
And what sort of code do i use to draw the images when start or draw is clicked? I've tried ToolKit and getImage sort of stuff but they all need a graphics variable to draw it, which is in the paintComponent method i believe.. or something like that.
Code attached as it's long. Does anyone know what i'm asking or how to help?
how do i get round that?
And what sort of code do i use to draw the images when start or draw is clicked? I've tried ToolKit and getImage sort of stuff but they all need a graphics variable to draw it, which is in the paintComponent method i believe.. or something like that.
Code attached as it's long. Does anyone know what i'm asking or how to help?
ok what format are you storing the images of the cards or are you drawing them using java ?
if you are loading them in, then you have two options. load them all at runtime of your GUI this way you wont have any wait time whilst playing the game but will obv take longer to load the app [you could achieve this by loading them into an array for example]. Or you can load them on the fly as you go along this will free up the load time at beginning.
this code will work for both.
for it to work and load all you will need to add a loop.
showing the image in the GUI is the easy part. just simply create a JLabel wherever you wish thte image to be and use the following
hope this helps if ive understood your question right
if you are loading them in, then you have two options. load them all at runtime of your GUI this way you wont have any wait time whilst playing the game but will obv take longer to load the app [you could achieve this by loading them into an array for example]. Or you can load them on the fly as you go along this will free up the load time at beginning.
this code will work for both.
Java Syntax (Toggle Plain Text)
import java.awt.Image; import java.io.File; import javax.imageio.ImageIO; Image[] cards = new Image[52]; try { cards[0] = ImageIO.read(new File("card.jpg")); } catch (Exception e) { System.out.println(e); }
for it to work and load all you will need to add a loop.
showing the image in the GUI is the easy part. just simply create a JLabel wherever you wish thte image to be and use the following
Java Syntax (Toggle Plain Text)
JLabel.setIcon(new ImageIcon(cards[0]));
hope this helps if ive understood your question right
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
i dont understand what you mean by needing a value for the stick() etc. why do you need to run stick at the start ? cant you just say stick(-1) and run a check in stick to see if -1 was entered and tell it to do what you want i.e. bypass the method ? but maybe you can clarify what you want it to do ?
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
•
•
i dont understand what you mean by needing a value for the stick() etc. why do you need to run stick at the start ? cant you just say stick(-1) and run a check in stick to see if -1 was entered and tell it to do what you want i.e. bypass the method ? but maybe you can clarify what you want it to do ?
the user then clicks either twist or stick buttons.
twist button draws and displays another card and adds that value to the previous total (draw() ). Thus it needs the total which was made in eval().
Stick button compares the total to the "opponents" total (a random number) and displays you lose/win etc (stick() ). Hence stick() needs the total value made in eval() (as does draw()).
I've done each method so it's called via actionPerformed. (so when the user clicks).
updated code attached. Problem now (as well as moving the total variable around) is i've got two of the arrays loading the images, one in start() one in draw() (thanks for the array code btw). I tried doing a seperate class with them in, and changing the coding in the switch box but ket saying "cannot find variable"
and i can't change the text back to black >
Last edited by hbk619; May 16th, 2007 at 4:56 pm.
![]() |
Similar Threads
- passing values from a form to a dialog form (VB.NET)
- Passing values (ASP.NET)
- Trying to get card images into a GUI (Python)
- passing values (VB.NET)
Other Threads in the Java Forum
- Previous Thread: I'm having problems too.
- Next Thread: help with a Java program that represents names
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





