Questions tagged [java-2d]

Java 2D is an API for drawing two-dimensional graphics using the Java programming language.

1076 questions
-1
votes
1 answer

Unable to drawimage on null layout swing

I want to draw some images on screen alongside some JButtons placed in different places of the screen. However whenever I have setLayout(null); the images do not show up on screen. If i don't set it to null I can make the images show up but I can't…
Zolak
  • 23
  • 3
-1
votes
1 answer

Java : read an image inside a binary file (or maybe more generally, from a stream)

I am making a java program that reads a binary file, which contains multiple images (in PNG format), and some binary data. How can i load the images (specifically, as java.awt.Image's) ? So far the only way i have found to load an image is via…
TwilCynder
  • 33
  • 6
-1
votes
2 answers

Java 2D rotate BufferedImage

This question was answered many time but I still can't apply it to my situation. I want to rotate image on 90 degrees clockwise. I'm currently having following code: private void writeImage(BufferedImage sourceImage, String Path) throws IOException…
AstroCool
  • 11
  • 4
-1
votes
1 answer

Why is an image displayed with Graphics.drawImage() in Java not like I drew it

I have BufferedImage that stores .png image (320 x 240) and I draw it on Сanvas with Graphics.drawImage(). But if you look closely, for example, the cross 3 by 3 pixels is actually 4 by 3 pixels. Look my question in the picture: enter image…
Archer
  • 67
  • 11
-1
votes
3 answers

Does anyone know the algorithm used for navigating a Pac-Man maze?

I need an algorithm for this pacman maze. Can anyone help?
Hiren
  • 7
  • 1
-1
votes
2 answers

Wrong result from Rectangle.contains() in java

It appears that the contains() method in Rectangle is not inclusive to the bottom right corner. For example the following code returns "false"; Rectangle r = new Rectangle(0,0,100,100); System.out.println(r.contains(100, 100));
Maxwell
  • 133
  • 1
  • 7
-1
votes
3 answers

After the for loop is finished why nothing is displayed in the applet screen?

Below is a simple Applet Code the problem is after for loop is finished. Nothing is displayed on the applet screen. I guess screen is cleared after for loop is finished. I am unable to fix it I would like to know how to prevent the screen from…
Udesh
  • 2,415
  • 2
  • 22
  • 32
-1
votes
1 answer

Game collision detection with rectangles

I have started with my first game but cannot figure out how the collision detection should work. The goal is that the player should not be able to go into the wall. I have following classes Player(), Wall(), Levels() and Game() Player class is…
-1
votes
1 answer

Gui- make an object move by a certain criteria

I am trying to make a particular "Pacman Game". Basically the main objects are: pacman and fruit. The background image is a picture of a certain map, meaning the game is bound by an exterior frame. The frame itself is set in pixels which I convert…
user6394019
  • 121
  • 5
-1
votes
1 answer

Detecting side of collision

I'm using awt and it's been working great. However, I need to detect the side that one object hits another. For a rectangle, it'd be a simple math, however for another shape (let's say text), it's not as simple. For example, I have a 'player' (a…
My Name
  • 19
  • 3
-1
votes
1 answer

How can I make my components to be evenly placed in a panel?

I have to display dot shaped status viewer, these dots will be displayed in a JPanel. I am searching a way to make it possible that the number of row and columns are computed to make the best use of the space available in the panel. The number of…
iXô
  • 1,133
  • 1
  • 16
  • 39
-1
votes
2 answers

How to make graphics move without showing tracing but keep it when I draw another one?

I was trying to draw a circle in JPanel with paintComponent, when I call repaint() every time it remove all original paint. But when I remove super, it will show the trace of circle moving. So how should I do for keeping the circle after moving…
-1
votes
1 answer

Make a drawn object move around randomly on a JPanel

This is my frog class which is being called by a GUI class. import java.awt.Color; import java.awt.Graphics; import java.util.Random; import javax.swing.ImageIcon; import javax.swing.JLabel; public class Frog implements Runnable { private int…
coderrrrrr
  • 17
  • 4
-1
votes
2 answers

Can't figure out this obstacle for ball animation

I have a task in which I have to make a app in a JFrame. It will contain 5 balls, which move randomly around the form, they can't exit the form and have to hit the borders. There's also an rectangle in the middle of the form, and that's the main…
leKt0
  • 3
  • 5
-1
votes
1 answer

How to copy a rotated square BufferedImage part using Java?

I want to copy a part of BufferedImage, but the copying form is not a simple square but rather a square rotated on some angle. As an output I want to get the BufferedImage with width and height equals to the copying square size and contents from the…
Kivan
  • 1,712
  • 1
  • 14
  • 30