graphics2d

Drawing a line on a JFrame

穿精又带淫゛_ 提交于 2019-11-29 09:57:59
I am trying to draw a line using the Graphics 2D but then the line appears over all the other components in the JFrame thus making them invisible. How do I correct this problem? Here's the code : import javax.swing.*; import java.awt.*; import java.awt.geom.*; class Success extends JFrame{ public Success(){ JPanel panel=new JPanel(); getContentPane().add(panel); setSize(450,450); JButton button =new JButton("press"); panel.add(button); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Line2D lin = new Line2D.Float(100, 100, 250, 260); g2.draw(lin); } public static void main

Painting in a BufferedImage inside Swing

六眼飞鱼酱① 提交于 2019-11-29 05:22:32
Im working on a paint application written in java and running into a few (more) problems. I have a gui and a working program(kinda), my only problem is that the lines and graphics that the user draws are not saved(disappear after next one is drawn). From a past question i learned that i will need to use a BufferedImage to store the drawings then paint that inside my paint class. My questions are, Can anyone provide a basic explanation/example of how to use a bufferedimage to store and paint the drawing and if i need to, how will i pass the color and thickness of the drawn line into a stored

Proper way of printing a BufferedImage in Java

好久不见. 提交于 2019-11-29 04:18:25
问题 I would like to know if there is a proper way of printing a BufferedImage in Java. Basically I have created a photo manipulation program which works fine, I can save images etc. But my real goal is to send it to the printer software so that you can select the amount of pages you want to print and page type. So my shortened question is, how do I send a buffered image to the printer so that a printer selection screen will popup etc and then be able to print? If anyone can show me an example of

Flip Image with Graphics2D

做~自己de王妃 提交于 2019-11-28 22:32:35
问题 I've been trying to figure out how to flip an image for a while, but haven't figured out yet. I'm using Graphics2D to draw an Image with g2d.drawImage(image, x, y, null) I just need a way to flip the image on the horizontal or vertical axis. If you want you can have a look at the full source on github. 回答1: From http://examples.javacodegeeks.com/desktop-java/awt/image/flipping-a-buffered-image: // Flip the image vertically AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx

Drawing Transparent Images In Java Graphics2D

无人久伴 提交于 2019-11-28 18:21:52
I want to draw a PARTIALLY transparent image on top of another (Making shadows over things). I am currently using java's Graphics2D class to render, I've been told to set the composite to AlphaComposite, but that only sets it completely transparent. Can I do this with my current setup? What do I have to do to fix this? This is the code I was told that would make it partially transparent: AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.5F); g.setComposite(ac); (I am using png images by the way) Heres your sscce (these are all in different classes but i put them

plotting a curve around a set of points

老子叫甜甜 提交于 2019-11-28 17:53:26
I have a set of points on a plane. They are partitioned into subsets. I want to plot a closed curve around points that belong to the same subset, so that points that belong to a subset will be inside the curve, and those that aren't will be outside. Therefore simple circles, or a convex hull might not work. For a starter, let's say I just want to have a smooth curve around a set of point (without the requirement that it excludes other points) Any ideas how to do that in R? ---added later--- What I'm looking eventually, is something in the spirit of the graphics in here: https://tex

How to draw images on transparent window?

主宰稳场 提交于 2019-11-28 12:46:44
I'm trying to draw Images with Graphics2D on JFrame. But this code only displays blank background. How to do that? Java Version: SE-1.6 IDE: Eclipse My code looks like this: import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import java.awt.geom.Line2D; import java.util.TimerTask; import javax.swing.JFrame; public class GraphicTest extends JFrame{ public static void main(String[] args) { GraphicTest gt = new GraphicTest(); gt.start(); } JFrame frame; BufferStrategy strategy; GraphicTest(){ int width = 320; int height = 240;

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

Clear portion of graphics with underlying image

你离开我真会死。 提交于 2019-11-28 11:43:11
问题 I'm making a 'game' of sorts where the player has to click on an image bouncing around the screen. The catch is that the screen is in darkness and the mouse cursor is a 'flashlight' which 'light up' a small circle around it. I have a JFrame in one class consisting of: public class GameFrame { public static void main(String[] args) throws IOException { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); JFrame jf = new JFrame("Flashlight Game"); jf.setVisible(true); jf

Painting an Image using Graphics2D

孤街浪徒 提交于 2019-11-28 11:28:03
问题 I'm trying to get an image to paint on the screen using java's Graphics2D. Here is the code I'm using. I want to see an image move steadily across the screen. At the moment I can see the image but it does not move unless I resize the window, in which case it DOES move. I have sketched out the classes below. public class Tester extends JFrame { private static final long serialVersionUID = -3179467003801103750L; private Component myComponent; public static final int ONE_SECOND = 1000; public