Questions tagged [java-2d]

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

1076 questions
4
votes
2 answers

Java swing small 2D game: how to modelize the view?

In a small java swing 2D game, what is the best solution for creating the board view? Use a component for the board and custom paint it and each square of the checker at once? Use a component for the board and create another component modelizing…
Guillaume
  • 5,488
  • 11
  • 47
  • 83
4
votes
1 answer

Drawing strings inscribed in a circle

I am aware of Java's drawString(String str, int x, int y) method; however, sometimes all I want is to label a circle with an appropriate string in the middle of it, given a font size (either in pts or in accordance to the circle's size). Is there an…
4
votes
2 answers

Java 2D Shading / Filling

I have created a "blob" from Bezier curves (screenshot below) and would now like to shade it in such a way that it appears pseudo-3D, with darker shading on all "left" edges and lighter on all "right" edges, and perhaps pure white "light spots" on…
Adamski
  • 54,009
  • 15
  • 113
  • 152
4
votes
3 answers

What is the use of Canvas in AWT?

I've been searching many sources yet I still cannot find a decent explanation. Why should I use it, what is its' purpose and why does it differ from JPanels and such?
beur_x
  • 169
  • 3
  • 11
4
votes
2 answers

Java fillRect on coords and mouseMove point coords are off on the Y axis

I came across this problem in a game I'm writing but have reproduced the issue on a separate jar that consists only of a frame, a panel, and a mouse motion listener. The issue is that I draw a rectangle - for example at x:512, y:384 (48x48). Using…
helion3
  • 34,737
  • 15
  • 57
  • 100
4
votes
4 answers

Stretching Polygon to other Polygon with Java

My problem is that I have a rectangle presented with a small perspective, and I would like to stretch it back to be presented as a rectangle again. To represent it visually, I currently have within my image something like the red shape, and I have 4…
Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106
4
votes
1 answer

Trouble Drawing Arcs Between Adjacent Edges of Triangle

I have been trying to write the code for generating random triangles and drawing arcs between the adjacent edges of the trianglefor describing the angle between them. It almost works. But it seems my math failed somewhere and arcs are not drawn…
pinkpanther
  • 4,770
  • 2
  • 38
  • 62
4
votes
1 answer

How to compute a path bounding box taking into account the Stroke

I am currently drawing a line using the code below and would like to get the bounding box around my path but if I call path.getBounds() I get a bounding box that ignore the stroke width and line join thus my drawing end-up having some part clipped…
skyde
  • 2,816
  • 4
  • 34
  • 53
4
votes
1 answer

Swing paint issue

I have a custom scrollbarUI which I paint both thumb and track of scrollbar. But when scrolling it keeps some lines like below which I don't want. : Painting code is below: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)…
Priyan Perera
  • 469
  • 1
  • 8
  • 13
4
votes
1 answer

Java graphics2D fillRect does not work properly with semi-transparent colors

I was writing a program with some custom rendering, and needed to render a rectangle with a border. I decided to simply call graphics2D.fillRect(), switch to the border color, and call graphics2D.drawRect(). However, even though I make these calls…
Eric Fitting
  • 160
  • 1
  • 7
4
votes
2 answers

Trying to draw lines with JPanel

I am trying to draw lines using JPanel and I have hit somewhat of a wall. I can get two sides down but once it comes to subtracting from the x cord it all goes wrong. package GUIstuff; import java.awt.Graphics; import javax.swing.JPanel; public…
Blank1268
  • 123
  • 3
  • 7
  • 14
4
votes
2 answers

about preparing the map of Risk game with swing in java

i want to start coding a game project which is called "Risk" and my first aim is build the map correctly. So logically, each territory should be a JButton but JButton's are rectangular oriented. Moreover, i know that every territory should be a…
quartaela
  • 2,579
  • 16
  • 63
  • 99
4
votes
4 answers

The best way of using graphics for games

I am new to java and programming in general,and i am trying to write a little shooting game with a spaceship and aliens, but having a lot of trouble with the graphics. It seems that I am mixing a lot of different kind of components. How should I…
user2030118
  • 155
  • 3
  • 14
4
votes
2 answers

Java GUI Rotation and Translation of Rectangle

I am trying to draw a rectangle in JPanel that would translate and then rotate itself to mimic the movement of a car. I have been able to make the rectangle translate and rotate, however it rotates around the origin of (0,0). I'm very pleased that I…
John Cava
  • 43
  • 1
  • 5
4
votes
2 answers

Issue in drawing lines while mouse dragging

I'm working on a paint applet that draws different shapes. I want to draw lines while dragging the mouse. The problem is that when the lines appear, they are as shown in the image below. I have class line that's constructed using one point (start…
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165