graphics2d

Java fillRect() with TexturePaint is slow

人走茶凉 提交于 2019-12-11 19:48:55
问题 TexturePaint Problems I am currently making a 2D game using texturepaints. One significant problem I encountered was the fact that filling rectangles with the graphics2D setPaint method set to a texture paint is extremely slower than filling a rectangle with a base color. Is there possibly any other way to speed up painting by creating a custom class similar to Texturepaint that paints much faster? At this point I really don't know what to do because my fps is stuck at around 18-23fps. EDIT :

Java: How to deal with graphics?

南楼画角 提交于 2019-12-11 19:47:16
问题 I am developing a small desktop application in Java using NetBeans. Since i am new to java so i mostly drag and drop controls and work with them. What i have in my application is JFrame, on that JFrame i place one JScrollPane where i am displaying some textual information. Now i added an other JScrollPane below the above and want to draw some rounded rectangle and then connecting those rectangles with the dotted lines. I also want to put little text in each rectangle. I need guidance from

Updating a rotated JLabel using Graphics2D causes old and new text to merge together

馋奶兔 提交于 2019-12-11 18:22:56
问题 I am trying to rotate a JLabel 90 degrees that shows the current time 90 degrees. After doing some research, most people have recommended using Graphics2D and AffineTransform. This almost works, but when the minute in the time is updated, the new digit appears to merge with the old digit. This does not happen for the seconds. Does anybody have any idea how to fix this issue or have an alternate solution? Driver class: import java.awt.Color; import java.awt.Dimension; import java.awt

Inclined plane Java (Triangle with angle)

落花浮王杯 提交于 2019-12-11 14:57:11
问题 i need to create an inclined plane according to a certain angle with a bloc on it and then use the physics laws to see if the bloc slides or not. For now, i created my bloc with a Path2D.Double, but i can't find a way to change the angle of the bloc. The angle is chosen from a spinner in the frame in the application.I created 2 class, one is the Frame, and the other is the Panel, where i draw my bloc. Here is the code of my path: @Override public void paintComponent(Graphics g) { super

Java How to add String below an image and resizing it?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 13:55:55
问题 I am trying to add a title string below a png image. The problem is that there is no space for the text and I have to add some white space. Im not sure how to do this. This is what I have done so far: BufferedImage image = ImageIO.read(new File("output.png")); Graphics g = image.getGraphics(); g.setFont(g.getFont().deriveFont(30f)); g.setColor(Color.BLACK); g.drawString("Hello World!", 100, 350); g.dispose(); ImageIO.write(image, "png", new File("test.png")); 回答1: Why not simply add the

Combining MouseListeners with Polygons in Graphics2D

限于喜欢 提交于 2019-12-11 13:39:05
问题 I've tried extending Polygon for my data class of choice (implementing MouseListener ). My paintComponent override in the parent JPanel is rendering the extended Polygon class (I called it Hexagon ) with .fillPolygon - it renders fine! But it doesn't let me interact with the MouseListener implemented in the code of it. Is there a stage I'm missing somewhere? Looked around for inspiration, arrived at this: https://docs.oracle.com/javase/tutorial/2d/advanced/user.html Unfortunately this limits

Java setClip seems to redraw

不想你离开。 提交于 2019-12-11 12:36:28
问题 I'm having some troubles with setClip in Java. I have a class that extends JPanel. Within that class I have overridden the paintComponent method. My paintComponent method looks something like this: paintComponent { //draw some lines here Rectangle whole = g2.getClipBounds();//g2 is my Graphics2D object Rectangle part = <some rectangle that is a part of the whole paintable area>; g2.setClip(part); //draw some more stuff here g2.setClip(whole); } The problem that I'm seeing is that the area in

How to Draw a Transparent Background?

回眸只為那壹抹淺笑 提交于 2019-12-11 12:01:25
问题 I am trying to make a piece of a JPanel transparent, but I cannot quite get it to work. Is it possible to do this? import java.awt.*; import javax.swing.*; public class ClearPanel extends JPanel{ public static void main(String[] args) { ClearPanel c = new ClearPanel(); c.setPreferredSize(new Dimension(200, 200)); c.setOpaque(false); JPanel backPanel = new JPanel(); backPanel.setBackground(Color.CYAN); backPanel.add(c); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Java Graphics2D Drawing into BufferedImage

强颜欢笑 提交于 2019-12-11 11:15:58
问题 I'm busy fiddling around with Java's Graphics2D and drawings and I although it works I am not sure how to create a BufferedImage from this graphic which it seems I need to do in order so save it somewhere. I have something very basic because I'm trying to understand how this works import javax.swing.*; import javax.imageio.*; import java.awt.*; import java.awt.image.*; import java.io.*; public class myFrame { public static void main(String[] args) { JFrame lv_frame = new JFrame(); lv_frame

How to draw a butterfly curve as accurate as possible?

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:57:31
问题 I am trying to draw a butterfly curve using Java . Here's the parametric equation for the mentioned curve: From what I remember from the college, the way to draw a parametric equation with Java is the next: public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.translate(300,300); int x1,y1; int x0 = 0; int y0 = (int)(Math.E-2); //for x = 0, we get y = Math.E - 2 int nPoints = 1000; g2.scale(30,-30); for(int i=0;i<nPoints;i++) { double t= 12*i*Math