Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why do some of my images load in jar files made in BlueJ, but some don't? I used some of the information around this site

Why do some of my images load in jar files made in BlueJ, but some don't?

I used some of the information around this site to find out to use URLs to get images into a jar file; which I want to be able to be used alone. But when I make the jar file with BlueJ, only some images show up.

Its a blackjack game, and only the table canvas shows up, while no cards ever do. Here's the code:

THIS WORKS (the table):

public class TableComponent extends JLabel{ BufferedImage table; public TableComponent(){ URL finalTable = getClass().getResource("blackjackTableCanvas.jpg"); try { table = ImageIO.read(finalTable); } catch (IOException e) { e.printStackTrace(); } } @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paintComponent(g2); g2.drawImage(table, 0, 0, null); }...} 

but this does not (the cards):

public class CardRender2 extends JComponent{ BufferedImage image; String val; String suit; String filename; public CardRender2(Card card) { this.val = card.value.face; this.suit = card.suit.toString(); filename = this.fetchCardFileLabel(); URL cardview = getClass().getResource("\\card deck\\" + filename + ".png"); try { image = ImageIO.read(cardview); } catch (IOException e) { e.printStackTrace(); } } public CardRender2(){ this.val = null; this.suit = null; filename = "DEALER_FIRST_CARD"; URL cardview = getClass().getResource("\\card deck\\DEALER_FIRST_CARD.png"); try { image = ImageIO.read(cardview); } catch (IOException e) { e.printStackTrace(); } } @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paintComponent(g2); g2.drawImage(image, 0, 0, null); }...} 

my cards are in a folder in the directory I try to import into BlueJ, whereas the table is in the directory root. There are 53 cards in there (incl dealer hidden card) and I'd rather not put all of then in the root. I tried to implement them similarly. How can I do this?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions