Tag: mouseclick event

图像在鼠标框架中没有新鲜点击在Java中

第一次在三个不同arrays的Jframe上显示三个随机图像。 甚至触发了MouseClicked方法,但帧中没有刷新图像。 我想每次点击Frame时刷新三个随机图像。 请帮忙 import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; import javax.swing.*; public class Cards extends JFrame implements MouseListener { public static void main(String[] args) { JFrame frame = new Cards(); frame.setTitle(“Cards”); frame.setSize(500, 500); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); new Cards(); } public Cards() { this.getContentPane().addMouseListener(this); cards1(); cards2(); cards3(); } public void cards1() […]

模仿CTRL +使用Javafx在ListView中单击多个选择

我正在尝试找到在ListView中选择多个项目的不同方法。 GUI将在触摸屏显示器上运行,因此我将无法按CTRL + Click。 通过研究各种过去的post,我已经能够通过将所有选定的项保留在数组中然后循环遍历它以获得最终选择来实现多选。 我的代码唯一的问题是,与CTRL +点击相比,选择顺利完成,每次选择新项目时,我的代码会导致类型闪烁。 所以基本上listView清除所有选择,然后选择正确的选择。 有没有办法让这种转变顺利进行? 是否更容易模仿触摸以获得CTRL +点击效果? selectedList = new int[totalTypes];//total number of item properties for(int x=0; x<selectedList.length;x++){//0 = not selected, 1 = selected selectedList[x]=0; } testView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); testView.setOnMouseClicked(new EventHandler(){ @Override public void handle(Event event){ if(selectedList[testView.getSelectionModel().getSelectedIndex()]==0){ selectedList[testView.getSelectionModel().getSelectedIndex()]=1; } else{ selectedList[testView.getSelectionModel().getSelectedIndex()]=0; } for(int x=0; x<selectedList.length;x++){ if(selectedList[x]==1){ testView.getSelectionModel().select(x); } else{ testView.getSelectionModel().clearSelection(x);; } } } […]

如何在Java窗口外获取鼠标点击坐标

我需要使用Swing实现一个类,当用户点击屏幕上的任何位置时,可以获取鼠标坐标。 如果我想在我自己的窗口中获取鼠标坐标,我会使用MouseListener ,但我希望它能够工作,即使用户点击我的程序外。 我希望我的课程表现得像KColorChooser :用户点击下拉按钮,他可以点击屏幕上的任意位置以获得该点的颜色。 但我不知道是否可以使用纯Java。