java-2d

java drawing a circle when mouse clicked

荒凉一梦 提交于 2019-12-19 19:48:46
问题 i am writing a program that when the mouse is clicked, a circle will be drawn. The below code i've wrote so far. import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.event.*; import java.awt.geom.*; public class test extends JFrame implements ActionListener, MouseListener { Shape circle = new Ellipse2D.Float(10, 10, 10, 10); public test () {

How to change diagram Scale in Java

大兔子大兔子 提交于 2019-12-19 11:28:11
问题 I have a diagram in which x axis shows the time and the y axis shows my data. I want to change the Scale by choosing different metrics for x axis. e.g second, minute and hour scale. the default is second. therefore if I choose the minute the diagram should be smaller and be more curved. Any idea? The UI is not completed however you suppose that the there would be x and y axis. The parameter degree determines that It should be scaled to second(degree=1), minute (degree=60) or hour(degree=3600)

How to go about creating a race track game? [closed]

独自空忆成欢 提交于 2019-12-18 17:03:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . i am planning to make racing game in android.I have created many applications in different mobile technology. but i am pretty much beginner for game application. So my question is how can i make race track in android? How should i show that car is moving on that race track. I have

Implementing Polygon2D in Java 2D

大兔子大兔子 提交于 2019-12-18 11:56:03
问题 I'm creating a 2D game in Java using the Java2D library for drawing, and I really need a float-precision Polygon object that I can use both to draw game objects and to do collision detection on them. Unfortunately, Java's Polygon object comes in int precision only, and there is no equivalent Polygon2D like there is with Rectangle and Rectangle2D. I've already done enough research to see that I have a few options, but none of them seem very good. Use Path2D . According to a Java developer

How to draw custom rounded rectangles in java?

北城以北 提交于 2019-12-18 07:17:15
问题 I know how to draw a rounded rectangle but I want to define roundness for each corner separately and draw something like the image below : 回答1: There's probably a few ways to achieve this, but the easiest I can think of would be to, as Andrew has already hinted, would be to define your own Shape import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Path2D; import javax.swing.JFrame;

How to create a big image file from many tiles in java?

邮差的信 提交于 2019-12-18 05:55:37
问题 My program produces 10 x 10 tiles images of 3000x3000 pixel, one by one (currently saved to 100 files named image_x_y.jpg ) I want to assemble these 100 images into one big image, without loading everything in memory. My goal is to create one big image file, of 30'000 * 30'000 pixels. I'm looking for a way to do this without using JAI (which cannot be installed from public maven repositories, I don't understand why) Is there a way to do this with pure java2D ? Or does another library exist,

How to show pictures in jFrame, using java2d?

北城以北 提交于 2019-12-17 22:59:42
问题 I'm new on working with Java and Netbeans. In many others languages, it's a simple stuff to do. But after broke my brain thinking, I couldn't. My doubt is simple to explain. How can I show bitmaps (stored on Hard Drive) in runtime, in a commom JFrame, using java2D? What I need to edit, and or create? Is it simple to do? Thanks in advance... 回答1: The basic process is use Graphics#drawImage to render an image you have previously loaded. There are a number of things you need in order to achieve

Occasional InterruptedException when quitting a Swing application

落花浮王杯 提交于 2019-12-17 17:55:11
问题 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

Draggable rectangles in Java 2D [duplicate]

混江龙づ霸主 提交于 2019-12-17 10:06:43
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: how to drag object I need to draw some UML components (classes, packages etc) using Java 2D and then be able to drag them around. Is there a way to do this? I mean, to make a shape "draggable"? 回答1: JHotDraw was designed as "a Java GUI framework for technical and structured Graphics." The linked JHotDraw Pattern Language: JHotDraw Domain Overview illustrates how to customize drawing editors. The sample org

Pacman open/close mouth animation

放肆的年华 提交于 2019-12-17 07:41:20
问题 I want to make the pacman open/close mouth animation using the easiest method. Here is my recent code: The problem is, nothing is happening? package ordner; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PacMan implements ActionListener { private JFrame frame; private DrawPanel panel; private void initGui() { frame = new JFrame("Pacman"); frame.setDefaultCloseOperation(JFrame