awt

How to detect JFrame window minimize and maximize events?

ぃ、小莉子 提交于 2019-11-29 19:03:41
问题 Is there a way to an event listener to a JFrame object to detect when the user clicks the window maximize or minimize buttons? Am using the JFrame object as follows: JFrame frame = new JFrame("Frame"); 回答1: You can use WindowStateListener. How to Write Window Listeners tutorial demonstrates how to create window-related event handlers. 回答2: Create a frame and add a listener: JFrame frame = new JFrame(); frame.addWindowStateListener(new WindowStateListener() { public void windowStateChanged

Clipboard monitoring on Mac OS X | Java

◇◆丶佛笑我妖孽 提交于 2019-11-29 18:49:06
问题 I'm having troubles getting data from the system clipboard on Mac OS X. What I'm trying to do is to listen to the system clipboard and print the content of the clipboard each time new [text based] information is put into it. The problem: bellow code works perfectly fine on Windows 7 and openSUSE Linux machines, however when I try running the same code on Mac OS X the program fails to print the new content of the clipboard until focus is given to the application. [Nothing is printed until I

Clear a transparent BufferedImage as fast as possible

帅比萌擦擦* 提交于 2019-11-29 18:24:06
问题 I have a transparent BufferedImage created with the following code(not relevant how it is created, I think): GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); Rectangle screen = transformationContext.getScreen(); // Create an image that supports transparent pixels return gc.createCompatibleImage((int) screen.getWidth(), (int) screen.getHeight(), Transparency

Create a Trailing line of blood behind a player

放肆的年华 提交于 2019-11-29 18:16:42
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 screen.) A simple solution might be to simple add each point to a List of Point s which before the player

Widgets behaving strangely when using “setlayout(null)”

六眼飞鱼酱① 提交于 2019-11-29 18:07:07
I'm doing the following call in my code: ... setLayout(null); ... I'm trying to place a button and a textfield by specifying their x and y coordinates. The problem when I run the program (either with Eclipse or BlueJ) is that I need to run on the panel up to the position of the button and the textfield in order to see respectively the button and the textfield. When I find the textfield, it is small. Only when I start writing it assumes the size I specified. Does anyone know how to solve it? Avoid setLayout (null), unless you have a very good reason for it. You can learn about layout managers

How to draw heart using java awt libaray?

你离开我真会死。 提交于 2019-11-29 18:02:50
How to draw heart using java awt libaray? I am using Java AWT Libaray and I need to draw a heart for my game. How can I do this using AWT? Here what I was thinking: may be use g.fillArc() ? but then if I make two curves at top than how to make a triangle at button? Would that be g.fillPolygon() ? g.fillArc(x, y, 20,20, 60, 60); //so this will be left curve g.fillArc(x+20, y, 20,20, 60, 60); //so right curve? //button triangle? I was wondering if any one is experence in awt and could show me how to do this? Had to write this code for something I'm doing and it works well enough. Draws a

Java keyboard input - game development

最后都变了- 提交于 2019-11-29 17:59:28
I have a specific "problem" with a game I'm creating for class. The game is an implementation of "Break it". To move the platform at the bottom I just used a key listener. The problem is that after the first key press there is a short "lag" or "stutter" before the platform starts moving. How could I prevent this to get a smooth response? Is there another way than KeyListener? KeyBindings? Here is the key listener implementation private class KeyControl implements KeyListener { private int dx = 20; public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_RIGHT) { if(dx < 0 ) dx =

get width and height of JPanel outside of the class

一笑奈何 提交于 2019-11-29 17:42:43
So I created a simple simple simulation where squares are spawned randomly with random vectors and bounce of the edges of the window. I wanted it to take into account the window being resized. So that if I change the dimensions of the window from 600x600 to 1200x600 the squares will bounce of the new border rather than 600x600. I tried doing getWidth() getHeight() but it would return 0. So I put it in the pain() (since it gets called on window resize) method and saved the return values as local variables. But I cannot call getjpWidth() from the Rect class. So basically what I need is to get

Animated GIF leads to SplashScreen being null

谁都会走 提交于 2019-11-29 17:38:34
I know this is probably close to a duplicate of this thread: Animated GIF in Splashscreen But since it seems unanswered and I can't comment on it or anything I'm sorry to repost this but it would be awesome if someone could give me an answer. I am making a game and this game takes quite a lot of time to start. Therefore I want to give the user feedback during the loading screen so he knows the application hasn't crashed. That's why I use the SplashScreen API from java 7. In eclipse, when I run my application using the following configuration in VM Arguments, SplashScreen.getSplashScreen()

Bufferstrategy not showing on java.awt.Frame

落花浮王杯 提交于 2019-11-29 17:29:53
public void configure() { Frame frame = ctx.getFrame(); frame.setTitle("AstroCycles | By: Carlos Aviles"); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setFocusable(true); frame.setSize(WIDTH, HEIGHT); frame.addKeyListener(ctx.getKeyEventDispatcher()); frame.addWindowListener(ctx.getWindowEventDispatcher()); frame.addMouseListener(ctx.getMouseEventDispatcher()); frame.setVisible(true); frame.createBufferStrategy(3); frame.getBufferStrategy().getDrawGraphics().setColor(Color.RED); frame.getBufferStrategy().getDrawGraphics().fillRect(0, 0, 75, 75); frame.getBufferStrategy(