Link to home
Start Free TrialLog in
Avatar of hzinox
hzinox

asked on

Problem to store user input using mouse event

Hi,

I have a problem with my mouse event. I have succesfully code my program so that it can accept user input via mouse click event i.e. the user click on any points in my input image and the RGB values of the corresponding points is selected. The next in the sequence is to store the RGB values in an arraylist (for example) so that I can use these values for the subsequent task. My problem is that the RGB values are not captured in the arraylist. What my code do is just let the user click on the point and that's all... Can anyone point out my mistakes and let me have some ideas to solve the problem? TQ.

public void pickRandomCentroid(){
...
      clusterLimit = new Pixel[cluster];
       centroidList = new HashSet();
       cluster = Integer.parseInt( (String) clusterSize.getSelectedItem());
       textOutputPanel.println("Number of Cluster: " + cluster);
       listener = new MouseAdapter(){
         public void mousePressed(MouseEvent evt){
             mouseDown(evt);
           }};
       imagePanel.addMouseListener(listener);
     }
     catch (Exception e) {
         e.printStackTrace();
     }

public void mouseDown(MouseEvent evt){
   mouse_x = evt.getX();
   mouse_y = evt.getY();
   if (mouse_x >= 0 && mouse_x < w) {
     if (mouse_y >= 0 && mouse_y < h) {
       int rgb = bi.getRGB(mouse_x, mouse_y);
       RGB(rgb);
       textOutputPanel.println("(" + R_val + "," + G_val + "," + B_val + ")");
       Pixel pixel = new Pixel(R_val, G_val, B_val);
       centroidList.add(pixel);
       if (centroidList.size() == cluster)
         imagePanel.removeMouseListener(listener);
       }
     }  
  }
--------------------------------------------------------------
...
      Image image = imagePanel.getImage();
      findHeightWidth(image);
      bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      Graphics2D graphics = bi.createGraphics();
      graphics.drawImage(image, 0, 0, this);
      this.pickRandomCentroid();
      Clustering cluster = new Clustering(textOutputPanel);
      cluster.setCentroid(centroidList); ----------------> to store the rgb in an arraylist
      cluster.procCluster(image, w, h, intImg, cluster); ------------------> to do next task using the content in the arraylist
...



SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial