awt

Make thread run on non EDT (event dispatch thread) thread from EDT

独自空忆成欢 提交于 2019-11-28 01:21:04
问题 I have a method running on the EDT and within that I want to make it execute something on a new (non EDT) thread. My current code is follows: @Override public void actionPerformed(ActionEvent arg0) { //gathering parameters from GUI //below code I want to run in new Thread and then kill this thread/(close the JFrame) new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState); } 回答1: You can create and start a new Java Thread that executes your method

creating huge BufferedImage

こ雲淡風輕ζ 提交于 2019-11-28 01:06:57
I'm unable to create a huge BufferedImage (lack of memory is not the problem). Does anyone have any ideas? 1. new BufferedImage(10000, 1000000, BufferedImage.TYPE_3BYTE_BGR); Exception in thread "main" java.lang.NegativeArraySizeException at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42) at java.awt.image.Raster.createInterleavedRaster(Raster.java:253) at java.awt.image.BufferedImage.<init>(BufferedImage.java:368) 2. new BufferedImage(10000, 1000000, BufferedImage.TYPE_INT_RGB); Exception in thread "main" java.lang.IllegalArgumentException: Dimensions (width=10000 height=1000000)

How does java.awt.Color.getColor(String colorName) work?

你。 提交于 2019-11-28 01:01:04
I'm trying to get colors by name, and I came across Converting a String to Color in Java , which suggests using java.awt.getColor . I can't work out what to pass it as a string though. The following System.out.println( java.awt.Color.getColor( "black", Color.red ) ); prints out java.awt.Color[r=255,g=0,b=0] i.e. it is going with the default color in there. I've put this in a text box, and tried alternative capitalisations etc. The docs aren't very helpful here. Can anyone suggest what magic strings to put in? The non-accepted answer uses Color.getColor . This method reads from system

How To Remove The Last Image In An Animation

人盡茶涼 提交于 2019-11-28 00:36:10
What I am trying to do is create an animation that creates a 'running' motion. Whenever I draw it on the screen, the last frame in the animation is left behind (So there is a trail of animation frames left behind when the sprite moves). I've tried if statements and changing the image's draw position when the frame changes: if(a2.sceneNum() == 0) spectre_Draw1 = (screenWidth() / 2 - 120 / 2 + 120 - 6); else spectre_Draw1 = 0; g.drawImage(pic[2], spectre_Draw1, (screenHeight() / 2 - 180 / 2), null); if(a2.sceneNum() == 1) spectre_Draw2 = (screenWidth() / 2 - 120 / 2 + 120 - 6); else spectre

How to draw a transparent shape using a Graphics object g?

孤街醉人 提交于 2019-11-28 00:32:33
I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this: BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(c); g.fillOval(0, 0, d, d); But now I want to draw a smaller transparent circle in the middle of it to make a ring (so when I draw this image over another image, the pixels around and inside the ring are not drawn). I want to use a Graphics

AffineTransform truncates image, what do I wrong?

◇◆丶佛笑我妖孽 提交于 2019-11-28 00:30:59
I have here an black/white png file of the dimensions 2156x1728 which I want to rotate 90 degrees using AffineTransform. The resulting image doesn't have the right proportions. Here some example code (given I have successfully loaded the png file into the BufferedImage ): public BufferedImage transform(BufferedImage image){ System.out.println("Input width: "+ image.getWidth()); System.out.println("Input height: "+ image.getHeight()); AffineTransform affineTransform = new AffineTransform(); affineTransform.setToQuadrantRotation(1, image.getWidth() / 2, image.getHeight() / 2); AffineTransformOp

Embed HWND (Window Handle) in a JPanel

人盡茶涼 提交于 2019-11-28 00:28:14
I am trying to embed a HWND (Window Handle) in a JPanel. Actually, I can embed my HWND into a JFrame, but the embedded window alway stay on top of the other component and I can't move it. If a try to remove all the child component of my JFrame, the HWND stay there. The HWND seems to be paint on top of the JFrame and not as one of is child. To embed the HWND into the JPanel I use User32 through jna: User32.SetParent(iage.getRenderHwnd(), (int) getGUIHwnd(j)); And I use this to get the HWND of my JFrame: j.getPeer() != null ? ((WComponentPeer) j.getPeer()).getHWnd(): 0; Is there a way to embed a

Create rectangle with mouse drag, not draw

亡梦爱人 提交于 2019-11-28 00:21:45
I want create a rectangle using the whole screen. By using the whole screen, I mean something like this: To start, is that even possible in Java, using the whole screen like that? Second, how would I go about doing it? Another thing, I do not want to draw an actual rectangle, I want to create on, as in a new java.awt.Rectangle . nb- First thing to note, this is done using Java 7, creating a transparent window in Java 6 is done differently and is not possible below update 10 (I believe) Basically, this creates a transparent window, sized and positioned to cover the entire virtual screen (that

How to make a splash screen for GUI?

纵饮孤独 提交于 2019-11-28 00:12:03
Hi there I'm new to GUIs in Java and was trying to make a splash screen or an image appear for 3 seconds. Then after that it it will go onto my main program. Does anyone have an ideas how to do this or can link me to any tutorials? So far I have done this but not sure where to go from here. public static void main(String[] args) { splashInit(); // initialize splash overlay drawing parameters appInit(); // simulate what an application would do } Alya'a Gamal Simplest one , is to create JFrame and add your screen on it then use Thread.Sleep(long millies) Try this code: JWindow window = new

How to flip BufferedImage in java

孤街醉人 提交于 2019-11-28 00:04:05
问题 I get RGB24 byte array and want to show it in Java. public void getByteArray(byte byteArray[]){ int count1 = 0; byte temp1 = 0; for (int i = 0; i < byteArray.length; i++) { //The order of RGB24 is red,green and blue.Change the //order to blue,green and red so that java can use TYPE_3BYTE_BGR to recognize it if (count1 == 0) { temp1 = byteArray[i]; count1++; } else if(count1 == 1) { //do nothing count1++; } else if(count1 == 2) { byteArray[i - 2] = byteArray[i]; byteArray[i] = temp1; count1=0;