import acm.graphics.*;
import acm.program.*;
import java.awt.Color;
import java.awt.event.*;
public class TestingClass2 extends GraphicsProgram implements MouseMotionListener{
//dimensions of play board
private static final int boardWidth = 402;
private static final int boardHeight = 600;
//paddle
private static final int paddleWidth = 60;
private static final int paddleHeight = 10;
private double xPosition;
GRect paddle;
public void run(){
setSize(boardWidth, boardHeight);
setPaddle();
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e){
xPosition = e.getX();
if(xPosition <= 0 && xPosition <= boardWidth - paddleWidth){
paddle.setLocation(xPosition, 580);
}
}
public void mouseMoved(MouseEvent e){
}
public void setPaddle(){
paddle = new GRect(boardWidth / 2 - 30.0, 580, paddleWidth, paddleHeight);
paddle.setFillColor(Color.BLACK);
paddle.setFilled(true);
add(paddle);
}
}
I want to move GRect. I used mouseMotionListener, but it doesn't work. Check the code, and try to help. Thanks
405 views Asked by user2263005 At
1
There are 1 answers
Related Questions in JAVA
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in AWT
- Caused by : java. awt. HeadlessException
- Java - Sierpinksi's Triangle
- Apache Batik Java Swing, SVG not loading in the right way
- KeyEvent in java does not work for alphabets or numerics but works fine for control, alt,up and down.but was not working for alphabets or numbers
- repaint() leaves trace of object initial position
- How does a FileDialog block the thread without blocking the thread?
- Unexpected results from Area.intersect()
- Bouncing Ball Animation 2/3
- How can I fix the skewing thats going in my graphics renderer caused because of my fov?
- package sun.awt.shell is not visible in java 17
- Java uncatchable ClassNotFoundException when using java.awt.Clipboard
- Difficulty capturing fast mouse movements in Java Swing paint app
- Robot.mouseMove does not move the mouse at all
- Adding datas to Jtable
- Why do I need to set the width to get the maximum size when it contains box horizontal glue in the panel that has a box layout?
Related Questions in MOUSE-LISTENERS
- Calling non-static method from within mousehandler results in error:" non static method cannot be referenced from static context
- Use while loop inside pynput's mouse listener
- Changing Color of JButton with mouseListener
- We are implementing global keyboard and mouse listeners, will they be detected by antiviruses as key-loggers?
- How do I get the program to wait for a click on another part of the GUI?
- I need to create a extension for specific page action
- How to open file chooser in the interactive Jtable with right mouse click
- MouseWheelListener and MouseMotionListener not working together
- How to draw curved lines on the screen with LinkedList and MouseListeners?
- How does the drawing guide in this java paint program work?
- How to get the index of an Arraylist Through mouselistener?
- Difference Between MouseEvents
- PyQt 4 / Qt 4 move QGraphicsItem with mouse using custom event handler
- Mouse-listener that stops a block from executing when the mouse is released
- One MouseListener for many JLabel components
Related Questions in MOUSEMOTIONEVENT
- Simulate touch_up event in kivy
- How should I split joined lines for my paint app in java
- How to make a moving ball with mouse motion listener
- SDL MOUSEMOTION yrel is not giving a proper value
- Updating screen with MouseMotionListener
- how to stop mouse motion event in particular stage
- Kivy: Access MouseMotionEvent information from Button on_release/on_press
- matlab get mouse coordinates on image without clicking (on mouse over)
- how to know if mouse dragged left or right inside jpanel in java
- how are the appropriate methods of MouseMotionListener in Java Swing?
- Simple Java Paint Program: How to change the color without changing the previous painted
- Error finding the angle between two points
- Why does my label not move until after I drag it when I call it to after my mouse wheel event?
- Is it possible to add MouseMotionListener to BufferedImage?
- MouseAdapter methods - why `mouseDragged`, `mouseMoved` and `mouseWheelMoved` included?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Use
addMouseMotionListenersrather thanaddMouseMotionListenerto register implementedMouseListenersforGraphicsProgram