Cannot Get grid style map to be drawn in JFrame - java

I am working on a simple game and do not have much JFrame background. How should i go about drawing a grid based map (20x20) with dynamic changes to the tiles (ie set pictures in them)?

Related

Drawing on a JPanel or frame?

I am currently coding a Java program that involves loading an image of a map on a JLabel. I would like to draw on this map image. Is this possible, and if so, how?

Add Buttons and Graphics in the Same Frame?

I am creating a program in which users choose options (which are buttons) and ultimately the program should display a graphics output based on their options. I have created the program with the buttons (which works fine) but I was having trouble with the graphics. I was wondering if it is possible to have both graphics (ex: a black rectangle) and the buttons on the same frame. Or, do I need to exit the frame with the buttons and create a new frame with the graphics? Thank you for any help.

BufferedStrategie on JPanel?

I am programming a game and at the moment I use canvas to render the graphic stuff on it I am using a game loop to render ever 16 ms the player,the Map and so on new.
I wanted to insert buttons on it for some functions like opening a questlog but there is no way to use normal buttons on canvas as far as I got it.
So I asked my programming teacher and he told me to use JPanel instead of canvas so I can use buttons and render my graphics on it.
But when I try to render on a JPanel in my gameloop the game is flickering.
I think this happens because a JPanel don't have bufferedstrategie so I wanted to ask if it's possible to do buffering on JPanel like on a canvas?

Making a hole in a JFrame

I was trying to make a simple GIF capturing app, but I needed to make a hole/transparent space in a JFrame based on a JPanel.
I tried many things, from per-pixel transparency (only works with undecorated windows...), custom shapes (again, undecorated windows only), etc...
This is what I want (edited):
This is what I have:
In .NET Framework, it's as simple as setting the TransparencyKey color of the form, and setting the panel's background color to that color.
I'm wondering if this is possible....

Positioning a label using swing in java

I have been using jFrame to build a GUI. I had to insert images in the GUI, for which i inserted a label and put the image as an icon for the label. Now, i have to find out the position of the image in terms of the x and y co-ordinates and i am unable to do that. I have used
setLocaction(x,y);
but it still doesn't seem to work. I even disabled the layout manager by using
setLayout(null);
What is the possible solution for this problem?
Edit
Basically i am creating a Solar system GUI using Swing, so the positions of the planets are to be set by me. I being new to java, there is being some difficulty in implementing the layouts.
This isn't a layout issue at all, but a drawing and possibly an animation issue. If this were my project, I'd
First and foremost, separate out the program logic from its display, a la the MVC or Model-View-Control pattern, or one of its many variants.
Create one JPanel for the GUI's graphics and do all my drawing in this
I would not display my planet images using ImageIcons inside of JLabels.
Rather, I'd create a background image and draw my planet sprites inside of the drawing JPanel's paintComponent method.
I'd create non-GUI Planet classes that a non-GUI model would hold.
In the GUI portion of my program, I would associate a BufferedImage with each Planet, probably using a HashMap<Plant, Image>.
I'd then draw each Planet's associated image in the drawing JPanel's paintComponent(...) method, and place it depending on the Planet's position field values.
If I wanted to animate this, I'd use a Swing Timer to drive my simple animation.
With null layout you should use setSize and setLocation methods on you label to get your image visible correctly inside your frame.

Categories

Resources