java-2d

How do I move a graphic across the screen with arrow keys?

瘦欲@ 提交于 2019-12-01 10:37:11
I'm trying to create the beginning of a simple game. The first thing I am trying to do is import a graphic into my code and move it across the screen. I was able to draw a ball on the screen and move it around but when I import a graphic from a file I am unable to move it around. What am I missing or doing wrong? import javax.swing.*; import java.awt.Graphics; import java.awt.*; import java.awt.event.*; import javax.swing.ImageIcon; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyListener; import javax.swing.JPanel;

How do I move a graphic across the screen with arrow keys?

老子叫甜甜 提交于 2019-12-01 08:17:45
问题 I'm trying to create the beginning of a simple game. The first thing I am trying to do is import a graphic into my code and move it across the screen. I was able to draw a ball on the screen and move it around but when I import a graphic from a file I am unable to move it around. What am I missing or doing wrong? import javax.swing.*; import java.awt.Graphics; import java.awt.*; import java.awt.event.*; import javax.swing.ImageIcon; import java.awt.Color; import java.awt.event.ActionEvent;

How do I specify fallback fonts in Java2D/Graphics2D

£可爱£侵袭症+ 提交于 2019-11-30 19:34:09
I'm using g.drawString(str, x, y) to draw a String with a Graphics2D object g . The current font of g does not cover all the characters of str (I have e.g. Chinese chars in there). On Mac OS X, a fallback font seems to be automatically used, but not on Windows, where black square outlines appear instead of the wanted characters. Why is the behavior different depending on the platform? How do I specify a fallback font (or several fallback fonts) in case of missing characters? (For instance, one of the nice fonts there .) Update/More Info So, the original font that doesn't support all characters

Inside clipping with Java Graphics

我们两清 提交于 2019-11-30 18:47:12
I need to draw a line using java.awt.Graphics, but only the portion of the line that lies outside of a rectangle should be rendered. Is it possible to use the Graphics clipping support or do I need to calculate the intersection and clip the line myself? You need to use the Area class. This example will demonstrate how to do what you ask: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Area; import java.awt.geom.Rectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; public

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

隐身守侯 提交于 2019-11-30 15:18:17
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 the images of cars and race track. But i have no idea how should i show the part of race track and how should show that car is moving on that track?? I suggest you download AndEngine ( an open source 2d android game develoopmnent framework ). In the examples there is a (very simple) race track demo with a movable car

How to Produce Physical Dimension of an Image drawn using Java

泄露秘密 提交于 2019-11-30 10:02:00
问题 I have drawn a square on JPanel in Swing Applet.now i want to print this square having physical dimension 50cm * 50 cm on to paper.it means the print measurement of the square is 50 * 50 cm in real world which i drawn on to panel of an applet .the printer uses 400 DPI to print. so how can i relate these to measurements ? in which file format i should save my drawing so it will have accurate measurement while printing , equals to printer DPI and quality of the image is maintained in print.

Draw on one side of a JPanel

旧街凉风 提交于 2019-11-30 09:55:25
问题 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 encountered was that when I try to implement this draw-mechanic in my frame, no circles appear. public class Application{ int x,y; private JPanel container; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Application().gui(); } }); }

How can I create a drop shadow, inner glow and outer glow in Java Swing?

╄→гoц情女王★ 提交于 2019-11-30 06:15:17
I am generating some images using the Graphics2D interface, and occasionally I'd like to be able to draw some text on the image and apply to it effects like the ones in Adobe Photoshop. Right now to generate a 'shadow' on the text I am drawing the text twice, once in the original color, and once in black with a slight (1px) x&y offset. Unfortunately this is overly simplistic as I need more control over the shadow (opacity,size, spread). As for Inner Glows and Outer Glows, I am not really sure where to start; a mask/gradient paint/alpha blending? Is there a Java library for producing these

Inside clipping with Java Graphics

人盡茶涼 提交于 2019-11-30 03:12:36
问题 I need to draw a line using java.awt.Graphics, but only the portion of the line that lies outside of a rectangle should be rendered. Is it possible to use the Graphics clipping support or do I need to calculate the intersection and clip the line myself? 回答1: You need to use the Area class. This example will demonstrate how to do what you ask: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt

Increasing screen capture speed when using Java and awt.Robot

我们两清 提交于 2019-11-30 01:51:31
问题 Edit: If anyone also has any other recommendations for increasing performance of screen capture please feel free to share as it might fully address my problem! Hello Fellow Developers, I'm working on some basic screen capture software for myself. As of right now I've got some proof of concept/tinkering code that uses java.awt.Robot to capture the screen as a BufferedImage. Then I do this capture for a specified amount of time and afterwards dump all of the pictures to disk. From my tests I'm