java.awt.event.MouseEvent.getPoint()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中java.awt.event.MouseEvent.getPoint()方法的一些代码示例,展示了MouseEvent.getPoint()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MouseEvent.getPoint()方法的具体详情如下:
包路径:java.awt.event.MouseEvent
类名称:MouseEvent
方法名:getPoint

MouseEvent.getPoint介绍

[英]Returns the x,y position of the event relative to the source component.
[中]返回事件相对于源组件的x,y位置。

代码示例

代码示例来源:origin: stackoverflow.com

addMouseListener(myMouseAdapter);
addMouseMotionListener(myMouseAdapter);
public void mousePressed(MouseEvent mEvt) {
  currentPointList = new ArrayList<Point>();
  currentPointList.add(mEvt.getPoint());
  repaint();
  currentPointList.add(mEvt.getPoint());
  repaint();
  currentPointList.add(mEvt.getPoint());
  pointsList.add(currentPointList);
  currentPointList = null;
JFrame frame = new JFrame("DrawStuff");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DrawStuff());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

MouseEvent evt = (MouseEvent)event;
      if(evt.getID() == MouseEvent.MOUSE_CLICKED){
        label.setText("mouse clicked at: " + evt.getPoint());
JFrame frame = new JFrame();
frame.setTitle(title);
frame.getContentPane().add(component, BorderLayout.CENTER);
frame.setSize(900, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
return frame;

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
@Override
public void mouseMoved(MouseEvent e) {
  Point point = e.getPoint();

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("JList Test");
  frame.setLayout(new FlowLayout());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLocationRelativeTo(null);
  String[] selections = {"Java", "C++", "C", "Scala", "JavaScript"};
  JList list = new JList(selections);
  frame.add(new JScrollPane(list));
  frame.pack();
  frame.setVisible(true);

  MouseListener mouseListener = new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent mouseEvent) {

      if (mouseEvent.getClickCount() == 1) {
        int index = list.locationToIndex(mouseEvent.getPoint());
        if (index >= 0) {
          Object obj = list.getModel().getElementAt(index);
          JOptionPane.showMessageDialog(null, obj);

        }
      }
    }
  };
  list.addMouseListener(mouseListener);

}

代码示例来源:origin: stackoverflow.com

for (int col = 0; col < GRID_COLS; col++) {
    panelGrid[row][col] = new JPanel(new GridBagLayout());
    backingPanel.add(panelGrid[row][col]);
panelGrid[1][1].add(blueLabel);
addMouseListener(myMouseAdapter);
addMouseMotionListener(myMouseAdapter);
  clickedPanel = (JPanel) backingPanel.getComponentAt(me.getPoint());
  Component[] components = clickedPanel.getComponents();
  if (components.length == 0) {
    dragLabelHeightDiv2 = dragLabel.getHeight() / 2;
    int x = me.getPoint().x - dragLabelWidthDiv2;
    int y = me.getPoint().y - dragLabelHeightDiv2;
    return;
  int x = me.getPoint().x - dragLabelWidthDiv2;
  int y = me.getPoint().y - dragLabelHeightDiv2;
  dragLabel.setLocation(x, y);
  repaint();
  JPanel droppedPanel = (JPanel) backingPanel.getComponentAt(me.getPoint());
  if (droppedPanel == null) {

代码示例来源:origin: stackoverflow.com

// 'E' stands for enhanced
public class EJSlider extends JSlider {

  public EJSlider() {
   super();
   addMouseListener(new MouseAdapter() {
     @Override
     public void mousePressed(MouseEvent e) {
      Point p = e.getPoint();
      double percent = p.x / ((double) getWidth());
      int range = getMaximum() - getMinimum();
      double newVal = range * percent;
      int result = (int)(getMinimum() + newVal);
      setValue(result);
     }
   });
  }

  public static void main(String[] args) {
   JFrame f = new JFrame();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.add(new EJSlider());
   f.pack();
   f.setVisible(true);
  }
}

代码示例来源:origin: stackoverflow.com

currentMouseLocation = e.getPoint();
addMouseListener(new MouseAdapter() {
 public void mouseReleased(MouseEvent e) {
JFrame test = new JFrame("Tab test");
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(400, 400);
tabs.addTab("Four", new JButton("Four"));
test.add(tabs);
test.setVisible(true);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Test");
frame.add(new JComponent() {
  Point p1, p2;
      public void mouseClicked(MouseEvent e) {
        if (p1 == null || p2 != null) { 
          p1 = e.getPoint();
          p2 = null;
        } else {
          p2 = e.getPoint();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

this.addMouseListener(mouseHandler);
this.addMouseMotionListener(mouseHandler);
public void mousePressed(MouseEvent e) {
  drawing = true;
  p1 = e.getPoint();
  p2 = p1;
  repaint();
public void mouseReleased(MouseEvent e) {
  drawing = false;
  p2 = e.getPoint();
  repaint();
public void mouseDragged(MouseEvent e) {
  if (drawing) {
    p2 = e.getPoint();
    repaint();
  this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0));
  this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA));
  this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0));
  this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA));

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(500,500));
  @Override
  public void mouseClicked(MouseEvent e) {
    int row = table.rowAtPoint(e.getPoint());
    int column = table.columnAtPoint(e.getPoint());

代码示例来源:origin: stackoverflow.com

TableColumn tc = table.getColumnModel().getColumn(BOOLEAN_COL);
tc.setHeaderRenderer(new SelectAllHeader(table, BOOLEAN_COL));
JFrame f = new JFrame();
f.add(new JScrollPane(table));
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
this.applyUI();
this.addItemListener(new ItemHandler());
header.addMouseListener(new MouseHandler());
tableModel.addTableModelListener(new ModelHandler());
  viewColumn = header.columnAtPoint(e.getPoint());
  int modelColumn = tcm.getColumn(viewColumn).getModelIndex();
  if (modelColumn == targetColumn) {

代码示例来源:origin: stackoverflow.com

if(rect.contains(e.getPoint())){
  JOptionPane.showConfirmDialog(this, "Click!");
JFrame frame = new JFrame("Canvas Thingy");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 300, 300);
frame.add(new Canvas());

代码示例来源:origin: stackoverflow.com

setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
setPreferredSize(new Dimension(500, 500));
final JFrame f = new JFrame("Test");
addMouseListener(new MouseAdapter() {
  @Override
  public void mousePressed(MouseEvent e) {
    drag = true;
    dragLocation = e.getPoint();
      if (dragLocation.getX()> getWidth()-10 && dragLocation.getY()>getHeight()-10) {
        System.err.println("in");
        setSize((int)(getWidth()+(e.getPoint().getX()-dragLocation.getX())),
            (int)(getHeight()+(e.getPoint().getY()-dragLocation.getY())));
        dragLocation = e.getPoint();
f.getContentPane().add(this,BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

table.addMouseListener( new MouseAdapter()
      int row = source.rowAtPoint( e.getPoint() );
      int column = source.columnAtPoint( e.getPoint() );
getContentPane().add( new JScrollPane(table) );
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );

代码示例来源:origin: stackoverflow.com

this.addMouseListener(new MouseAdapter() {
    mousePt = e.getPoint();
    repaint();
    int dy = e.getY() - mousePt.y;
    textPt.setLocation(textPt.x + dx, textPt.y + dy);
    mousePt = e.getPoint();
    repaint();
    JFrame f = new JFrame(TITLE);
    f.add(new MouseDragTest());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

代码示例来源:origin: stackoverflow.com

mainMap = new JFrame();
mainMap.setResizable(false);
mainMap.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    super.mouseClicked(me);
    if (poly.contains(me.getPoint())) {
      System.out.println("Clicked polygon");
p.addMouseListener(ma);//add listener to panel
mainMap.add(p);
mainMap.pack();
mainMap.setVisible(true);

代码示例来源:origin: stackoverflow.com

b.addMouseListener(behavior);
b.addMouseWheelListener(behavior);
JFrame f = new JFrame();
f.setLocation(10, 10);
f.setDefaultCloseOperation(3);
f.add(b);
f.pack();
f.setVisible(true);
  startPoint = e.getPoint();
  rectLocale = new Point();
  rectSize = new Dimension();
  Point currentPoint = e.getPoint();
  rectSize.width = Math.abs(currentPoint.x - startPoint.x);
  rectSize.height = Math.abs(currentPoint.y - startPoint.y);

代码示例来源:origin: stackoverflow.com

imageLabel.addMouseListener(myMouseAdapter);
imageLabel.addMouseMotionListener(myMouseAdapter);
imageLabel.setBorder(BorderFactory.createEtchedBorder());
btnPanel.add(saveImageBtn);
btnPanel.add(clearImageBtn);
add(imageLabel, BorderLayout.CENTER);
add(btnPanel, BorderLayout.SOUTH);
  pointList.add(e.getPoint());
  imageLabel.repaint();
  pointList.add(e.getPoint());
  imageLabel.repaint();
JFrame frame = new JFrame("DrawAndSaveImage");
frame.getContentPane().add(new DrawAndSaveImage());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

list.addMouseListener(new MouseAdapter() {
    if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown()
        && !isMenuShortcutKeyDown(e)) {
      list.clearSelection();
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(list));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

addMouseListener(mouseAdapter);
addMouseMotionListener(mouseAdapter);
Floor2 mainPanel = new Floor2(w, h, gridDiv);
JFrame frame = new JFrame("Floor2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
  p1 = e.getPoint();
   return;
  drawingLine = new Line2D.Double(p1, e.getPoint());
  repaint();

相关文章