awt

Java.awt.robot mousepress is not having any effect

南楼画角 提交于 2019-12-11 13:53:56
问题 I'm trying to simulate a left click in a different program using awt.robot, with the following code: int mask = InputEvent.BUTTON1_DOWN_MASK; bot.mouseMove(x, y); bot.mousePress(mask); bot.mouseRelease(mask); While this is moving the mouse to the correct part of the screen, the other program doesn't seem to be receiving the click. What am I doing wrong? In certain other programs, this same method produces the click, but in one program, it has no effect. I have tried Thread.sleep() to wait 30

Java Graphics Full Screen Mode not Registering Keyboard Input

拥有回忆 提交于 2019-12-11 13:47:45
问题 I'm trying to write a full screen application that takes keyboard inputs. I've tried adding keylisteners to my JFrame and now to a canvas within the JFrame and setting them both as focusable but it doesn't seem to be registering anything at all. Is there something special I have do to in full screen mode to get it to register my keyEvents? Any help greatly appreciated. (display is just an extension of JFrame with no changes yet) public class chanceCore implements Runnable, KeyListener,

Switching on a string/implementing button actions

点点圈 提交于 2019-12-11 13:09:36
问题 Full disclaimer: I'm a CS student, and this question is related to a recently assigned Java program for Object-Oriented Programming. Although we've done some console stuff, this is the first time we've worked with a GUI and Swing or Awt. We were given some code that created a window with some text and a button that rotated through different colors for the text. We were then asked to modify the program to create radio buttons for the colors instead—this was also intended to give us practice

Drawing a zigzag (Spring) in java

两盒软妹~` 提交于 2019-12-11 12:46:52
问题 I am currently making a program which animates the simple harmonic motion of a mass-spring when it is displaced. I have everything working apart from the fact that instead of drawing something like a spring, my program currently uses the graphics.drawline method to draw a straight line to represent the spring. I ideally want something like this however I am not very experienced with graphics and don't really know how to approach it, I tried to make an algorithm myself but it kept falling

How can I add States to my game?

拈花ヽ惹草 提交于 2019-12-11 12:35:21
问题 In my current game there are supposed to be different states, for example when I am in the Main Menu of the game, the state would turn "MainMenu", if I am in the game (The game GAME) the state would be "Game". As it is right now it just starts the game GAME and not the MainMenu. So my question is how can I add it so that it works the way it should? EDIT: I want the game to start in the MainMenu-STATE of course, in case that wasn't clear :) And then press "play" to start the Game GAME, "Exit"

How to Rotate AWT rectangle in JAVA?

我的梦境 提交于 2019-12-11 12:03:17
问题 I am creating a small java 2D game and i want to know if there is any way to rotate AWT rectangle AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) origXform.clone(); newXform.rotate(angle, pivotX, pivotY); // pivotX ,pivotY is the starting point of the hand image g2d.setTransform(newXform); Rectangle arm = new Rectangle(bowX + 5, bowY + 55, 60, 5); g2d.drawImage(playerBowReadyImg, bowX, bowY, null); //hand image on the above code i simply draw the

Changing RGB values of a color over time

拈花ヽ惹草 提交于 2019-12-11 11:53:18
问题 I want to create a background color that transitions smoothly between colors by changing its RGB values incrementally. I am using the setBackground(Color) to change the background. Would this be possible in Java? 回答1: Here is some old code that changes the background Color when a component gains focus. import java.awt.*; import java.awt.event.*; import java.util.Hashtable; import java.util.ArrayList; import javax.swing.*; public class Fader { // background color when component has focus

Java AWT list box

跟風遠走 提交于 2019-12-11 11:45:09
问题 I was implementing a pure AWT list box. If the items inside the list box are more than it can accommodate then it creates a scroll bar. I want to customize the scroll bar and place a user defined image over the scroll bar. How can I achieve this? 来源: https://stackoverflow.com/questions/7866465/java-awt-list-box

What is the syntax for a mouseListener when using acm.graphics

不问归期 提交于 2019-12-11 11:42:36
问题 I have a "button" which is just a GRect from the ACM Graphics Library. It has an inherited method addMouseListener which I have tried (and failed) using. I need to know the syntax so that when someone clicks on the "button" I can invoke another method which resides in the same class. I want to know: Is it ButtonName.addMouseListener or addMouseListener(ButtonName) Can I put the line mentioned above right after I create the button? What is the syntax that allows a click on the button to call

Java Applet to BufferedImage [duplicate]

*爱你&永不变心* 提交于 2019-12-11 11:24:13
问题 This question already has an answer here : Swing: Obtain Image of JFrame (1 answer) Closed 6 years ago . I created a JFrame that loads an external applet for a game like so: //Setup everything for the Stub.. Below adds the stub to the applet and creates it. DownloadFile(new URL(World + "/" + Archive), "./gamepack.jar"); CAppletStub Stub = new CAppletStub(new URL(World), new URL(World), this.Parameters); applet = (Applet) new URLClassLoader(new URL[] {new URL(World.toString() + "/" + Archive)}