當前位置: 首頁>>代碼示例>>Java>>正文


Java MouseListener類代碼示例

本文整理匯總了Java中java.awt.event.MouseListener的典型用法代碼示例。如果您正苦於以下問題:Java MouseListener類的具體用法?Java MouseListener怎麽用?Java MouseListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MouseListener類屬於java.awt.event包,在下文中一共展示了MouseListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import java.awt.event.MouseListener; //導入依賴的package包/類
public void start(MouseListener listener) {
    frame = new JFrame("Snake for Wear (but now on desktop)");
    frame.getContentPane().setPreferredSize(new Dimension(500, 500));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    surface = new JPanel() {
        @Override
        public void paintComponent(Graphics graphics) {
            render((Graphics2D) graphics);
        }
    };
    surface.setFocusable(true);
    surface.setBackground(Color.black);

    surface.addMouseListener(listener);
    frame.add(surface);

    frame.setVisible(true);
}
 
開發者ID:pontusstjerna,項目名稱:SnakeWear,代碼行數:22,代碼來源:Renderer.java

示例2: init

import java.awt.event.MouseListener; //導入依賴的package包/類
public void init() {
    if (script == null) {
        throw new RuntimeException("Script is null");
    }
    if (script instanceof MouseListener) {
        addMouseListener((MouseListener) script);
    }
    if (script instanceof MouseMotionListener) {
        addMouseMotionListener((MouseMotionListener) script);
    }
    if (script instanceof MessageListener) {
        addMessageListener((MessageListener) script);
    }
    if (script instanceof Paintable) {
        Context.getInstance().addPaintable((Paintable) script);
    }
    if (script instanceof GameActionListener) {
        addActionListener((GameActionListener) script);
    }
}
 
開發者ID:Parabot,項目名稱:Parabot-317-API-Minified-PkHonor,代碼行數:21,代碼來源:ScriptEngine.java

示例3: removeListener

import java.awt.event.MouseListener; //導入依賴的package包/類
public void removeListener() {
    for (MouseListener ml : com.getMouseListeners()) {
        com.removeMouseListener(ml);
    }
    for (MouseMotionListener mml : com.getMouseMotionListeners()) {
        com.removeMouseMotionListener(mml);
    }
    for (KeyListener kl : com.getKeyListeners()) {
        com.removeKeyListener(kl);
    }
    reset();
    com.repaint();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,代碼來源:SelectionManager.java

示例4: init

import java.awt.event.MouseListener; //導入依賴的package包/類
private void init() {
    this.setLayout(new FlowLayout(
            FlowLayout.LEADING, 0, 0));
    setLinkLikeButton(button);
    leftParenthesis = new JLabel("(");                              //NOI18N
    rightParenthesis = new JLabel(")");                             //NOI18N
    add(leftParenthesis);
    add(button);
    add(rightParenthesis);
    MouseListener ml = createLabelMouseListener();
    leftParenthesis.addMouseListener(ml);
    rightParenthesis.addMouseListener(ml);
    button.setEnabled(false);
    this.setMaximumSize(
            this.getPreferredSize());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:LinkButtonPanel.java

示例5: createMouseListener

import java.awt.event.MouseListener; //導入依賴的package包/類
private MouseListener createMouseListener() {
    return new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (SwingUtilities.isRightMouseButton(event)) {
                JComponent comp = (JComponent)event.getSource();
                Item item = null;
                if (comp instanceof JList) {
                    JList list = (JList)comp;
                    Point p = event.getPoint();
                    int index = list.locationToIndex(p);
                    if (index >= 0 && !list.getCellBounds(index, index).contains(p)) {
                        index = -1;
                    }
                    if (index >= 0) {
                        item = (Item)list.getModel().getElementAt(index);
                    }
                }
                Action[] actions = null == item ? category.getActions() : item.getActions();
                JPopupMenu popup = Utilities.actionsToPopup( actions, getComponent() );
                Utils.addCustomizationMenuItems( popup, getPalettePanel().getController(), getPalettePanel().getSettings() );
                popup.show(comp, event.getX(), event.getY());
            }
        }
    };
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:CategoryDescriptor.java

示例6: init

import java.awt.event.MouseListener; //導入依賴的package包/類
public void init() {
        if (script == null) {
            throw new RuntimeException("Script is null");
        }
        if (script instanceof MouseListener) {
            addMouseListener((MouseListener) script);
        }
        if (script instanceof MouseMotionListener) {
            addMouseMotionListener((MouseMotionListener) script);
        }
//        if (script instanceof MessageListener) {
//            addMessageListener((MessageListener) script);
//        }
        if (script instanceof Paintable) {
            Context.getInstance().addPaintable((Paintable) script);
        }
//        if (script instanceof GameActionListener) {
//            addActionListener((GameActionListener) script);
//        }
    }
 
開發者ID:Parabot,項目名稱:Parabot-317-API-Minified-OS-Scape,代碼行數:21,代碼來源:ScriptEngine.java

示例7: CompletionScrollPane

import java.awt.event.MouseListener; //導入依賴的package包/類
public CompletionScrollPane(JTextComponent editorComponent, MouseListener mouseListener) {
    
    setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
    setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
    
    // Use maximumSize property to store the limit of the preferred size
    setMaximumSize(new Dimension(400, 300));
    // At least 2 items; do -1 for title height
    int maxVisibleRowCount = Math.max(2,
        getMaximumSize().height / CompletionLayout.COMPLETION_ITEM_HEIGHT - 1);

    // Add the completion view
    view = new JPanel();
    JCheckBox checkbox = new JCheckBox("Rename comments");
    checkbox.setFocusable(false);
    view.add(checkbox);
    JCheckBox checkbox1 = new JCheckBox("Rename Test Class");
    checkbox1.setFocusable(false);
    view.add(checkbox1);
    setViewportView(view);
    installKeybindings(editorComponent);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:CompletionScrollPane.java

示例8: CloseableTabComponent

import java.awt.event.MouseListener; //導入依賴的package包/類
public CloseableTabComponent(Icon icon, String title, boolean closeable, String tooltip, final NBTabbedPane parent, MouseListener controller) {
    super(new BorderLayout( 2, 0 ) );

    lblTitle.setText( title );
    if( parent.getType() == TabbedType.EDITOR )
        lblTitle.setIcon( icon );
    add(lblTitle, BorderLayout.CENTER);
    lblTitle.setToolTipText( tooltip );

    addMouseListener(controller);
    lblTitle.addMouseListener( controller);
    if( closeable ) {
        closeButton = CloseButtonFactory.createBigCloseButton();
        add(closeButton, BorderLayout.EAST);
        closeButton.addMouseListener( controller );
        if( parent.getType() == TabbedType.EDITOR )
            closeButton.setToolTipText( NbBundle.getMessage(CloseableTabComponent.class, "BtnClose_Tooltip") );
    } else {
        closeButton = null;
    }
    this.parent = parent;
    setOpaque(false);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:CloseableTabComponent.java

示例9: ExtendedJLabel

import java.awt.event.MouseListener; //導入依賴的package包/類
public ExtendedJLabel(	ControlJFrame objPcontrolJFrame,
						MouseListener objPmouseListener,
						String strPlabel,
						Icon objLicon,
						Color objPbackgroundColor,
						int intPtooltip) {

	super(strPlabel, objLicon, SwingConstants.CENTER);
	this.objGcontrolJFrame = objPcontrolJFrame;
	this.intGtooltip = intPtooltip;
	this.setFont(this.objGcontrolJFrame.getFont());
	if (objPbackgroundColor != null) {
		this.setBackground(objPbackgroundColor);
	}
	this.setOpaque(true);
	if (objPmouseListener != null) {
		this.objGmouseListener = objPmouseListener;
		this.addMouseListener(this.objGmouseListener);
	} else {
		if (this.objGmouseListener != null) {
			this.removeMouseListener(this.objGmouseListener);
		}
	}
}
 
開發者ID:jugglemaster,項目名稱:JuggleMasterPro,代碼行數:25,代碼來源:ExtendedJLabel.java

示例10: removeNotify

import java.awt.event.MouseListener; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void removeNotify() {
    super.removeNotify();

    getGUI().dialogRemove(FreeColDialog.this);

    removeAll();
    if (this.pane != null) {
        this.pane.removePropertyChangeListener(this);
        this.pane = null;
    }

    for (MouseListener listener : getMouseListeners()) {
        removeMouseListener(listener);
    }
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:20,代碼來源:FreeColDialog.java

示例11: addMouseListener

import java.awt.event.MouseListener; //導入依賴的package包/類
/**
 * Adds a {@link MouseListener} for this component. Makes sure it works on resized components as
 * well as charts.
 */
@Override
public void addMouseListener(final MouseListener listener) {
	super.addMouseListener(listener);
	// needed because we set the size of them/added tooltips so they intercept events now
	labelAttName.addMouseListener(listener);
	labelStatsMissing.addMouseListener(listener);
	labelStatsConstruction.addMouseListener(listener);
	labelStatsMin.addMouseListener(listener);
	labelStatsMax.addMouseListener(listener);
	labelStatsAvg.addMouseListener(listener);
	labelStatsDeviation.addMouseListener(listener);
	labelStatsLeast.addMouseListener(listener);
	labelStatsMost.addMouseListener(listener);
	labelStatsValues.addMouseListener(listener);
	labelStatsDuration.addMouseListener(listener);
	labelStatsFrom.addMouseListener(listener);
	labelStatsUntil.addMouseListener(listener);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:AttributeStatisticsPanel.java

示例12: removeMouseListener

import java.awt.event.MouseListener; //導入依賴的package包/類
/**
 * Removes a {@link MouseListener} from this component. Makes sure it is removed from resized
 * components as well as from charts.
 */
@Override
public void removeMouseListener(final MouseListener listener) {
	super.removeMouseListener(listener);
	// needed because we set the size of them/added tooltips so they intercept events now
	labelAttName.removeMouseListener(listener);
	labelStatsMissing.removeMouseListener(listener);
	labelStatsConstruction.removeMouseListener(listener);
	labelStatsMin.removeMouseListener(listener);
	labelStatsMax.removeMouseListener(listener);
	labelStatsAvg.removeMouseListener(listener);
	labelStatsDeviation.removeMouseListener(listener);
	labelStatsLeast.removeMouseListener(listener);
	labelStatsMost.removeMouseListener(listener);
	labelStatsValues.removeMouseListener(listener);
	labelStatsDuration.removeMouseListener(listener);
	labelStatsFrom.removeMouseListener(listener);
	labelStatsUntil.removeMouseListener(listener);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:AttributeStatisticsPanel.java

示例13: removeListener

import java.awt.event.MouseListener; //導入依賴的package包/類
/**
 * Removes an event listener from the Panel.
 *
 * @param eventListener
 *        The event listener.
 *
 * @throws IllegalArgumentException
 *        If the event listener isn't supported by this function.
 */
public void removeListener(final EventListener eventListener) {
    if (eventListener instanceof KeyListener) {
        this.removeKeyListener((KeyListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseListener) {
        this.removeMouseListener((MouseListener) eventListener);
        return;
    }

    if (eventListener instanceof MouseMotionListener) {
        this.removeMouseMotionListener((MouseMotionListener) eventListener);
        return;
    }

    throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
 
開發者ID:Valkryst,項目名稱:VTerminal,代碼行數:28,代碼來源:Panel.java

示例14: addDropTarget

import java.awt.event.MouseListener; //導入依賴的package包/類
public void addDropTarget(final Component c, final MouseListener l) {
  c.addMouseListener(new MouseAdapter() {
    public void mouseEntered(MouseEvent e) {
      Component source = (Component) e.getSource();
      if (source.isShowing()) {
        if (lastRelease != null) {
          e.translatePoint(source.getLocationOnScreen().x,
                           source.getLocationOnScreen().y);
          if (isCloseEnough(e.getPoint(), lastRelease.getPoint())) {
            e.translatePoint(-source.getLocationOnScreen().x,
                             -source.getLocationOnScreen().y);
            l.mouseReleased(e);
          }
        }
        else {
          dropTarget = source;
          dropHandler = l;
        }
      }
    }
  });
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:23,代碼來源:DragBuffer.java

示例15: blokajMouseListener

import java.awt.event.MouseListener; //導入依賴的package包/類
private MouseListener blokajMouseListener() {
    final MouseAdapter adapter = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int selectedIndex = blokajTable.getSelectedRow();

            if (selectedIndex < 0) {
                blokajRoomsTable.revalidate();
                blokajRoomsTable.repaint();
                blokajCustomerTable.revalidate();
                blokajCustomerTable.repaint();
            }

            reservIdFromRow = blokajTable.getValueAt(selectedIndex, 0).toString();
            blokajRoomsModel.setRowCount(0);
            populateBlokajRoomsModel(blokajRoomsModel, reservIdFromRow);
            blokajCustomerModel.setRowCount(0);
            populateBlokajCustomerModel(blokajCustomerModel, reservIdFromRow);
            super.mousePressed(e);
        }
    };
    return adapter;
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:24,代碼來源:Main_Blockade.java


注:本文中的java.awt.event.MouseListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。