Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
0
votes
4 answers
Animated drawing of a successively complex image in Java
I am trying to draw an image on a JPanel that requires thousands of calculations, and I want to animate the progression of the drawing. I.e., instead of doing all 100K iterations of drawing in one go, and then repainting the JPanel, I want to…

Andrei Utkin
- 71
- 1
- 1
- 3
0
votes
4 answers
Multiple calls of paintComponent()
I have these two classes:
public class Pencil extends JComponent implements MouseListener, MouseMotionListener{
Plansa plansa;
Graphics g;
public Pencil(Plansa newCanvas){
this.plansa = newCanvas;
…

Diana
- 11
- 2
- 5
0
votes
2 answers
What is the best way to call repaint() at regular intervals in my Java2D program?
I'm looking to call repaint() in my Java2D simulator at regular intervals.
What would be the best way to do this? Should I start another thread and have a loop that keeps track of currentTimeMillis()? Or is there a better way?

Scorcher84
- 423
- 1
- 6
- 9
0
votes
1 answer
Mandelbrot set in java doesn't calculate correctly
I'm still relatively new to Java. I've been working on a program to display the mandelbrot set. My current code generates an image that is close, but not quite the mandelbrot set. This is my generation code:
private void generateMap () {
//…

leopardGeckos
- 91
- 2
- 8
0
votes
1 answer
Resizing Jpanel when resizing JFrame
I need to draw a x-y axis coordinate system on a JPanel. I want to implement a function that when resize JFrame, the x,y axis coordinate can resize automatically.
public void paintComponent(Graphics gl) {
Graphics2D g = (Graphics2D) gl;
…

user1831190
- 87
- 5
0
votes
2 answers
drawing shapes on a grid
I need to draw random shapes on a grid such as lines squares etc. This part I'm able to do. My problem is the start and end point of the lines I'm drawing falls anywhere in a grid cell. I would like them to be only at intersection points. One cell…

user2224555
- 15
- 1
- 5
0
votes
0 answers
Deviation location on drawline according to mouseClicked Point
Having a JPanel on a JFrame , the JPanel is as the follow -
public class MyPanel extends JPanel implements MouseListener,
MouseMotionListener {
...
@Override
public void mouseClicked(MouseEvent arg) {
...
…

URL87
- 10,667
- 35
- 107
- 174
0
votes
0 answers
Java Applet becomes a blank white screen when it's done
All my applet does is draw something, step by step.
My update() block goes something like:
public void update(Graphics g)
{
if (!done)
{
while (!doneDrawing)
{
imageGraphics.drawSomething(...);
g.drawImage(image);
}
…

user1778856
- 641
- 4
- 10
- 17
0
votes
2 answers
Paint component doesn't print polygon according to intended coordinate
I have problem drawing the triangle polygons based on the coordinates which are stored in linked list. When I checked the linked list elements using System.out.println in paint component method
Public void paintComponent (Graphics g) {
...
for…

Jessy
- 15,321
- 31
- 83
- 100
0
votes
1 answer
multiple grapics2d objects
I need to apply different Affine Transform to different graphic objects(eg lines), is it suitable to use multiple Graphics2D objects to perform this task?
Code:
Graphics2D g2seconds = (Graphics2D) g; // g - Graphics class
Graphics2D g2minutes…

hunterra
- 95
- 1
- 6
0
votes
1 answer
JAVA2d Setting element on right place
I'm writing a simple game in JAVA2D. I created a class "Ground". When I create an object of this class like that...
Ground g1 = new Ground("WATER", 50, 100, 5, 5) //params: type of surface, margin-left, margin-top, width, height
...I create a…

Sheppard25
- 493
- 1
- 7
- 22
0
votes
3 answers
Reducing the number of collide methods in a Java Game
I'm making a simple game in java, and I have many methods which test if two object collide. Objects include a man, enemy, arrow, wall, coin and so on. I have a bunch of methods which count for every type of collision which could occur, they look…

Joe
- 173
- 3
- 10
0
votes
1 answer
Graphics2D animation, cant understand why paintComponent only draws the shape one time and then stops
Graphics2D animation, cant understand why paintComponent only draws the shape one time and then stops. I Also can't understand why my timer counter variable isn't incrementing. I've been banging my head against this for over an hour, can anyone…

Rafael Rondon
- 27
- 1
- 4
0
votes
1 answer
How to graph a simple curve sketch using g.drawline and a loop?
I would like to know how to make a simple graph using the method g.drawLine and using loops to update the coordinates, I am really really new at this and have no idea what I need to do or where to start, I do have this simple program that uses *'s…

user2145216
- 1
- 2
0
votes
1 answer
How to find custom shape speicific area?
please , see following image, here you can see blue rectangle is custom shape bounds and custom shape is shoe , i want to find area of a portion written in image and i want that area in form of rectangle
do is there any path iterator concept…

Mihir
- 2,480
- 7
- 38
- 57