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 best solutions below
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in AWT
- Opening jar file with external library
- pass a value obtained from a JButton to a variable
- Java repaint updates only part of my Canvas
- How to use panels in applets?
- How can I map an action for option (Mac keyboard) up for a JTextField?
- Disable close button in Processing
- How to get JTabbedPane in JSplitPane to fill the whole window?
- Java AWT setBackground Color by ActionEvent
- Change Color of MenuBar, Menu, and MenuItem in Java using the AWT Components
- How to use JButton with a class extending Canvas?
- How to implement .png pics in a JFrame?
- addActionLister parameter
- how to call a graphical method in actionperformed?
- Debugging GridBagLayout - components clumped to center
- jLabel and jTable conflict
Related Questions in MOUSE-LISTENERS
- Where should I place a new mouseListener in the main method to animate CarShape left or right when the mouse is clicked?
- Getting mouse's position returns position without window bar
- Can you use an Adapter inside of a Listener class?
- How do I create a JPanel with two images where only a part of the one below is shown on mouse over?
- Java jLabel on top of another listener
- No Enclosing instance error
- Checkers Java Code Error
- Single MouseListener Event to get text from JTextArea
- How to get the parent object of a clicked component using getParent()?
- Add actionlistener to jpanel
- Java - mouseMoved() event handling in Swing
- Changing Color of JButton with mouseListener
- How to Change setVisible() on Panels in different Java Class
- How to consume JRadioButton select on mouse click doesn't seem to work
- MouseAdapter methods - why `mouseDragged`, `mouseMoved` and `mouseWheelMoved` included?
Related Questions in MOUSEMOTIONEVENT
- Why does my label not move until after I drag it when I call it to after my mouse wheel event?
- Error finding the angle between two points
- Simple Java Paint Program: How to change the color without changing the previous painted
- JAVA: MouseDragged Event Precision
- How to find the mouse position relative to a panel constantly?
- Java: Filling in Graphics based on 2D array as mouse held down
- MouseAdapter methods - why `mouseDragged`, `mouseMoved` and `mouseWheelMoved` included?
- Is it possible to add MouseMotionListener to BufferedImage?
- Detect current screen bounds
- How should I split joined lines for my paint app in java
- how are the appropriate methods of MouseMotionListener in Java Swing?
- Simulate touch_up event in kivy
- Kivy: Access MouseMotionEvent information from Button on_release/on_press
- How to make a moving ball with mouse motion listener
- matlab get mouse coordinates on image without clicking (on mouse over)
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)
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?
Use
addMouseMotionListenersrather thanaddMouseMotionListenerto register implementedMouseListenersforGraphicsProgram