Jump to content

Blackjack interface

- - - - -

  • Please log in to reply
6 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

I'm a beginner on Java GUI so I don't know much.I'm trying to build a Blackjack game and I would like help on GUI. Is a simple Blackjack game with Betting(increase and decrease using buttons), Hit, Stand, Double down and Split. My idea is to create a simple table with one player at first. How I can do it?

  • Player's cards to show on lower and middle level (when split, leave space between pairs)
  • Dealer's cards show on upper middle level (first card face down)
  • Maybe show some chips with betting

I have a folder with cards pictures so the only think is use their address to add them on table.

Thank you
toto7


*Found this picture, want something simple as that.
Attached File  blackjack_table.png   106.82K   43 downloads

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I can only see this GUI being possible with custom painting in java. Maybe one of the GUI guru's can offer some incite on this.

Here are some of the default layout managers that java provides: A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
Note* This isn't custom drawing.

It would be more complicated but you can use custom drawing: Creating the Demo Application (Step 3) (The Java™ Tutorials > Creating a GUI With JFC/Swing > Performing Custom Painting)

If you consider using a simpler UI format though, I think your design can be accomplished using one of the provided layout managers.

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Thank you for help.

I created this very simple table
class DrawingTable extends JPanel {


public void paintComponent(Graphics g) {


	super.paintComponent(g);

	setBackground(new Color(24,101,30));

	Graphics2D  g2d = (Graphics2D) g;

	

	Ellipse2D.Double circle = new Ellipse2D.Double(30,30,460,260);

	g2d.setPaint(new Color(82,160,53));

	g2d.fill(circle);

	g2d.setPaint(new Color(85,43,0));

	g2d.setStroke(new BasicStroke(25));


	g2d.draw(circle);


	}


}

Now how I can add on this table pictures of cards that a player deal?
Thank you
toto_7

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You could make it easier and use an image for the background like the image you linked in your first post. Then just draw the image, and you only have to worry about drawing the cards themselves.

#5
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Can you help me please with the code? As I said, I'm not so good on this.
Thank you

P.S. I will be able to set the cards on the table image?

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#6
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

toto_7 said:

Can you help me please with the code? As I said, I'm not so good on this.
Thank you

P.S. I will be able to set the cards on the table image?

You really need to consult the api. There are methods like fill, setColor, draw, etc. but are for drawing images instead.
Example:
Graphics (Java Platform SE 7 )

The cards can also be drawn using these methods. You'll need to keep track (x,y) of where the cards are on the screen though if you're wanting the users to interact with them.

#7
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Updated my current class and add two more methods

class DrawingTable extends JPanel {


	private Image img = null;

	private int x,y;

	

	public void paintComponent(Graphics g) {


		super.paintComponent(g);

		setBackground(new Color(24,101,30));

		Graphics2D  g2d = (Graphics2D) g;

		

		Ellipse2D.Double circle = new Ellipse2D.Double(30,30,460,260);

		g2d.setPaint(new Color(82,160,53));

		g2d.fill(circle);

		g2d.setPaint(new Color(85,43,0));

		g2d.setStroke(new BasicStroke(25));

	

		g2d.draw(circle);


	}

	

	public void DrawImage(String file, int x, int y) {

		 img =  Toolkit.getDefaultToolkit().getImage(file);

		 this.x = x;

		 this.y = y;

	}

		     

	public void paint(Graphics g) {

		super.paint(g);

		g.drawImage(img, x,y,40,70, this );

		g.finalize();

	}


}

My question now is how I can modify my current code so be able create more than an image a time (Not erase(overwrite) previous)

Thank you
toto_7

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users