Questions tagged [java-2d]

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

java-2d
Filter by
Sorted by
Tagged with
0 votes
1 answer
329 views

Draw on one side of a JPanel

I want to program an application that lets you draw circles with a mouse click on the left side of a JFrame, and all the points are getting "mirrored" to the right side. The first problem I ...
MassU's user avatar
  • 51
0 votes
1 answer
391 views

Java2D - Access font CMap to render ligatures

I need to print Emojis with ligatures (🇺 + 🇸 = 🇺🇸 ) into a Graphics2D object. From what I see you can either use graphics2d.drawString(string, x, y); or create a GlyphVector from the font and then ...
Simone Rondelli's user avatar
-6 votes
1 answer
670 views

Java Package not in Folders

I have a java program where I get the Graphics2D from a BufferedImage via createGraphics() and printed it out and got: sun.java2d.SunGraphics2D[font=java.awt........... you get the idea but when I go ...
Sean Letendre's user avatar
1 vote
2 answers
108 views

How can I rearrange my code for the rain and poster to appear

So here I have a set of code to display generated polygons with a background: public class Drawing extends JFrame{ public static void main(String []args) { Drawing b = new Drawing(); } ...
Miyazaki Ahmad's user avatar
2 votes
1 answer
1k views

Graphics (2D) Rotation: Rotate x Axis

I have a JPanel in which I draw triangles via the method drawPolygon. My Goal is to rotate the graphics around the X axis. I know that there is a method called rotate, but this method rotates only ...
NoSenseSenpai's user avatar
1 vote
1 answer
118 views

Draw an oval exactly within the perimeter of an AWT Panel

I want to draw an oval exactly within the panel, similar to @Override public void paint(Graphics g) { super.paint(g); g.drawOval(x,y,this.getHeight(), this.getHeight() ); ...
Dylan Czenski's user avatar
0 votes
0 answers
163 views

Drawing lost when resizing java applet window

import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="kp.class" width = 400 height = 400></applet> */ public class kp extends Applet implements ...
Karan Nagpal's user avatar
0 votes
1 answer
141 views

How to add transparent text to photo?

I have got a stupid problem.I want add a text with alpha 0.5 to my photo to make a watermark but setColor doesn't add a color. When I trying use setComposite I see the error "cannot find symbol". ...
Piotr's user avatar
  • 175
0 votes
0 answers
161 views

Java paint program double buffering

So I'm working on a paint program in school and now I have to double buffer it. After a week of searching and using tutorials online I am still unable to double buffer my program properly... I have ...
Nathan L's user avatar
-4 votes
2 answers
667 views

java - Different stroke for different shapes? Graphics2d

I am making a paint application for a project and running into an issue. My model stores two ArrayLists of circle and square objects. (Every time one is drawn, it is stored) I also have a JSlider ...
PplTookMyName's user avatar
2 votes
1 answer
652 views

Force space between Panels to be 0 using BoxLayout?

Currently as part of a project I'm working on, I am implementing a component which can be used to visualize a permutation of bits (as part of a cryptographic algorithm). I am doing so by creating two ...
Mike Carpenter's user avatar
1 vote
1 answer
526 views

Java Buffer Strategy causes severe lag

I have a small engine that runs well on my OSX laptop, but runs crashes or lags severely when ran on a less powerful Linux PC. I minimized the code the point where it's just one small class, but the ...
Bun's user avatar
  • 128
0 votes
1 answer
156 views

Drawing a simple circle with Java swing does not work

I think I am missing something really obvious but somehow this code does give me an empty window but it does not paint the red oval. What am I missing? public class Test extends JPanel { @...
Sebastian's user avatar
  • 527
2 votes
1 answer
1k views

Java AWT fillOval() not working

I'm working on a program that draws a graph, so I would like to draw points! I'd like the points to be circular since that's usually how points are represented, and to the best of my knowledge, g2....
Shannon's user avatar
  • 100
-1 votes
2 answers
90 views

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 ...
leKt0's user avatar
  • 3
1 vote
1 answer
1k views

How can I draw a text into a buffered image with different font affects in Java 2d?

I am trying to convert Multi-line Text to image but couldn't found a way to draw it with different Font format's is there any way to do it.Thanks in Advance.
Syed M Abbas Hashim's user avatar
1 vote
1 answer
197 views

How to make overlapping shapes produce a new color?

I'm making a game in which there will be red and blue Shapes moving around on screen. I've looked high and low for how to make anywhere they overlap a different color (purple). I am only using Java2D, ...
Ryguy9999's user avatar
0 votes
0 answers
44 views

Graphics2D Paint, not working when graphics scaled

Using this class for a gradient on a rectangle https://github.com/griffon/griffon-harmoniccode-plugin/blob/master/src/main/eu/hansolo/gradients/ContourGradientPaint.java As soon as i enable scaling ...
clienthax's user avatar
  • 1,212
-1 votes
1 answer
93 views

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 ...
Kivan's user avatar
  • 1,732
1 vote
1 answer
287 views

Drawing an image at floating points - Java

Graphics2D's drawImage() method requires strictly integers. How could one draw an image using floating points in Java2D, if at all? If not what would SO recommend?
2ARSJcdocuyVu7LfjUnB's user avatar
7 votes
2 answers
1k views

Java game 2D overlapping shadows with Swing

I am currently developing a 2D Java game using Swing as my primary drawing component. Every object has a shadow (BufferedImage) but every shadow overlaps other shadows. Is it possible to only have the ...
Patrick Swijgman's user avatar
-1 votes
2 answers
81 views

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 ...
user avatar
2 votes
1 answer
377 views

How to fade out the edges of a Java2D Area object?

I have a method that creates shadows based on where things are on the screen and the final product of that method is an Area, which I then draw onto the screen and it contains all shadows on screen in ...
Miles's user avatar
  • 554
0 votes
1 answer
85 views

Java Applet that Moves Six Squares

I am new to Java and working on an applet that drags six squares. So far, I have code that allows me to move each square, independently (from right-to-left). However, I am unable to click on the ...
user5834454's user avatar
-2 votes
2 answers
2k views

How to make code move the ball?

I try to make a ping pong game but my ball don't move so how to make the ball is move? This is my code package test; import java.awt.*; import java.awt.event.*; import java.util.logging.Level; ...
백형신's user avatar
1 vote
1 answer
347 views

Custom methods for graphics in java.awt.graphics

So right now, I'm new to using java awt graphics. I've gotten the basics down, like how to actually put things on the screen, but my main issue is that I'm trying to create custom methods for use ...
Omar Ahmed's user avatar
3 votes
0 answers
250 views

Java Area.subtract method taking really long time on shapes with same geometry

Just a general inquiry. I'm testing out a symmetry detection system that I wrote and I appear to come across on issue with the java.awt.geom.Area class. Specifically, I'm testing the vertical symmetry ...
CB_Maverick's user avatar
1 vote
1 answer
66 views

How to copy a region of an image enclosed by cubic curves

I have a Java program that works very similar to the Bezier tool in Inkscape. The purpose of my program is to allow the user to use the curves to draw a path around an object (like the head of a ...
minh hoang's user avatar
1 vote
1 answer
29 views

Simple GUI that moves 3 PNG's across the screen - not working correctly

I'm creating a simple GUI that moves 3 PNG's across the screen but it's not working correctly. Here is the code I have I'm new to GUI and swing so there may be some very simple commonplace errors and ...
Sean T.'s user avatar
  • 11
1 vote
1 answer
62 views

Java paint doesn't work

am try to call paint in my listener but draw rectangle shouldn't be call maybe my code is wrong help me please am newbie in java btnNewButton_5.addActionListener(new ActionListener() { ...
Par Whale's user avatar
2 votes
1 answer
116 views

Java2D based Game engine lags when there's no input

I am messing around with my custom built game engine, which uses Java2D APIs to draw on a Canvas (Active rendering). The thing that I noticed is that a simple scene with a square moving around gets ...
Warrior's user avatar
  • 573
0 votes
1 answer
965 views

How rotate rectangle around corner on applet?

I want to rotate the rectangle around one of corner, but I don't now how determine the new coordinates of corners. Rotation may be around any corner. May be exists another method of rotation? Can ...
Sergo's user avatar
  • 15
0 votes
1 answer
169 views

JPanel doesn't paint when frame.setUndecorated(true)

EDIT: After moving expressions around in the constructor, i currently managed to get it to draw it sometimes completely and sometimes partly. I'm creating this game in Java2D and basically if I set ...
MichaelvdNet's user avatar
  • 1,074
1 vote
1 answer
55 views

graphics object are not visible when i called repaint method

Here I have a problem I would like you to help me solve. Thank you to all who wish to do so. I have objects that inherit from the JComponent class to which I added a MouseListener. I have a grid ...
 hanyatou's user avatar
1 vote
1 answer
340 views

Pixelating a section of a bufferedImage

I need to pixelate a section of a bufferedImage. I have tried modified the code from How can I pixelate a jpg with java? however this is designed for an entire image and does not seem to work with ...
Mannie's user avatar
  • 1,655
0 votes
0 answers
46 views

Is there any way to use doubles for x and y values in a JPanel?

I'm making a mini game where the player is a ball in the middle of the screen and shoots bullets guided by the mouse. I thought in order to guide the projectiles I could work out the gradient between ...
user avatar
-1 votes
3 answers
155 views

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 ...
Alex Webster's user avatar
0 votes
0 answers
29 views

Merging 2 images in Java increase size [duplicate]

I have 2 images to be merged that are 810KB & 850KB in size (Jpegs). When I use the following method, the resulting 'merged' PNG images size is 16.4MB (on disk). Why is this the case and how can I ...
Mannie's user avatar
  • 1,655
0 votes
1 answer
4k views

Java Applet Drawing Shapes by User Input

here is what I wanted to do. There is a textfield and user enters what he wants. For example "Rectangle" or "rectangle", "circle" or "CIRCLE" like that. And then the user presses the button. After ...
Ufuk Ozdogan's user avatar
3 votes
0 answers
65 views

Intersection quick failure for Java2D

I'm trying to come up with a fast iterative/recursive process for telling when a java2D path does NOT intersect any other java2D objects. In other words, I would like to come up with a "quick failure" ...
CB_Maverick's user avatar
1 vote
1 answer
108 views

Drawing in Java 2D with fast mousemovement

it's going to be long, so thanks in advance for reading and/or answering :) Edit: This How to draw a continuous curve of repeated ovals on speedy mouse cursor dragging? has an answer I am not ...
AverageGatsby's user avatar
-7 votes
3 answers
706 views

Class doesn't have a main method (Traffic Light)

I found a java code from this link. and when I tried to run it the error class doesnt have a main method.I know this is a similiar post but I tried searching/trying for different solution but when I ...
Vista's user avatar
  • 201
0 votes
0 answers
55 views

android merge several images

I'm trying to merge up to around 200 images. I'm using the following code but on attempting to merge the 3rd image, the first 2 go away and all that I'm shown is only the 3rd image. In reality, when I'...
user3123813's user avatar
1 vote
2 answers
319 views

Pie Chart not showing expected output

I'm trying to keep my piechart up to date to the data that changes during the simulator run. My issue is that the piechart is not showing the data the correct way and I've no clue what the issue is. ...
lloydd4's user avatar
  • 57
0 votes
3 answers
89 views

understanding difficulties java swing

im trying to paint random (not yet) circles on a JPanel through click on a JMenu. Im using a JTextField (and have to keep this) for some output. Here is my Class: class RandomDrawer extends JPanel ...
Kaw's user avatar
  • 17
1 vote
1 answer
1k views

Drawing rectangles and oval

First sorry if my question was asked before (i had search but couldn't find answer) here is the question: I wanna draw rectangle and oval when user type 1 or 2. I am programming with JAVA and here is ...
Od Chan's user avatar
  • 78
0 votes
0 answers
425 views

Collision between a ball and a rectangle

I was required to change the direction of a ball according to the collision between the ball and a rectangle. That's my code: public Velocity hit(Point collisionPoint, Velocity currentVelocity) { ...
rotemhas's user avatar
2 votes
2 answers
1k views

FontMetrics returns wrong height

I want to get the exact height of my string in pixels on my panel. So I wrote a program that draws the string, and then draws a rectangle around it. Using FontMetrics I used the getStringBounds ...
Oliver Watkins's user avatar
0 votes
1 answer
2k views

Draw A Tree Data Structure in Java [duplicate]

Given a tree how one could approach to draw the same using Java Swing that what we draw in a simple piece of paper to understand a tree ? i.e. drawing all the nodes an values inside the node circle as ...
Soumya Kanti Naskar's user avatar
2 votes
1 answer
73 views

Making the ball returns back in applet

This code makes the ball go forward only , how i can make the ball returns back? what is the expression that i can add it to the loop in order to make the ball returns back to the left. Applet ...
moonlight's user avatar

1 2 3
4
5
22