awt

Resize code does not correspond with mouse movement

强颜欢笑 提交于 2019-12-13 06:03:56
问题 I have some code to resize a chatpanel dynamically, but it does not move according to the mouse. What happens is the mouse moves at a faster rate than the panel gets resized. For example, how I want it to be, is in any application, when you click on the border between two windows, and drag it, the mouse stays along with the piece you are clicking on, and currently this is not happening. here is my code. please let me know if you need more public void mouseDragged(MouseEvent e) { if(getCursor(

Creating images with a java

依然范特西╮ 提交于 2019-12-13 05:15:19
问题 Hello) Help solve the problem: We need to create a green square image and display it. I could draw a square, but I need to create it using java. Please help me to do this) That's what I tried to do: import java.awt.Canvas; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.JFrame; public class Game extends Canvas { private static final long serialVersionUID = 1L; private static final int WIDTH = 400; private static final int HEIGHT = 400; @Override public void

KeyListener not being triggered after I swap JPanels

风格不统一 提交于 2019-12-13 04:59:49
问题 Im making a game and Im having it so that when the user presses "I" in the game, the game panel is set to invisible while it adds the Inventory panel to the JFrame. Then when the user exits the Inventory it will remove the Inventory JPanel and then set back the game JPanel to visible. Now this all sounds good, but whenever it removes the Inventory JPanel and goes back to the game JPanel, the KeyListener stops working. I even set back the setFocusable(true) property back on the game JPanel

Java awt Robot still cant press non-numpad arrows on windows?

随声附和 提交于 2019-12-13 04:26:02
问题 This bug is known for years, yet is is still present in Java 1.7.0_25 version which I'm using on Windows 8. The following result are same regardless of wether i have numlock turned on or not: Robot bot = new Robot(); bot.keyPress(KeyEvent.VK_UP); //this in documentation is non-numpad up arrow key bot.keyRelease(KeyEvent.VK_UP); //pressed the numpad up arrow key //folowing line is line #43 bot.keyPress(KeyEvent.VK_KP_UP); //this in documentation is numpad up arrow key bot.keyRelease(KeyEvent

how to put a component at the center of other component that sit in a JPanel

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:09:38
问题 I wondered how do I put a JLabel or a JPanel at the center of a JTable that Sit in a JPanel. I saw one example with BufferedImage but I could not convert it for some resone, here is the example link: Put JLabel on Component in JPanel I put also an image to show what I mean. Press to see the result I need by the way this is how it looks like when I uses windows 8 now... any idea ? 回答1: You can add any component directly to the table (this is how an editor works). You just need to set the size

KeyListener is not working

僤鯓⒐⒋嵵緔 提交于 2019-12-13 03:59:56
问题 The following code is not working. I am trying to move a player left, right, up, and, down using key pressed method but when i press the keys it does not respond. I did not paste the whole code just the part that moves the box there are other if statements to achieve movement of other contents. public class innerClassKeyPressed { void keyPressed( KeyEvent e) { int key= e.getKeyCode(); if(key==KeyEvent.VK_LEFT){ dx=-1; } if(key==KeyEvent.VK_RIGHT){ dx=1; } if (key==KeyEvent.VK_UP){ dy=-1; } if

Java Challenge on Permitting the User to Draw A Line

£可爱£侵袭症+ 提交于 2019-12-13 03:43:45
问题 My question has been alluded to in java draw line as the mouse is moved, however, I have not advanced far enough into this book to have covered JPanels, JFrames and Points as stated by the prior programmer who asked this question. Answering this question definitely would help most beginner programmers better understand the graphics class and drawing, an often intricate process, especially for beginners. According to the text I am using (as I am learning Java on my own), this was the example

java.awt.Robot is not functioning as expected

空扰寡人 提交于 2019-12-13 03:39:30
问题 I have the following code: autoPlay = new Robot(); autoPlay.setAutoDelay(500); autoPlay.mouseMove((game.getLocationOnScreen().x + 1), (game.getLocationOnScreen().y + 1)); autoPlay.mousePress(InputEvent.BUTTON1_DOWN_MASK); autoPlay.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); autoPlay.mouseMove((game.getLocationOnScreen().x + 381), (game.getLocationOnScreen().y + 1)); autoPlay.mousePress(InputEvent.BUTTON1_DOWN_MASK); autoPlay.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); autoPlay.mouseMove((game

mouseEntered will not execute

大城市里の小女人 提交于 2019-12-13 03:38:36
问题 I am trying to do a mouseEntered test to change a square colour however the MouseListener mouseEntered would not execute. The mouse is responding but only to clicks, pressed and release. So i am not sure what is going on. I hope you can help me point my problem thanks. //Class class RectangleClass extends JPanel{ private int height; private int width; private boolean MouseEntered= false; private boolean MouseExit= false; private JPanel myPanel = new JPanel(); //Inner class with mouse Event

Java - get Graphics

我的梦境 提交于 2019-12-13 02:50:26
问题 im making a java swing game. I heard that swing components don't use active rendering(you can only override paint methods), and for that reason, i have been using BufferStrategy with Canvas. Now i have discover the getGraphics() method from JComponent and JPanel. If we can do active render in swing components, why game tutorials still override paint() and paintComponent() ? 回答1: Don't EVER use getGraphics , it can return null and is nothing more the a snap-shot of the last paint cycle.