Mouse 2 « Event « Java Swing Q&A





1. Messagebox with Mouseevent    coderanch.com

I tried to add messagebox when the mouse is released..But is not showing..I don't know where do i went wrong? package MyApplet; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.text.DateFormat; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import javax.swing.*; import java.awt.*; import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; import javax.swing.border.Border; public class test1 ...

2. problem with mouselisteners    coderanch.com

3. mouse curser    coderanch.com

4. Mouse click event    coderanch.com

5. how to draw shapes with mouse?    coderanch.com

So what have you tried so far? Where exactly are you stuck? The problem can be broken down to -- detecting mouse events -- custom painting -- storing already drawn graphics for repeat, OR -- drawing to an offscreen buffer As I don't suppose you expected someone to write the entire code for you, do please help us to help you ...

7. Mouse clicking    coderanch.com

For your XO app, you don't want to use a MouseAnything; you are putting buttons on, which support ActionListeners, so you want ActionListeners. I don't like your design; you ought to be adding your buttons with a for-loop, because they are so similar to one another. You also ought to add ActionListeners to them individually, rather than using addActionListener(this). See these ...

8. on mouse over    coderanch.com

i am implementing jtable.in my jtable i inserted icons into table cells. i have to change icon when mouse pointer enter to icon. i have to change icon when mouse pointer exited from icon. i added mouselistener and i implemented mouse entered and exited methods. i am finding row and columns through mouseevent.getPoint(),table.columnAtPoint(p),table.rowAtPoint(p) methods. but i am getting -1 values to ...

9. mouseclicked    coderanch.com





10. Take screenshots without blinking mouse    coderanch.com

11. help with draw line on mouse click    coderanch.com

hi my code is to draw lines on mouse click between mouse click and release.Though i am able to draw lines but ,previously drawn lines are also shown on JPanel.I want only recently drawn line to be shown.So somebody help me on this where should i make changes in my code to meet my requirement. And my jpanel does not show ...

12. Multiple mouselisteners    coderanch.com

Hi revered wizards, I am writing a style exercice in preparation of a complex program I wish to write in which I'll be dragging around all sorts of objects that will react differently depending on the area's they are dragged over and dropped in. So, first I'm coding a simple Hanoi style game in which the tiles are to be dragged ...

13. Newbie problem with Event ... MouseListener    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class ChessBoard extends JFrame implements MouseListener, MouseMotionListener { JLayeredPane layeredPane; JPanel Board; JLabel chessPiece; int xAdjustment; int yAdjustment; public ChessBoard() { Dimension BoardSize = new Dimension(600, 600); // Use a Layered Pane for this this application layeredPane = new JLayeredPane(); getContentPane().add(layeredPane); layeredPane.setPreferredSize(BoardSize); layeredPane.addMouseListener(this); layeredPane.addMouseMotionListener(this); //Add a chess board to the Layered Pane ...

14. Strange exception possibly related to MouseListener?    coderanch.com

Hi guys/gals, I'm getting a strange exception for which I can't really trace the cause. I'm try to recursively draw a user-defined number of squares or circles in a JFrame. The trouble occurs when I click the 'Draw' button. The myMouseListener class calls the commence() method in the NumberPanel class, and you see the (strange) stack trace that ensues. Can anyone ...

15. Drawing with mouse    coderanch.com

Rob Camick wrote: (...) Or you could also use JLayeredPanes. One layer for the image and one the the panel with your custom painting. The Swing tutorial has a section on "How to Use Layered Panes". my goal is to have this random sized image over which i can draw a straight line of any slope for a start i added ...

16. Trying to update gui when clicking on mouse    coderanch.com

I try to change a circle to be filled or not filled when I click on the circle. But with this code: public class Panel extends javax.swing.JPanel implements MouseListener { Bol[][] points; Graphics g; public void paint(Graphics g) { System.out.println("paint"); this.g = g; super.paintComponent(g); for (int i = 0; i < 10; i++) { for (int j = 0; j < ...





17. Using mouseClicked in swing    coderanch.com

18. how to Draw, mouse dragged points on JPane and Save it    coderanch.com

hi, i am able to draw mouse drag point on JPanel and able to store image that i draw on the pane . how can i do it here is my code import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import javax.swing.*; public class test extends JPanel { private int x1,y1,x2,y2,x,y; public test() { setPreferredSize(new Dimension(400,300)); addMouseListener(new java.awt.event.MouseAdapter() { ...

20. How can i use mouse to click on an image and draw a point after i clicked ?    coderanch.com

Rob Camick wrote:Custom Painting Approaches shows a couple of different ways. It draws a Rectangle but you can change it to paint a dot. It draws on a JPanel but you can change it to draw on a JLabel with an ImageIcon. But, for first time i clicked on image, it get coordinate and draw a red dot, for the second ...

21. Image text on mouseover    coderanch.com

22. Overlapping MouseListeners    coderanch.com

Hi all! I need some help with getting 2 MouseListeners working at the same time on 2 different overlapping JPanels. I have created a sample class that shows what is happening. Perhaps this is "the way that it is", but I need a way around the problem. I have a background panel and a foreground panel. I need to track the ...

23. get constant parameter from mouseEvent    coderanch.com

24. MouseListener isn't working right    coderanch.com

What is wrong with my code? The only thing that works (out of the MouseListener and KeyListener) is the MouseListener. Partially. It is printing out the System.out.println line. It is not doing anything else. import java.awt.*; import java.awt.Color.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.Timer; public class Ball extends JPanel implements ActionListener, MouseListener, KeyListener { //double instead of Double double ...

25. mouseClicked and mouseDragged    coderanch.com

So my latest project is an adaption of Conway's Game of Life, which I've successfully knocked together in an hour or two. For drawing the "pixels" on the grid I use a MouseAdapter which the custom panel listens to. class GridClickListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent e) { int gridX = e.getX() / squareLen; // squareLen is the size ...

26. mouselisteners in a separate class?    coderanch.com

Hi Guys, Background story: I'm working on the structure of my application, which contains a GUI class, and a separate class for each of the checklist form that are loaded into the GUI frame. Now I've got a sh*tload of mouseentered and mouseexited lines in each of the forms. Where do you reckon placing the mouseover code is best? Currently I'm ...

27. MouseListener - mouseEntered question.    coderanch.com

28. Mouse events not getting captured:    coderanch.com

First off, you guys are awesome. You have helped me before, and I appreciate it greatly. This might actually be more appropriate for the threading and synchronization forum, but I thought I'd try this forum first, because I suspect my problem is in how I handle my canvas object: I'm trying to make a fairly graphics intensive program (to be more ...

29. Help understanding why mouse event seems to be registering twice.    coderanch.com

I'm working on a applet that in part will update the user with the amount of times they have clicked and it seems that the variable I set 'count' is doing: count += 2; instead of what I put down as: count ++; I need help understanding why that is. import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.ArrayList; import javax.swing.*; public ...

30. mouse click alert    java-forums.org

31. Basic MouseListener Question    java-forums.org

Just creating a MouseListener is not enough. You also need to add that mouselistener to the component via addMouseListener. Myself, I would avoid having either the MainApplet or the MyJComponent classes implement MouseListener and instead would use an inner class -- if it is a real small listener than an anonymous inner class, if bigger than a non-anonymous inner class, or ...

32. Mouse Event + Image Thresholding    java-forums.org

I currently have a program that opens a .jpg image. I need to add code so that the user can click on the image and then thresholding is applied to the image. I've looked a lot of places for help to implement the mouse event but had no luck. Any help would be appreciated.

33. mouseListener trouble please help!    java-forums.org

Hi everybody! I am working on a Battle Ship game, and i am having some issues with Mouse listener. The problem is i can not add a mouselistener to JFrame, or JPane. Why? here's my code below (all the other stuff works, just the line with the comment gives an error when i add it. Java Code: import javax.swing.*; import javax.imageio.ImageIO; ...

34. mouselistener and mouseactionlistener    java-forums.org

can any one tell why this is giving me following errors: mouse_event.java:19: illegal start of expression public void mousePressed(MouseEvent e){ ^ mouse_event.java:19: illegal start of expression public void mousePressed(MouseEvent e){ ^ mouse_event.java:19: ';' expected public void mousePressed(MouseEvent e){ ^ mouse_event.java:19: ';' expected public void mousePressed(MouseEvent e){ ^ mouse_event.java:26: illegal start of expression public void mouseClicked(MouseEvent e){ ^ mouse_event.java:26: illegal start of ...

35. Mouse event filtering?    java-forums.org

My problem is, that I don't want some components to react on right mouse button click. For example: I have a few JInternalFrames on my JDesktopPane and they are shown in different "layers": one is at the back, one is at the front, others are between them (some behind another) :confused: And when I click on the visible part of some ...

36. Mouseover question    java-forums.org

37. Help with some basics please (mouse events)    java-forums.org

Hey I'm trying to make a number guessing game in Java. The game part of it works perfectly, but I also have a jpg with the instructions for the game. Im trying to make the mouse clicked event hide the instructions and the mouse dragged event show the instructions. I don't see anything wrong with my code..but it doesnt seem to ...

38. Forcing the mouse to stay quiet    java-forums.org

[NOT SOLVED] Forcing the mouse to stay quiet Hello, everbody. In the process of learning more about events and listeners I decided to modify the program from my previous post (a very simple application that draws a circle on the center of the window, then deletes and draws it again when the user clicks a mouse button) so that ...

39. Problem with mouseListener    java-forums.org

Java Code: I've got this Jpanel: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class A3JPanel extends JPanel implements ActionListener, KeyListener, MouseListener { private Rectangle boundary; private Ant[] ants; private Player player; private Timer t; private GameOver over; public A3JPanel() { boundary = new Rectangle(5, 5, 490, 490); ants = new Ant[30]; for (int i = 0; i < ants.length; i++) { ...

40. Problem with mouseListener (REPOST)    java-forums.org

Java Code: I've got this Jpanel: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class A3JPanel extends JPanel implements ActionListener, KeyListener, MouseListener { private Rectangle boundary; private Ant[] ants; private Player player; private Timer t; private GameOver over; public A3JPanel() { boundary = new Rectangle(5, 5, 490, 490); ants = new Ant[30]; for (int i = 0; i < ants.length; i++) { ...

41. Sluggish MouseListener    java-forums.org

Hey all, Im trying to make a simple sudoku problem solver. What I've got at the moment is a set of 9 JPanels as "Grids" each containing 9JPanels as the "Squares". When someone clicks on a square, it should be highlighted. I think ive properly added a mouseListener on each square, and if you click on one it *does* highlight. However, ...

42. mouseListeners    java-forums.org

Your JFrame's contentPane is a JPanel which extends from JComponent (most all Swing components inherit from JComponent either directly or indirectly). I would either get the contentPane via getContentPane() and add the MouseListener to that. But having said that, does your class create JPanels and populate it with components? If so, it's often better to add the mouse listener to one ...

43. Mouse    java-forums.org

Do some research on the MouseEvent class. You create an instance of the class the same as with any other class. Use new and give the constructor some args. The trick is to put the mouse event object into the EventQueue for the app. Here's some code I wrote for AWT several years ago to allow the pressing of the Enter ...

44. SplitButton of dropdownbutton invisible when mouse clicking    java-forums.org

The splitbutton of dropdownbutton is cliked a dropdown menu willbe displayed, but it is not disable when mose cliking operation on the jpanel or outside the window. How to invisible or hiding the SplitButton of dropdownbutton menu when performing mouseevent operation on the jpanle or outside the window? the code is below of this. import java.awt.*; import java.awt.event.*; import javax.swing.*; import ...

45. popup without mouse event    java-forums.org

46. MouseMotionListener    java-forums.org

Hi, I am writting a simple graphics editor and I am having a trouble with mouseMotionListener speed performance. I write a simple class to demonstrate the issue. It basically just counts the Euklidiean distance between two registered points measured in pixels while the mouse is dragged, stores it in set and when mouse is released, it prints the result. I think ...

47. Mouseover with continuous updating?    java-forums.org

I am currently working on a simple swing application which requires shifting the coordinates of an image. This shifting is supposed to occur whenever the mouse if over a rectangle placed near the edges of the screen. If you have played any RTS games such as Starcraft, C&C, or Warcraft 3, it is similar to their shifting movement. Currently, I can ...

48. get onbjet reference on mouse event    java-forums.org

49. KeyListeners doesn't work in NB, while MouseListener does    java-forums.org

KeyListeners doesn't work in NB, while MouseListener does Well, I'm confused about his one. If theses interfaces work identically, both should be handled easily. But they are not. I'm able to control app using mouse, but KeyPressed() is never called for keyboard. Have a look at my code: Java Code: /* * To change this template, choose Tools | ...

50. Polling mouse status directly without MouseEvent?    java-forums.org

I'm currently trying to figure out if a mouse button is held down, but I'd rather not have to rely on setting booleans on the MouseEvents Pressed and Released, as that can cause problems if you alt-tab out of the program. Is there a way to poll the status of the mouse buttons directly as there is with the mouse position? ...

51. Getting all mouse locations    java-forums.org

Hi all, I've been searching around the topic including this forum but haven't come across anything helpful. I'm basically trying to build the "brush" tool in my "paint" program, which I would like to act much like the one in MS Paint or any other paint program you can find. Apart from some other issues I'm trying to figure out, currently ...

52. Java MouseClicked problem.    java-forums.org

i have a problem while using netbeans IDE 7.0.1, this is my campus assignment, i got stucked for 3 days because of this, what i'm going to do is click an image for going through the next page, i made 3 status, first one for normal condition "0", second one for hover "1" and the third one for turn to next ...

53. MouseMotionListener    java-forums.org

54. Mouse dragg not working    java-forums.org

Java Code: import javax.swing.*; import java.awt.*; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.*; import java.awt.font.FontRenderContext; public class Mousedragg extends javax.swing.JApplet { public void init() { Container cont = getContentPane(); cont.setLayout(new BorderLayout()); setPreferredSize(new Dimension(300, 300)); JScrollPane scroll = new JScrollPane(); getContentPane().add(scroll, BorderLayout.CENTER); scroll.getViewport().add(new Imagepanel()); } private class Imagepanel extends JPanel implements MouseListener,MouseMotionListener { Imagepanel image; JScrollPane scroll ...

55. MouseListener & GUI    java-forums.org

Hey all, this is probably going to be the last question i'll have here for a while. But I was wondering what's wrong with this code? I need it for my programming class, and even my teacher doesn't know why it doesn't work. So i'm relying on you guys to help. here is the GUI class: Java Code: /** * The ...

56. Java mouse events in gui.    java-forums.org

58. Problem with TrayIcon and mouse events    forums.oracle.com

is there a way to request my thread to be moved into Swing section? Well, the idea is to post the question in the proper forum in the first place. yes, but i didnt find anything related to my problem. Really, I found posted examples of using a MouseListener. Does your code work for other events or is the problem only ...

59. Problem with MouseListener and JComponent    forums.oracle.com

Hi, I am making a "game" where I have a 2D map made of png images and I want to enable the user to click on each separate image that makes together a whole map. I figured out how to do that in the JPanel when I tried out if the coordinates of the mouseevent overlay any of the used images, ...

60. GUI MouseEvent overwrite in another class.    forums.oracle.com

Thanks for the reply, Basically the project is an instant messaging system. But what I am having trouble with is changing what a button does in the GUI class, when the GUI class is initialized in another class. For Example: In my GUI class I have created a text box and a button, the button doesn't do anything when the GUI ...