java-2d

Split image into clickable regions

一曲冷凌霜 提交于 2019-11-29 07:54:47
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 clicked. Seems possible anyone? David Kroukamp Have a look at what I have made: This is the image I used for

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

跟風遠走 提交于 2019-11-29 06:42:37
问题 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

how can you make a progress bar without using JProgressBar?

假如想象 提交于 2019-11-29 00:23:47
i am looking at putting a progress bar into a game i am making with a count down from a random number between 5 and 20 down to 0. this is my code so far: package Software; import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JPanel; import javax.swing.Timer; public class CountDownProgressBar extends JPanel { RandomValues randomNum; int timeValue; Timer timer; int length, newLength; public CountDownProgressBar() { timer = new Timer(24, new ActionListener() { @Override public void actionPerformed(ActionEvent

Game design in an OO manner

感情迁移 提交于 2019-11-28 15:52:42
问题 I'm designing a simple game, which uses Java 2D and Newtonian physics. Currently my main "game loop" looks something like: do { for (GameEntity entity : entities) { entity.update(gameContext); } for (Drawable drawable : drawables) { drawable.draw(graphics2d); } } while (gameRunning); When an entity is instructed to update itself it will adjust its velocity and position based on the current forces applied to it. However, I need entities to exhibit other behaviour; e.g. if a "bad guy" is shot

How to show pictures in jFrame, using java2d?

谁都会走 提交于 2019-11-28 14:50:06
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... 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 this... An image to paint A surface to paint on Luckily, both these are relatively easy to achieve in Swing

Drawing the Cannabis Curve

眉间皱痕 提交于 2019-11-28 13:29:43
Inspired by Cannabis Equation from the Math site (it refers to the Wolfram Research Cannabis Curve ) I was wondering.. How would we draw this curve using Java-2D? import java.awt.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import javax.swing.*; import java.io.File; /** Draws the CannabisCurve http://mathworld.wolfram.com/CannabisCurve.html Inspired by a question asked at: http://math.stackexchange.com/q/618786/38356 */ class CannabisCurve { double size = 80d; int pad = 5; CannabisCurve() { JOptionPane.showMessageDialog(null, new ImageIcon

about drawing a Polygon in java

拈花ヽ惹草 提交于 2019-11-28 13:27:14
hi there i'm trying to improve myself about java2D and first of all i'm dealing with drawing polygons. However, i can not see the polygon on frame. I read some tutorials and examples but as i said i face with problems. here is the sample code of drawing a polygon; import java.awt.Color; import java.awt.Graphics; import java.awt.Polygon; import javax.swing.JFrame; public class jRisk extends JFrame { private JFrame mainMap; private Polygon poly; public jRisk(){ initComponents(); } private void initComponents(){ mainMap = new JFrame(); mainMap.setSize(800, 600); mainMap.setResizable(false);

How to draw circle on JPanel? Java 2D

我与影子孤独终老i 提交于 2019-11-28 13:02:11
I have a JPanel for which I set some image as the background. I need to draw a bunch of circles on top of the image. Now the circles will be positioned based on some coordinate x,y, and the size will be based on some integer size. This is what I have as my class. import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import javax.swing.JPanel; class ImagePanel extends JPanel { private Image img; CircleList cList; //added this public ImagePanel(Image img) { this.img = img; Dimension size = new Dimension(img.getWidth(null), img.getHeight(null)); setPreferredSize(size);

Rotating Ball loses sharpness and colors

走远了吗. 提交于 2019-11-28 12:54:13
问题 package testIDE; import java.awt.BorderLayout; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.ArrayList; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import Utils.MyJFrame; public class ExampleClass { public static void main(String[] args) { JFrame ballRotate = new BallRotate(); } } class BallRotate extends MyJFrame {

Create a Trailing line of blood behind a player

强颜欢笑 提交于 2019-11-28 12:19:49
问题 I am currently working on a simple top down shooter. The object is a ball that slides around the screen, and I am trying to make a sort of wet-dragging affect. I am using Java Swing and just the default Graphics2d lib inside. This is what I have: and this is my goal: I need to know how I can make a curved line that has the ability to change alpha at the trailing end. I have searched online but I can only find non-dynamic solutions. (The tail needs to update as the player moves across the