awt

mouse motion listener only in one direction

可紊 提交于 2019-11-26 23:35:45
问题 i have been working on mouse motion listener in Java couldn't sort it out completely because i want the object to move towards the direction where ever on the screen the mouse is pointed at but unforunately when the mouse is inside the applet window, the object moves only towards a single direction. Here is my code below.. import java.awt.*; import java.awt.geom.*; import java.util.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class MouseOver extends Applet

AffineTransform truncates image, what do I wrong?

老子叫甜甜 提交于 2019-11-26 23:27:10
问题 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();

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

耗尽温柔 提交于 2019-11-26 23:25:30
问题 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

How can I programmatically generate keypress events? [duplicate]

社会主义新天地 提交于 2019-11-26 23:15:06
问题 This question already has an answer here : How to simulate keyboard presses in java? (1 answer) Closed 2 years ago . What the java program should do is it should trigger keyboard press on some condition without a person pressing a keyboard key. So any program running in windows and in focus which requires keyboard input will get the input without a person actually pressing the keyboard. I found these related questions here : question 1, question 2 I was wondering if there is any method to do

Zoom box for area around mouse location on screen [closed]

痞子三分冷 提交于 2019-11-26 23:13:26
Is there any way to create a dynamic Zoom Box in Java which will include e. g. 20x20pix area around the cursor (but even when cursor will move beyond the Frame of app) and which will be shown for example in a small JPanel? I'm asking in context of a Color Chooser program. The last functionality need to be implemented is just that Zoom Box. I'm sure there are a number of different ways that this could be achieved. This basically uses a separate component, which acts as the "zoom box". You supply it a component that you want to "zoom" on. It adds a mouse listener so it can monitor mouse motion

How to determine if GraphicsEnvironment exists

房东的猫 提交于 2019-11-26 23:03:46
问题 I have an application that needs user input for password. What i want to do is to either read the password from console (if the OS supports one e.g unix) or display a JOptionPane and ask the user to enter his password (if the OS supports graphical interface e.g windows). Some people may argue that a console will always be available in both the above cases so a console input will be sufficient. But problem is if the Java app starts using javaw.exe then a console is not available. Thus, i need

Turn an array of pixels into an Image object with Java's ImageIO?

吃可爱长大的小学妹 提交于 2019-11-26 22:43:33
问题 I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object) into an Image object using the following code: public Image getImageFromArray(int[] pixels, int width, int height) { MemoryImageSource mis = new MemoryImageSource(width, height, pixels, 0, width); Toolkit tk = Toolkit.getDefaultToolkit(); return tk.createImage(mis); } Is it possible to achieve the same result using classes from the ImageIO package(s) so I don't have to use the AWT

KeyListener not working

一笑奈何 提交于 2019-11-26 22:26:39
问题 For some reason, my KeyListener just isn't responding to KeyPressed events. If it matters, I'm on Ubuntu 12.04. It should be printing "Key Pressed" whenever a key is pressed, but it doesn't. Here's the code: import java.awt.event.*; import javax.swing.*; import java.awt.Graphics; public class DisplayPanel extends JPanel { private Tile[][] tiles; private Creature[] creatures; private Dungeon dungeon; private Player player; public DisplayPanel(Dungeon dungeon, Tile[][] tiles, Creature[]

move component after drag and drop

前提是你 提交于 2019-11-26 22:18:46
问题 I've seen code of drag and drop . Question1: how can we move image inside dropped panel (using mouse pointer) after image will be dropped. (destination of image, I want to be where where I release mouse. and then to change location too (using mouse will be better. or using buttons - but using mouse is better) Question2: how can I change location after dropping end? p.s I want here image to component. first I drag and drop component. then change location using mouse pointer (move it). here is

Once exported, java cannot find/draw images

梦想与她 提交于 2019-11-26 22:10:04
问题 Hello stackoverflowites, I am in the process of developing a 2d game, and when I run it inside of eclipse, my program loads all of it's images and resources fine. However, I am using the not-necessarily-recommended way of creating my images and image icons, which is shown below: bannerLogo.setIcon(new ImageIcon("/res/client/BannerHeader.jpg")); Now, when exporting to a jar, it does not show the image (which is expected since im not using the correct way.) I searched for the correct way to do