Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:53:44+00:00 2026-06-04T01:53:44+00:00

For school I need to make a game dealing [X] random cards. I used

  • 0

For school I need to make a game dealing [X] random cards.
I used this code to buildup and display my images.
There is only one thing going wrong. When displaying the project, only the last card is
displayed.

Is there any way I can show these images next to each other?

public static void main(String[] args) throws FileNotFoundException, IOException {
    Cards cards = new Cards();
    int dealSize = 6;
    deal = cards.getShuffledCards(dealSize);
    System.out.println("Deal of 4 randomly picked cards " + deal);
    f = new JFrame();
    for(int i=0; i < dealSize; i++) {
        card = deal.get(i).toString();
        f.getContentPane().add(setLabel(card));
    }
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocation(200,200);
    f.setVisible(true);



}

public static JLabel setLabel(String fileLocation) throws FileNotFoundException, IOException {
    InputStream file = new BufferedInputStream(
        new FileInputStream([DIRECTORY TO IMAGES]" + fileLocation));
        BufferedImage image = ImageIO.read(file);
        label = new JLabel(new ImageIcon(image));
        return label;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:53:45+00:00Added an answer on June 4, 2026 at 1:53 am

    You would probably have to make an arbitrary grid, in which one card can occupy each part. Like a GridLayout or GridBagLayout.

    From what I can see by skimming your code, you are basically overwriting the last element you put, for each iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this school project I'm making, where I need to make my code
I need to to make for school a simple strategy game simulator. To do
I need to make a poker game for school in c++. I have made
this is for an assignment at school, where I need to determine the size
I need to make an application for school that includes a login and rights.
We need to make some small program for school that rolls 5 dices and
I really need to know how to make collision detection. I can only do
For school I need to make a program in JavaScript that says if circles
I am new to C++. For a school project I need to make a
For a school project, I need to make a simple paint application that can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.