本文整理汇总了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);
}
示例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);
}
}
示例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();
}
示例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());
}
示例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());
}
}
};
}
示例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);
// }
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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.");
}
示例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;
}
}
}
});
}
示例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;
}