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.getSelectedIte m());
textOutputPanel.println("N umber of Cluster: " + cluster);
listener = new MouseAdapter(){
public void mousePressed(MouseEvent evt){
mouseDown(evt);
}};
imagePanel.addMouseListene r(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.removeMouseList ener(liste ner);
}
}
}
-------------------------- ---------- ---------- ---------- ------
...
Image image = imagePanel.getImage();
findHeightWidth(image);
bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG B);
Graphics2D graphics = bi.createGraphics();
graphics.drawImage(image, 0, 0, this);
this.pickRandomCentroid();
Clustering cluster = new Clustering(textOutputPanel );
cluster.setCentroid(centro idList); ----------------> to store the rgb in an arraylist
cluster.procCluster(image, w, h, intImg, cluster); ------------------> to do next task using the content in the arraylist
...
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.getSelectedIte
textOutputPanel.println("N
listener = new MouseAdapter(){
public void mousePressed(MouseEvent evt){
mouseDown(evt);
}};
imagePanel.addMouseListene
}
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("(
Pixel pixel = new Pixel(R_val, G_val, B_val);
centroidList.add(pixel);
if (centroidList.size() == cluster)
imagePanel.removeMouseList
}
}
}
--------------------------
...
Image image = imagePanel.getImage();
findHeightWidth(image);
bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARG
Graphics2D graphics = bi.createGraphics();
graphics.drawImage(image, 0, 0, this);
this.pickRandomCentroid();
Clustering cluster = new Clustering(textOutputPanel
cluster.setCentroid(centro
cluster.procCluster(image,
...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.