java-2d

How to move two circles together in a JFrame from two different classes

为君一笑 提交于 2019-11-28 11:05:08
问题 I am trying to display the two circles moving together on a single frame through two different classes. But only one is shown moving at a time,even though value of "x" is changing continuously in class child1, paintComponent() is only taking the value of "x1" and showing the circle in moving from class child2. If two separate frames are assigned to both the classes they works perfectly fine. Here is my code import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event

Rounding Inaccuracies When Combining Areas in Java?

假如想象 提交于 2019-11-28 08:52:51
问题 I'm working with Areas in Java. My test program draws three random triangles and combines them to form one or more polygons. After the Areas are .add() ed together, I use PathIterator to trace the edges. Sometimes, however, the Area objects will not combine as they should... and as you can see in the last image I posted, extra edges will be drawn. I think the problem is caused by rounding inaccuracies in Java's Area class (when I debug the test program, the Area shows the gaps before the

Occasional InterruptedException when quitting a Swing application

坚强是说给别人听的谎言 提交于 2019-11-28 05:50:06
I recently updated my computer to a more powerful one, with a quad-core hyperthreading processor (i7), thus plenty of real concurrency available. Now I'm occasionally getting the following error when quitting ( System.exit(0) ) an application (with a Swing GUI) that I'm developing: Exception while removing reference: java.lang.InterruptedException java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) at sun.java2d.Disposer.run(Disposer.java:125) at

Split image into clickable regions

江枫思渺然 提交于 2019-11-28 01:23:19
问题 Is there any way to split an image to region (right now it's JLabel but I can change it if necessary)? I use swing in my program and I have an image (square for this example) with some triangles, stars and trapezoids inside it (it can be JPG, PNG, etc). The idea is that the user will click inside one of those shapes and then I will put another small icon on top of the area the user clicked. The user can click on multiple areas but at the end of the day, I need to know which shapes were

How to draw a transparent shape using a Graphics object g?

孤街醉人 提交于 2019-11-28 00:32:33
I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this: BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(c); g.fillOval(0, 0, d, d); But now I want to draw a smaller transparent circle in the middle of it to make a ring (so when I draw this image over another image, the pixels around and inside the ring are not drawn). I want to use a Graphics

How to get a good quality thumbnail

六眼飞鱼酱① 提交于 2019-11-27 21:15:14
问题 I am trying to create a high quality thumbnail of this image, with Java and Scalr 3.2 This is the relevant source code, where THUMB_WIDTH = 77 and THUMB_HEIGHT = 57 BufferedImage srcImg = ImageIO.read(new File(sourceFile)); BufferedImage dstImg = Scalr.resize(srcImg, Scalr.Method.QUALITY, THUMB_WIDTH, THUMB_HEIGHT); ImageIO.write(dstImg, format, new File(destFile)); If I use format = "png" , here is the result: If I use format = "jpg" , here is the result: With imagemagick identify I've found

Is there a 100% Java alternative to ImageIO for reading JPEG files?

心已入冬 提交于 2019-11-27 18:35:07
We are using Java2D to resize photos uploaded to our website, but we run into an issue (a seemingly old one, cf.: http://forums.sun.com/thread.jspa?threadID=5425569 ) - a few particular JPEGs raise a CMMException when we try to ImageIO.read() an InputStream containing their binary data: java.awt.color.CMMException: Invalid image format at sun.awt.color.CMM.checkStatus(CMM.java:131) at sun.awt.color.ICC_Transform.<init>(ICC_Transform.java:89) at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:516) at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1114)

Java 2D Drawing Optimal Performance

烂漫一生 提交于 2019-11-27 17:20:58
I'm in the process of writing a Java 2D game. I'm using the built-in Java 2D drawing libraries, drawing on a Graphics2D I acquire from a BufferStrategy from a Canvas in a JFrame (which is sometimes full-screened). The BufferStrategy is double-buffered. Repainting is done actively, via a timer. I'm having some performance issues though, especially on Linux. And Java2D has so very many ways of creating graphics buffers and drawing graphics that I just don't know if I'm doing the right thing. I've been experimenting with graphics2d.getDeviceConfiguration().createCompatibleVolatileImage, which

Line2D decoration tips needed - Graphics2D

偶尔善良 提交于 2019-11-27 16:17:51
I have Line2D and Arc2D objects laid out on my JPanel by Graphics2D drawing. You can have a look a part of it on this question " How to make pixel perfect Line2D in - Graphics2D ". Now what I want to achieve is, I want to create two parallel lines and arcs for all Line2D and Arc2D objects. Visually, Normal Line2D and Arc2D drawn currently, Want to decorate it like this, My Thoughts so far, I might be able to achieve this by creating two different line and give an offset +gap and -gap from my normal line position. However This will make lots of objects which I don't want to. Now, is it possible

Java2D: Is it always safe to cast Graphics into Graphics2D

馋奶兔 提交于 2019-11-27 14:34:30
Assuming we always use a Sun JVM (say, 1.5+), is it always safe to cast a Graphics reference to Graphics2D? I haven't seen it cause any problems yet and, to my understanding, the Graphics class is legacy code but the Java designers didn't want to change the interfaces for Swing and AWT classes in order to preserver backwards compatibility. Jorge Ferreira According to the discussion here , it is always safe to cast from Graphics to Graphics2D . However I am not able to quickly find the official Sun statement on this. The reason it is valid to cast from Graphics to Graphics2D, is because Sun