Questions tagged [java-2d]

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

1076 questions
-1
votes
2 answers

Images no displaying in my java program

Recently i decided to start learning how to make 2D games With JAVA ( eclipse ) so i found a tutorial online that shows how to make superMari game with java, i wrote the same code he wrote and i followed step by step what he did, which wasn't a big…
user6534005
-1
votes
3 answers

Shape will not appear when I add JButton to JPanel

I'm trying to make a panel that contains a shape and a button. The issue is that when I add a button to the JPanel, the shape does not appear. It just shows the button on the top of my screen. The square only shows up when add the square to the…
-1
votes
2 answers

How to find out where a line collides with something?

I have an origin of a line at point (xo, yo), and I have multiple "walls" which are square rectangles with x and y values at the top left corner. The line is meant to follow something (the player as a motion tracker to be specific), but it should…
Miles
  • 487
  • 3
  • 12
-1
votes
1 answer

JavaSwing coordination on JPanel issue?

I use netbeans IDE to create Gui then I customize the Jpanel2 and draw polygon on it this is code snippet int[] polygonXs = { 151, 153, 158, 159, 154}; int[] polygonYs = { 6, 1, 3, 8, 10}; Shape shape = new Polygon(polygonXs, polygonYs,…
Sarin Suriyakoon
  • 420
  • 1
  • 7
  • 19
-1
votes
1 answer

How can I scale points to fit a fixed size graph?

I'm trying to graph x,y points on a fixed 600x600 pixel JPanel. The origin (0,0) is at the center of the panel (300,300). I can have points ranging from 0,0 to well into the positive or negative thousands. How can I scale them so the points farthest…
Ryan Miles
  • 307
  • 4
  • 11
-1
votes
2 answers

Java -> Basic Drawing -> Howto -> Button click adds a shape to a jpanel

Could someone provide a basic example of a Java ui wherein a button click draws a rectangle on a jpanel that's next to it? You find examples of drawing where the mouse is captured, or drawing that's static from loading the ui, but I couldn't find an…
InnerOrchestra
  • 37
  • 2
  • 10
-1
votes
1 answer

Rotating Ball loses sharpness and colors

package testIDE; import java.awt.BorderLayout; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.ArrayList; import javax.swing.ImageIcon; import…
user3133542
  • 1,695
  • 4
  • 21
  • 42
-1
votes
1 answer

Repaint with java2D and swing JPanel

This is my first question here, so I hope it will meet the requirements. I have developed an UI in Swing that updates its central part when the user click on radio buttons to change the number of players. The central UI is a JPanel on which I draw…
zorglub
  • 3
  • 2
-1
votes
2 answers

what calls paintComponent()?

I am attempting to draw sprites out of a sprite sheet. I have the following class public class GTComponent extends JComponent { Graphics2D g2; @Override public void paintComponent(Graphics g){ g2 = (Graphics2D)g; } …
DarkDestry
  • 183
  • 1
  • 11
-1
votes
1 answer

Java: Ball Collision with Frame

Not knowing how to do this is killing me. I currently have a frame with a ball which moves diagonally downwards and right, when it collides with the edge of the frame, it needs to bounce. The bounce part I can work out myself after, what I need help…
-1
votes
1 answer

Drawing bar chart that looks like MS Excel equivalent

Is it possible to create bar graphs in Java which has the same look and feel like the way we create bar graphs in MS Excel? It is not possible to add the difference between the two graphs i.e. one created using JFreeChart (using Java) and the…
user3194262
  • 51
  • 1
  • 1
  • 7
-1
votes
1 answer

Conversion of co-ordinates from points to mm

I have a code using AWT graphics and applets. public class Draw extends Applet{ public void paint(Graphics g){ g.drawLine(10,10,20,10); } } The code above draws a line of 10 units. I am not really sure which unit is…
Maxim Dsouza
  • 1,507
  • 3
  • 19
  • 32
-1
votes
3 answers

Draw grid issue

I want to create a simple grid in Java as a map editor working with tiles. In my render method I've put this public void render(Graphics g){ renderGrid(g,96,64); } private void renderGrid(Graphics g,int width, int height) { …
Lucarnosky
  • 514
  • 4
  • 18
-1
votes
2 answers

Get portion of an image using rotated Shape

From the above image if I want a portion behind the RED Rectangle I can easily get it, but the issue I cannot get the portion behind the Yellow Rectangle because it is rotated. So how can I get a portion of an image from a rotated shape on it? For…
Mihir
  • 2,480
  • 7
  • 38
  • 57
-1
votes
1 answer

Using JComponent to draw unique rectangle

How do I draw the unique rectangle(cube) inside the oval: https://i.stack.imgur.com/pmHTl.jpg For me it is tricky to use graphics to draw a rectangle such as the one shown. Any advice on what to do. Ok. I will try to make myself as clear as I can.…
omar ahmed
  • 1
  • 1
  • 4