java-2d

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

Java- how to clear graphics from a JPanel

主宰稳场 提交于 2020-01-03 13:36:13
问题 I'm creating a simple program where I draw a black oval where I click with my mouse. However I want a new oval to appear and the old one to disappear. How would I go about doing this? I've messed around with the removeAll() method inserted into my mousePressed method, however it isn't working for me. Is the removeAll() method even suitable for this? Or should I use something else? Sorry if the answer is obvious, but I am still new to this and trying to learn. Any advice would be immensely

Multiple calls of paintComponent()

会有一股神秘感。 提交于 2020-01-03 05:51:04
问题 I have these two classes: public class Pencil extends JComponent implements MouseListener, MouseMotionListener{ Plansa plansa; Graphics g; public Pencil(Plansa newCanvas){ this.plansa = newCanvas; this.plansa.setFlagShape(false); } @Override public void mouseDragged(MouseEvent arg0) { plansa.setMouseDragged(arg0); this.plansa.setFlagShape(false); plansa.paintComponent(plansa.getGraphics()); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent

RoundRectangle2D clip is not very smooth

坚强是说给别人听的谎言 提交于 2020-01-03 05:14:31
问题 I have a JPanel that i want to clip the corners so that it has rounded edge. Here is what i am doing. ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(color); Shape s = new RoundRectangle2D.Double(0, 0, width, height, arc, arc); g.setClip(s); So notice that i am setting the clipping to a RoundRectangle2D. Also i am setting anti-aliasing still my rounded edges are really jagged. Soft clipping example this link has a way to do soft

How to display many SVGs in Java with high performance

谁说我不能喝 提交于 2020-01-02 07:54:07
问题 What I want My goal is to be able to display a large number of SVG images on a single drawing area in Java, each with its own translation/rotation/scale values. I'm looking for the simplest solution allowing this, optionally even using OpenGL to speed things up. What I've Tried My initial naive approach was to use SVGSalamander to draw directly on a JPanel, but the performance was pathetic. I poked around around and learned that I should do something like manually convert each SVG into a

Java Swing based game framework. Any advice? [closed]

邮差的信 提交于 2020-01-02 07:44:14
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm developing game using Java Swing framework. Does anyone know good framework based on Swing? Mostly I care about performance of

JLabel animation in JPanel

ε祈祈猫儿з 提交于 2020-01-01 19:33:15
问题 After scratching around I found that it's best to implement a custom image component by extending a JLabel. So far that has worked great as I can add multiple "images" (jlabels without the layout breaking. I just have a question that I hope someone can answer for me. I noticed that in order to animate JLabels across the screen I need to setlayout(null); and setbounds of the component and then to animate eventually setlocation(x,y); . Is this a best practice or a terrible way to animate a

Mouse pointer detection over a Path2D

北慕城南 提交于 2020-01-01 09:44:14
问题 I have constructed a Path2D that represents an unclosed shape consisting of straight lines: I want to be able to detect when the mouse is clicked and the mouse pointer is near to (within a few pixels of) the path. Using the contains method does not work because the algorithm treats the unclosed shape as implicitly closed (i.e. by drawing a straight line between the start and end points). Does anyone know of another mechanism for achieving this? 回答1: Create a BasicStroke (the width controls

How can I create a hardware-accelerated image with Java2D?

不问归期 提交于 2019-12-31 13:52:35
问题 I'm trying to create a fast image generator that does lots of 2d transformations and shape rendering, so I'm trying to use a BufferedImage and then acquire the Graphics2D object to perform all my drawing. My main concern now is to make is really fast so I'm creating a BufferedImage like this: GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); BufferedImage bImage = gc

Swing animation optimization

一曲冷凌霜 提交于 2019-12-31 03:45:08
问题 I have been working on a simple animation using a Timer on a JComponent . However, I experience incredibly choppy motion when I view the animation. What steps should I take to optimize this code? MyAnimationFrame import javax.swing.*; public class MyAnimationFrame extends JFrame { public MyAnimationFrame() { super("My animation frame!"); setSize(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(new AnimationComponent(0,0,50,50)); setVisible(true); } public static void main(String[