Help with Java please!

Anything else. Post a funny site or tell us about yourself. Discuss current events or whatever else you want. Post off topic threads here.
Post Reply
User avatar
poehalcho
Elite Member
Posts: 6131
Joined: Mon Apr 30, 2007 3:32 pm
Quick Reply: Yes
Location: ┌(╬ಠ益ಠ)╯( ̄ー ̄)(ノ◕ヮ◕)ノ:・✧(╯°Д°)╯彡┻━┻ψ(`∇´)ψ(☞゚∀゚)☞¯\_(ツ)_/¯ლ(ಥ益ಥლ)ԅ༼ ◔ڡ◔༽งヽ༼ʘ̚ل͜ʘ̚༽ノᕕ(ᐛ)ᕗ( ͡° ͜ʖ ͡°)

Help with Java please!

Post by poehalcho »

Ok, so I've got to make a game of blackjack with Java.
The codes for the way the game works are already done. they're set in individual classes.
my job is to make the event-handlers of the main java applet thing work together with the other classes so the game works as a whole.

I have no idea how though D:. I spent my whole day yesterday making event handlers that do what turned out to already have been done in the classes -.-

so anyway. I'm supposed to call upon those methods. And I have no idea how it works.

I just need someone to post a clear example for me to observe.

please, I've wasted so much time on this. even worse, when I started screwing with the event handlers this morning, I cut the stuff I made before and it autosaved. then I got a bsod before I could paste it back >_<.
Image
Day[9] wrote:"Tea is a lot like gold expansions - it helps you kill people."
- Day[9] Daily 337 -

User avatar
Squirt
Forum God
Posts: 8186
Joined: Sat Jan 05, 2008 9:48 pm
Quick Reply: Yes
Location: Off Topic

Re: Help with Java please!

Post by Squirt »

Use banana phone

lol I slacked on java. All I did was a tic tax toe game. Sort of
Image
Spoiler!

woutR wrote:Squirt, you're a genius when it comes to raping women.

User avatar
SM-Count
Ex-Staff
Posts: 2761
Joined: Sat Jan 12, 2008 7:02 pm
Quick Reply: Yes
Location: /wave

Re: Help with Java please!

Post by SM-Count »

Um... multi-threaded examples? MVC or just random classes? A lot of things to consider and they all have different examples... (Or just post the code, er... upload the files somewhere :/)

User avatar
poehalcho
Elite Member
Posts: 6131
Joined: Mon Apr 30, 2007 3:32 pm
Quick Reply: Yes
Location: ┌(╬ಠ益ಠ)╯( ̄ー ̄)(ノ◕ヮ◕)ノ:・✧(╯°Д°)╯彡┻━┻ψ(`∇´)ψ(☞゚∀゚)☞¯\_(ツ)_/¯ლ(ಥ益ಥლ)ԅ༼ ◔ڡ◔༽งヽ༼ʘ̚ل͜ʘ̚༽ノᕕ(ᐛ)ᕗ( ͡° ͜ʖ ͡°)

Re: Help with Java please!

Post by poehalcho »

SM-Count wrote:Um... multi-threaded examples? MVC or just random classes? A lot of things to consider and they all have different examples... (Or just post the code, er... upload the files somewhere :/)


this is the main part:
Spoiler!


These are the classes I'm supposed to use to make it work.

Spoiler!

Spoiler!

Spoiler!


I've made an instance in the first part with:

Code: Select all

 private KaartSpel blackjack = new KaartSpel();


and the

Code: Select all

 public void paint(Graphics g)
     {
         blackjack.teken(g);
     }

is experimental.
Image
Day[9] wrote:"Tea is a lot like gold expansions - it helps you kill people."
- Day[9] Daily 337 -

User avatar
SM-Count
Ex-Staff
Posts: 2761
Joined: Sat Jan 12, 2008 7:02 pm
Quick Reply: Yes
Location: /wave

Re: Help with Java please!

Post by SM-Count »

Yeah.... reading code in a different language isn't gonna work out too well for me. For a game like this, you just have to fire property change events and then call the methods that corresponds with the event. (you come up with the event names obvoiusly) That or use propertychangesupport which is a pretty easy way to do it, just google that and there should be examples.

As to the specific questions, say you don't have all that swing stuff and this was your main method.

Code: Select all

public class Main() {
  private kaartSpel k;

  public Main() {
    k = new kaartSpel();
  }

//... lots of swing code

//gonna pretend this is the button that deals a new hand
  public void nieuwspelKnopActionPerformed(ActionEvent evt) {
    k.deelKaarten();
//alternatively k = new kaartSpel(); k.deelKaarten(); I dunno if there's a reshuffle method or it reshuffles itself or something cause I can't read it but if there is use that instead of just instantiating a new one but you need to have all the cards back before you deal again
  }
}

and that's it... now if you press the thing I pretended was the "deal new hand" button your kaartSpel will have a new hand dealt and store it inside the player/bank list. Of course you'll have to write swing code (/pat) to make it show up and stuff but just stuff all your important things in those action performed methods. The event name (evt) may matter but again I didn't read through the entire code, just skimmed it. For example if you have an ace you can name the evt name for draw card as the card number from your interface and then do a conditional if evt == 0 (assume 0 stands for ace) then pop up a dialog for player to choose whether they want a 1 or 11 and else just have the card number be stored in the player hand list.

Btw, why are there 10 things for the hand list? doesn't black jack only have 2 cards? Maybe it's just the language barrier and you're storing more stuff in there than simple card numbers :/

User avatar
poehalcho
Elite Member
Posts: 6131
Joined: Mon Apr 30, 2007 3:32 pm
Quick Reply: Yes
Location: ┌(╬ಠ益ಠ)╯( ̄ー ̄)(ノ◕ヮ◕)ノ:・✧(╯°Д°)╯彡┻━┻ψ(`∇´)ψ(☞゚∀゚)☞¯\_(ツ)_/¯ლ(ಥ益ಥლ)ԅ༼ ◔ڡ◔༽งヽ༼ʘ̚ل͜ʘ̚༽ノᕕ(ᐛ)ᕗ( ͡° ͜ʖ ͡°)

Re: Help with Java please!

Post by poehalcho »

SM-Count wrote:Btw, why are there 10 things for the hand list? doesn't black jack only have 2 cards? Maybe it's just the language barrier and you're storing more stuff in there than simple card numbers :/


erhh might not've been the exact same thing as blackjack.
my card game knowledge is as limited as my java -.-

the idea of the game was to get as close as possible to 21. if you go over you lose.
if the computer gets closer to 21 than you, you also lose. if the computer goes over 21 you win. you can skip a turn if you think you're chances of getting too high are large.

Also thank you for the explanation. This is much clearer than any of my online instructions D:. I also just received a completed version of the whole thing from a classmate. I'll use your info and his project to make something of my own.

As my thanks, a laugh:
here's an example of how they explain an instance in my instructions:
A new chair that is made under the class Chair is called an instance of Chair. For instance, a kitchen chair is an instance of the class Chair, but a kitchen table is not.

Yes, now they expect me to know everything about instances.
Last edited by poehalcho on Sun May 23, 2010 7:27 pm, edited 4 times in total.
Image
Day[9] wrote:"Tea is a lot like gold expansions - it helps you kill people."
- Day[9] Daily 337 -

User avatar
SM-Count
Ex-Staff
Posts: 2761
Joined: Sat Jan 12, 2008 7:02 pm
Quick Reply: Yes
Location: /wave

Re: Help with Java please!

Post by SM-Count »

edit: didn't see your edit and I'm sorry for how terribly they're teaching you, makes me cringe

User avatar
emperor3000
Frequent Member
Posts: 1049
Joined: Thu Nov 29, 2007 6:43 am
Quick Reply: Yes
Location: Home

Re: Help with Java please!

Post by emperor3000 »

Spoiler!


Spoiler!
Image

User avatar
EvGa
Addicted Member
Posts: 2612
Joined: Wed Apr 23, 2008 4:33 am
Quick Reply: Yes
Location: Texas

Re: Help with Java please!

Post by EvGa »

emperor3000 wrote:
Spoiler!


Spoiler!


OP:Try This

I know you already figured it out but maybe that will help in the future. Finding examples on youtube is a really good way to learn also.
Image

Post Reply

Return to “Off Topic Lounge”