java-2d


atan2 - find angle between two points (360deg)

◇◆丶佛笑我妖孽 提交于 2020-01-16 02:05:24
问题 I have a game where there is a Player and some enemies . These enemies, just as the player itself, can shoot bullets . But the angle of bullets don't change as it is supposed to; The newly created bullet is supposed to find the angle between itself and the player, then just go in that direction - this has to be done in 360° . I have followed this answer but I believe that I have done something incorrect. because this is what happens: and this is how it should be: currently it only goes like

Why does it draw lines in the wrong place?

与世无争的帅哥 提交于 2020-01-15 06:29:53
问题 I have a problem with this... When I draw a line the character follows the line I drew but the computer paints a line somewhere else: So does anyone know what is going on? My code: @SuppressWarnings({"serial","rawtypes","unchecked"}) public class someGame extends JFrame implements MouseListener, KeyListener{ ArrayList lines = new ArrayList(); Point2D.Double start; final Color BROWN = new Color(156,93,82); Slider thread; Rectangle cow = null; boolean drawGuy = false; public someGame(){ super(

Draw ring with given thickness, position, and radius. (Java2D)

吃可爱长大的小学妹 提交于 2020-01-14 04:35:14
问题 I need to draw a ring, with given thickness, that looks something like this: The center must be transparent, so that it doesn't cover previously drawn shapes. (or other rings) I've tried something like this: //g is a Graphics2D object g.setColor(Color.RED); g.drawOval(x,y,width,height); g.setColor(Color.WHITE); g.drawOval(x+thickness,y+thickness,width-2*thickness,height-2*thickness); which draws a satisfactory ring, but it covers other shapes; the interior is white, not transparent. How can I

How to initialize Graphics? because it says it was not initialized [closed]

血红的双手。 提交于 2020-01-11 14:35:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have this part of my code but it will not initialize and I do not know how to do it. It keeps giving me an error such as Exception in thread "main" java.lang.NullPointerException at memor.main(memor.java:131) import java.awt.*; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.GridLayout;

how to draw multiple rectangles

只谈情不闲聊 提交于 2020-01-11 13:41:27
问题 so I am trying to make a simple program where you click on the screen and it creates a block that falls and collides with a larger block beneath and sticks to it. Kind of like a simple collision program. The problem is when I create one block it deletes the block previously. I made an array, but it still does this. Do any of you know what Im doing wrong? Im sure its a simple fix. public class Screen extends JPanel implements Runnable { public static JLabel statusbar; //displays a status bar

How to serialize Java 2D Shape objects as XML?

≡放荡痞女 提交于 2020-01-09 03:41:08
问题 The Shape interface is implemented by objects of Java 2D ( Arc2D , Area , CubicCurve2D , Ellipse2D , GeneralPath etc..). Some of the concrete objects are marked as Serializable and can be stored and restored using object serialization, but others like Area do not implement the interface and throw errors. But since we are constantly warned that such naive serialization is not necessarily stable across Java implementations or versions, I'd prefer to use some form of serialization that is. That

How to serialize Java 2D Shape objects as XML?

自古美人都是妖i 提交于 2020-01-09 03:40:12
问题 The Shape interface is implemented by objects of Java 2D ( Arc2D , Area , CubicCurve2D , Ellipse2D , GeneralPath etc..). Some of the concrete objects are marked as Serializable and can be stored and restored using object serialization, but others like Area do not implement the interface and throw errors. But since we are constantly warned that such naive serialization is not necessarily stable across Java implementations or versions, I'd prefer to use some form of serialization that is. That

What is the best way to call repaint() at regular intervals in my Java2D program?

柔情痞子 提交于 2020-01-06 07:17:17
问题 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? 回答1: Use timer function in java (javax.swing.Timer) and this may useful for you efiicient way to repaint 回答2: Use a Timer. If its a Swing application use a Swing Timer. If its AWT then use TimerTask. 来源: https://stackoverflow.com/questions/1586984/what-is-the-best-way

java2d and scale

喜欢而已 提交于 2020-01-06 06:01:48
问题 when I scale my shape [Rectangle] with g2d.scale(2,2) or with AffineTransform , I can't detect correct hit on shape because my shape scale still same as previous and only view of shape is change. I need solution for solving this problem [change size of shape after Transform]. thanks 回答1: You can either use an inverse transform, as shown here, or do the scaling explicitly, as shown here. 来源: https://stackoverflow.com/questions/3664908/java2d-and-scale

Drawing multiple circles with Java2D

大憨熊 提交于 2020-01-04 06:07:49
问题 I am trying to use Java2D to do some simple graphics programming. I've started easy, just trying to display a couple of circles in a JFrame. I was successful displaying a single circle, but when adding a second circle, only the last circle added to the JFrame is displayed. I use class Circle to define my circle and to override the paintComponent method used to display it. Any suggestions on what I might be doing wrong would be greatly appreciated. Code for my classes Circle and DancingCircles

工具导航Map