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 6900171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:30:45+00:00 2026-05-27T07:30:45+00:00

public class MinesweeperMenu extends MinesweeperPanel{ private JPanel picture = new JPanel(); private JButton play

  • 0
public class MinesweeperMenu extends MinesweeperPanel{

private JPanel picture = new JPanel();
private JButton play = new JButton("Play");
private JButton highScores = new JButton("High Score and \nStatistics");
private JButton changeMap = new JButton("Create Custom \nor Change Map");
private JButton difficulty = new JButton("Custom or\nChange Difficulty");
private JButton user = new JButton("Change User");
Image img;

public MinesweeperMenu()
{
    // Set Layout for the menu
    LayoutManager menuLayout = new BoxLayout(menu, BoxLayout.Y_AXIS);
    menu.setLayout(menuLayout);

    // Set Layout for the window
    LayoutManager windowLayout = new BorderLayout();
    window.setLayout(windowLayout);

    // Add buttons to the panels
    menu.add(play);
    menu.add(highScores);
    menu.add(changeMap);
    menu.add(difficulty);
    menu.add(user);

    // Add picture to the frame
    try{
    File input = new File("./setup/images/MineMenuPicture.jpg");
    img = ImageIO.read(input);
    }
    catch(IOException ie)
    {
        System.out.println(ie.getMessage());
    }

    // Add action listeners
    changeMap.addActionListener(new ChangeMapListener());   

}


public void paintComponent(Graphics g)
{
    // POSITION OF THE PICTURE
    int x = 650;
    int y = 585;
    g.drawImage(img, x, y, null);
}

public void displayFrame()
{
    // Display Frame
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

public static void main(String[] args)
{
    MinesweeperMenu menu = new MinesweeperMenu();
    window.pack();
    menu.displayFrame();
    window.repaint();
}
}


public class MinesweeperPanel extends JFrame{

public static final Color COLOR_KEY = new Color(220, 110, 0);

// Initialize all the objects
public static JFrame window = new JFrame("Minesweeper++");
public static JPanel menu = new JPanel();

// Close the current window
public static void close()
{
    window.setVisible(false);
    window.dispose();
}



}

I can’t get my image to display in the frame. I’ve tried everything, but I’m getting the impression it’s a mistake that I’m not realizing since I am new to Java Swing. Any help would be greatly appreciated.

  • 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-05-27T07:30:46+00:00Added an answer on May 27, 2026 at 7:30 am

    You’re making things difficult for yourself by having a very confusing program structure, and I suggest that you simplify things a lot.

    For one, there’s no need for your current MinesweeperMenu class to extend MinesweeperPanel, and for the latter class to extend JFrame. Then you have a static JFrame somewhere else — that’s too many JFrames, and to boot, you’re trying to display your image in one JFrame but showing the other one that doesn’t have the picture. Your program needs just one JFrame and it should probably be created, stuffed with its contents, packed and displayed in one place, not scattered here and there as you’re doing.

    You’re trying to display the picture in a paintComponent override, but this method will never get called since your class extends JFrame (eventually) and JFrame doesn’t have this method. You’re using the right method, but the class should be extending JPanel, and you should have an @Override annotation above the paintComponent method block to be sure that you’re actually overriding a parent method.

    You should get rid of all static everything in this program. The only thing static here should be the main method and perhaps some constants, but that’s it.

    There are more errors here, and I have too little time to go over all of them. Consider starting from the beginning, starting small, getting small bits to work, and then adding them together.

    For instance, first create a very small program that tries to read in an image into an Image object, place it in a ImageIcon, place the ImageIcon into a JLabel, and display the JLabel in a JOptionPane, that simple, just to see if you can read in images OK, for example, something like this:

    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    
    public class TestImages {
    
       // *** your image path will be different *****
       private static final String IMG_PATH = "src/images/image01.jpg";
    
       public static void main(String[] args) {
          try {
             BufferedImage img = ImageIO.read(new File(IMG_PATH));
             ImageIcon icon = new ImageIcon(img);
             JLabel label = new JLabel(icon);
             JOptionPane.showMessageDialog(null, label);
          } catch (IOException e) {
             e.printStackTrace();
          }
       }
    }
    

    Then when you’ve done this, see if you can now create a JPanel that shows the same Image in its paintComponent method, and display this JPanel in a JOptionPane.

    Then create a JFrame and display the image-holding JPanel in the JFrame.

    Through successive iterations you’ll be testing concepts, correcting mistakes and building your program.

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

Sidebar

Related Questions

public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class PeopleCollection : IEnumerable { private Dictionary<string, Person> listPeople = new Dictionary<string, Person>();
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class WordDisplay extends Activity { private int level; private int group; private int
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class GenericDao <T, PK extends Serializable> { private final Class<T> type; @Resource(name =
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private

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.