java-2d

custom shape rotation issue

邮差的信 提交于 2019-12-02 08:42:15
I am trying to rotate a custom shape around its center, but can not get the result as expected. what i want is * shape should be rotated around its center without moving itself. * what my solution is currently doing is rotating a whole shape around its center , by every rotation its changing its position. I have multiple shapes so i have created a class to encapsulate a shape with its transform in following class public abstract class Shoe implements Shape, ShoeShape { // variable declaration /** * */ public Shoe() { position = new Point(); lastPosition = new Point(); } public void draw

how to draw multiple rectangles

我们两清 提交于 2019-12-02 08:36:04
so I am trying to make a simple program where you click on the screen and it creates a block that falls and collides with a larger block beneath and sticks to it. Kind of like a simple collision program. The problem is when I create one block it deletes the block previously. I made an array, but it still does this. Do any of you know what Im doing wrong? Im sure its a simple fix. public class Screen extends JPanel implements Runnable { public static JLabel statusbar; //displays a status bar showing what mouse movements are taking place private Image cat; //image of the cat public int xCoord ;

Slow Java2D Drawing on Integrated Graphics

杀马特。学长 韩版系。学妹 提交于 2019-12-02 07:48:28
I'm working on a simple 2D game, rendering via the Java2D API. I've noticed that when I try to draw on integrated graphics card the performance crashes. I've tested this game on both my main rig with a newer ATI Radeon and my 5 year old laptop which also has an (incredibly antiquated) Radeon. On both I get good FPS, but when I try to use my Intel i5's onboard HD 4000 graphics, it crawls at around 20 FPS. I'm using Full Screen Exclusive mode. At any given moment, I am rendering approximately 1000 images at once. Annoyingly, when I try to getAvailableAcceleratedMemory() it just returns -1 for

Canvas fillRect() not filling defined canvas

你说的曾经没有我的故事 提交于 2019-12-02 07:13:06
I am extending a Canvas and adding it to a JFrame . I understand that AWT and Swing should not be mixed and that drawing on JPanel is preferred but i'm trying to follow a game engine tutorial and i'd like to stick to it since I got it working so far. The Canvas has minimumSize , maximumSize , and prefferedSize set to the dimensions of 550, 400 . When I do a draw call graphics.draw(0,0,550,400) it doesn't fill the entire screen as it should. I changed the draw call to graphics.draw(0,0,560,410) essentially adding 10px to it and it filled the entire screen. Whats wrong? BTW: graphics.draw(10,10

want to drawLine additionally when Timer generates Events

主宰稳场 提交于 2019-12-02 06:08:22
As I wrote in title, I want to drawLine additionally when Timer generates events. Line will be draw like first time; ㅡ second time; ㅡ ㅡ I want line will be added on before's maintained situation If first purpose cannot be done, (because I'm not good at Java yet, that's just my idea) I want to draw N line in Nth events then i redraw new N+1 line in (N+1)th events. Which could be done in Java? P.S. How to stop the Swing Timer ? You'll basically have to (not in order): Build an event to happen on each tick of the timer Pass it to a new timer (stopping the timer is in the documentation) Set some

Which is a better top level container for this design, JFrame with Jpanels, or JDesktop with JInternalFrames

时光怂恿深爱的人放手 提交于 2019-12-02 04:46:41
问题 I'm a beginner with Swing and AWT, I'm looking to build a GUI using Netbeans. My GUI requires three areas, that I'm currently thinking of as JPanels on a JFrame. I require a "Drawing" panel that will listen for mouse input and draw Java2D shapes. The drawing panel will be anchored to the top left. The other two areas are a "Properties" scroll pane, and a "Controller" scroll pane. The controller pane will determine which drawn elements will be displayed via buttons, and the properties scroll

min and max value in 2d array java

佐手、 提交于 2019-12-02 03:59:01
问题 I want to output max and min value of 2d array. Max works well, but min always outputs zero even when theres no zeros in array.I set Math.random() to 99 to prevent smaller chance to get zero in array for this example. Heres full code: public class e { public static void main(String[] args) { int a[][] = new int [5][5]; int l = a[0][0]; int m = a[0][0]; int i,j,r,k; for(i=0;i<a.length;i++) // for(j=0;j<a[i].length;j++){ // 2d array random number generator a[i][j] =(int)(Math.random()*99); // }

drawPolygon keeps drawing lines from starting (mousePressed) location to current (mouseDragged) location

橙三吉。 提交于 2019-12-02 03:19:37
So, I'm trying to dynamically draw a Polygon starting from when I click the mouse until I stop dragging and release. Instead of, for the purpose of this question, a square outline being drawn when I click, drag down, then right-across, then up, then left-across, this is what happens: http://imgur.com/t8ZN3Pp Any suggestions? Notes: model.addPolygon() creates a Polygon with starting points and adds it to an ArrayList called 'polys' model.addPolygonPoint() adds points to this created polygon that is stored in 'polys' my paint function iterates through polys to paint public void mousePressed

Which is a better top level container for this design, JFrame with Jpanels, or JDesktop with JInternalFrames

↘锁芯ラ 提交于 2019-12-02 00:52:37
I'm a beginner with Swing and AWT, I'm looking to build a GUI using Netbeans. My GUI requires three areas, that I'm currently thinking of as JPanels on a JFrame. I require a "Drawing" panel that will listen for mouse input and draw Java2D shapes. The drawing panel will be anchored to the top left. The other two areas are a "Properties" scroll pane, and a "Controller" scroll pane. The controller pane will determine which drawn elements will be displayed via buttons, and the properties scroll pane will show details about any shape object that is clicked in the drawing pane (endpoints, color, etc

How can I save a BufferedImage to be below a particular size

这一生的挚爱 提交于 2019-12-01 17:02:25
问题 (Using java 8) Given a image user needs to be able to specify min/max image size in pixels and also maximum size of saved image in kbs, image is saved as jpg. So I have the first bit working, by resizing buffered image: public static BufferedImage resizeUsingImageIO(Image srcImage, int size) { int w = srcImage.getWidth(null); int h = srcImage.getHeight(null); // Determine the scaling required to get desired result. float scaleW = (float) size / (float) w; float scaleH = (float) size / (float)