Search Results

Search found 364 results on 15 pages for 'mouseevent'.

Page 1/15 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • JavaFX MouseEvent continues when I remove the object it happened on

    - by Kyle
    It took me a while to realize what was going on with mouse events going through my blocking dialog boxes when I closed them, but I finally figured out why. I still don't know any good way to fix it. I have a custom dialog box (that blocks the mouse) with a close button. When I click the close button, I remove the dialog box from the scene, but JavaFx is still processing the MouseEvent and now it finds that there is nothing blocking the screen behind where the cancel button was, so that component receives a MouseEvent. How do I make the mouseEvent stop processing when I see that they pressed cancel and remove the dialog box? Or, is there a way to make the removing of the dialog box not happen until after it is done processing the MouseEvent? Example Code for the problem: import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.shape.Rectangle; import javafx.scene.input.MouseEvent; import javafx.scene.control.Button; var theScene:Scene; var btn:Button; Stage { title: "Application title" scene: theScene= Scene { width: 500 height: 200 content: [ Rectangle{ width: bind theScene.width height: bind theScene.height onMouseClicked: function(e:MouseEvent):Void{ println("Rectangle");} }, Button{ layoutX: 20 layoutY: 50 blocksMouse: true text: "JustPrint" action:function():Void{ println("JustPrint");} }, btn = Button{ layoutX: 20 layoutY: 20 blocksMouse: true text: "Cancel" action:function():Void{ println("Cancel"); delete btn from theScene.content;} }, ] } } When you press "JustPrint" you get: JustPrint When you press "Cancel" you get: Cancel Rectangle

    Read the article

  • Flash AS3 undefined property MouseEvent in document class

    - by Lee
    Hi guys, this is my first time trying to use document classes in AS3 and im struggling. I am trying to add event listeners to a 2 levels deep movie clip, waiting for a click however i am getting the following error. ERROR: Access of undefined property MouseEvent package { import flash.display.MovieClip; import flash.media.Sound; import flash.media.SoundChannel; public class game extends MovieClip { public var snd_state = true; public function game() { ui_setup(); } public function ui_setup() { ui_mc.toggleMute_mc.addEventListener(MouseEvent.CLICK, snd_toggle); } public function snd_toggle(MouseEvent) { // 0 = No Sound, 1 = Full Sound trace("Toggle"); } } }

    Read the article

  • Dispatch MouseEvent

    - by shay
    there is a way to Dispatch MouseEvent , same as dispatchKeyEvent using the KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(listener); that happens before the event transferred to the component ? i know i have 2 options 1) add mouse event to all compoenents recursive 2) use a transparent glasspane dose java support this , or i have to use the one of the options above thank you

    Read the article

  • FLex MouseEvent doesn't fire when Mouse stays over element

    - by Tomaszewski
    Hi, i'm trying to make a scrollable box, when a mouse enters and STAYS on "wrapper"'s area, "pubsBox" moves 10 pixels to the left. <mx:Canvas id="wrapper" height="80" width="750"> <mx:HBox id="pubsBox" horizontalGap="10" height="80" width="100%" /> </mx:Canvas> My problem is that I'm not sure how to make the MouseEvent.MOUSE_OVER work, to recognize that the mouse is still ON the area and so pubsBox should continue to move 10 pixels to the left every second. I understand that i have to use a Timer, but what I'm concerned about is the fact that I can't get Flex to recognize that the mouse is still OVER "wrapper" and continue firing the event. Any ideas?

    Read the article

  • MouseEvent.CLICK not working? (AS3)

    - by Jake
    ok so here's my code in AS3, I'd like to know why when i actually click on the picture, nothing happens. And if any of you have great tutorial of what to learn after classes/functions in AS3, let me know =D : package { import flash.display.Bitmap; import flash.display.Sprite; import flash.display.Shape; import flash.events.MouseEvent; public class Main extends Sprite { [Embed(source="../Pics/Picture.png")] private var HeroClass:Class; private var hero:Bitmap = new HeroClass(); public function Main():void { addChild(hero); hero.addEventListener(MouseEvent.CLICK, onClick); function onClick(e:MouseEvent):void { trace("hey"); hero.visible = false; } } } }

    Read the article

  • ActionScipt MouseEvent's CLICK vs. DOUBLE_CLICK

    - by TheDarkIn1978
    is it not possible to have both CLICK and DOUBLE_CLICK on the same display object? i'm trying to have both for the stage where double clicking the stage adds a new object and clicking once on the stage deselects a selected object. it appears that DOUBLE_CLICK will execute both itself as well as 2 CLICK functions. in other languages i've programmed with there was a built-in timers that set the two apart. is this not available in AS3?

    Read the article

  • Possible to manipulate UI elements via dispatchEvent()?

    - by rinogo
    Hi all! I'm trying to manually dispatch events on a textfield so I can manipulate it indirectly via code (e.g. place cursor at a given set of x/y coordinates). However, my events seem to have no effect. I've written a test to experiment with this phenomenon: package sandbox { import flash.display.Sprite; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFieldType; import flash.text.TextFieldAutoSize; import flash.utils.setTimeout; public class Test extends Sprite { private var tf:TextField; private var tf2:TextField; public function Test() { super(); tf = new TextField(); tf.text = 'Interact here'; tf.type = TextFieldType.INPUT; addChild(tf); tf2 = new TextField(); tf2.text = 'Same events replayed with five second delay here'; tf2.autoSize = TextFieldAutoSize.LEFT; tf2.type = TextFieldType.INPUT; tf2.y = 30; addChild(tf2); tf.addEventListener(MouseEvent.CLICK, mouseListener); tf.addEventListener(MouseEvent.DOUBLE_CLICK, mouseListener); tf.addEventListener(MouseEvent.MOUSE_DOWN, mouseListener); tf.addEventListener(MouseEvent.MOUSE_MOVE, mouseListener); tf.addEventListener(MouseEvent.MOUSE_OUT, mouseListener); tf.addEventListener(MouseEvent.MOUSE_OVER, mouseListener); tf.addEventListener(MouseEvent.MOUSE_UP, mouseListener); tf.addEventListener(MouseEvent.MOUSE_WHEEL, mouseListener); tf.addEventListener(MouseEvent.ROLL_OUT, mouseListener); tf.addEventListener(MouseEvent.ROLL_OVER, mouseListener); } private function mouseListener(event:MouseEvent):void { //trace(event); setTimeout(function():void {trace(event); tf2.dispatchEvent(event);}, 5000); } } } Essentially, all this test does is to use setTimeout to effectively 'record' events on TextField tf and replay them five seconds later on TextField tf2. When an event is dispatched on tf2, it is traced to the console output. The console output upon running this program and clicking on tf is: [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=0 localY=1 stageX=0 stageY=1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="rollOver" bubbles=false cancelable=false eventPhase=2 localX=0 localY=1 stageX=0 stageY=1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseOver" bubbles=true cancelable=false eventPhase=3 localX=0 localY=1 stageX=0 stageY=1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=2 localY=1 stageX=2 stageY=1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=2 localY=2 stageX=2 stageY=2 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=2 localY=3 stageX=2 stageY=3 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=3 localY=3 stageX=3 stageY=3 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=5 localY=3 stageX=5 stageY=3 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=6 localY=5 stageX=6 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=7 localY=5 stageX=7 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=9 localY=5 stageX=9 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=10 localY=5 stageX=10 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=11 localY=5 stageX=11 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=12 localY=5 stageX=12 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseDown" bubbles=true cancelable=false eventPhase=3 localX=12 localY=5 stageX=12 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseUp" bubbles=true cancelable=false eventPhase=3 localX=12 localY=5 stageX=12 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="click" bubbles=true cancelable=false eventPhase=3 localX=12 localY=5 stageX=12 stageY=5 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=10 localY=4 stageX=10 stageY=4 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=9 localY=2 stageX=9 stageY=2 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseMove" bubbles=true cancelable=false eventPhase=3 localX=9 localY=1 stageX=9 stageY=1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="mouseOut" bubbles=true cancelable=false eventPhase=3 localX=-1 localY=-1 stageX=-1 stageY=-1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] [MouseEvent type="rollOut" bubbles=false cancelable=false eventPhase=2 localX=-1 localY=-1 stageX=-1 stageY=-1 relatedObject=null ctrlKey=false altKey=false shiftKey=false delta=0] As we can see, the events are being captured and replayed successfully. However, no change occurs in tf2 - the mouse cursor does not appear in tf2 as we would expect. In fact, the cursor remains in tf even after the tf2 events are dispatched. Please help! Thanks, -Rich

    Read the article

  • JavaFX2: Drag Event start and end coordinates

    - by user
    I have one node(ImageView) that displays an image and another node(rectangle) that resides on top of it. The behavior I need is that when the mouse is dragged(press-drag-release gesture) over the rectangle, both the nodes should move coherently. My thought process goes in the following direction: • Move both the nodes by the same distance in the direction of the drag. For this option(maybe there are more options) I need the distance between the start and end of the mouse drags. I tried capturing the start and end coordinates of the drag but have been unsuccessful. I think I am getting lost in which handlers to implement. The code I have is below: import javafx.event.EventHandler; import javafx.geometry.Rectangle2D; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; public class MyView { double mouseDragStartX; double mouseDragEndX; double mouseDragStartY; double mouseDragEndY; ImageView imageView; public MyView() { imageView = new ImageView("C:\\temp\\test.png"); } private void setRectangleEvents(final MyObject myObject) { myObject.getRectangle().setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { mouseDragStartX = mouseEvent.getX(); mouseDragStartY = mouseEvent.getY(); mouseEvent.consume(); } }); myObject.getRectangle().setOnMouseReleased(new EventHandler<MouseEvent>() { public void handle(MouseEvent mouseEvent) { mouseDragEndX = mouseEvent.getX(); mouseDragEndY = mouseEvent.getY(); myObjectDraggedHandler(); } }); } private void myObjectDraggedHandler() { Rectangle2D viewport = this.imageView.getViewport(); double newX = this.imageView.getImage().getWidth() + (mouseDragEndX - mouseDragStartX); double newY = this.imageView.getImage().getHeight() + (mouseDragEndY - mouseDragStartY); this.imageView.setViewport(new Rectangle2D(newX, newY, viewport.getWidth(), viewport .getHeight())); } } P.S: This code is just for indicating what I am trying to implement and will not compile correctly. Or maybe my question should just have been: How to capture the length or span of a mouse drag?

    Read the article

  • receiving error #1009 in flash cs4 actionscript3

    - by Leah
    I'm having a weird issue where my buttons will work initially and direct me to an appropriate page, but when i go back to that page and try to use the buttons the roll-overs work but none of the buttons direct to a different page. This is the actionscript on the initial page with the buttons. If I choose any of these buttons they work. For example the profile_btn will take me to the go_to_page" stop(); import flash.events.MouseEvent; //button instancese listed below profile_btn.addEventListener(MouseEvent.CLICK, aClick); function aClick(event:MouseEvent):void{ gotoAndPlay("go_to_page"); } color_btn.addEventListener(MouseEvent.CLICK, cClick); function cClick(event:MouseEvent):void{ gotoAndPlay("color_page"); } drawing_btn.addEventListener(MouseEvent.CLICK, dClick); function dClick(event:MouseEvent):void{ gotoAndPlay("drawing_page"); } letsgo_btn.addEventListener(MouseEvent.CLICK, fClick); function fClick(event:MouseEvent):void{ gotoAndPlay("home_page"); } //go to flash fish animation digital_btn.addEventListener(MouseEvent.CLICK,onMouseClick2); function onMouseClick2(e:MouseEvent):void { var request:URLRequest=new URLRequest("aquarium2.swf"); navigateToURL(request,"blank");} //go to resume document resume_btn.addEventListener(MouseEvent.CLICK,onMouseClick3); function onMouseClick3(e:MouseEvent):void { var request:URLRequest=new URLRequest("LeahHonseyResume.pdf"); navigateToURL(request,"blank"); once at the go_to_page, it plays through a motion tween and ends up at the profile_page. from this page, there is a home_btn. Here is the actionscript for the profile_page. stop(); home_btn.addEventListener(MouseEvent.CLICK, gClick); function gClick(event:MouseEvent):void{ gotoAndPlay("return_frame"); } But when I click on the home_btn I get an output: TypeError: Error #1009: Cannot access a property or method of a null object reference. at flash7_fla::MainTimeline/frame38() It does take me to the correct page, but none of the button then on this page are working. the actionscript for the return_frame page is: stop(); import flash.events.MouseEvent; //button instances listed below profile_btn.addEventListener(MouseEvent.CLICK, hClick); function hClick(event:MouseEvent):void{ gotoAndPlay("profile_page"); } color_btn.addEventListener(MouseEvent.CLICK, iClick); function iClick(event:MouseEvent):void{ gotoAndPlay("color_page"); } drawing_btn.addEventListener(MouseEvent.CLICK, jClick); function jClick(event:MouseEvent):void{ gotoAndPlay("drawing_page"); } letsgo_btn.addEventListener(MouseEvent.CLICK, kClick); function kClick(event:MouseEvent):void{ gotoAndPlay("home_page"); } //go to flash fish animation digital_btn.addEventListener(MouseEvent.CLICK,onMouseClick4); function onMouseClick4(e:MouseEvent):void { var request:URLRequest=new URLRequest("aquarium2.swf"); navigateToURL(request,"blank");} //go to resume document resume_btn.addEventListener(MouseEvent.CLICK,onMouseClick5); function onMouseClick5(e:MouseEvent):void { var request:URLRequest=new URLRequest("LeahHonseyResume.pdf"); navigateToURL(request,"blank");} Can anyone help me figure out why this script is not working? Thank you. I am a beginner flash user, and am trying to build my portfolio site for a homework assignment on Monday. Leah

    Read the article

  • flash as3, Error #1009

    - by smerels
    I'm making a website that exist out of linked pages. All the pages are on the time line and all the code is in an as3 file. The first page with links works but if I want to place a link on the second frame I get the 1009 error Cannot access a property or method of a null object reference. Because the link doesn't exist on the first frame. This is my code. package { import flash.display.MovieClip; import flash.events.MouseEvent; public class Honger extends MovieClip { public function Honger():void { weten.buttonMode = true; weten.addEventListener(MouseEvent.CLICK, onClickWeten); spelen.buttonMode = true; spelen.addEventListener(MouseEvent.CLICK, onClickSpelen); antwoorden.buttonMode = true; antwoorden.addEventListener(MouseEvent.CLICK, onClickAntwoorden); } public function onClickWeten(e:MouseEvent):void { this.gotoAndStop("vragen"); } public function onClickSpelen(e:MouseEvent):void{ this.gotoAndStop("spel"); } public function onClickAntwoorden(e:MouseEvent):void{ this.gotoAndStop("sp"); } } } Does anyone know how to solve this problem within the code?

    Read the article

  • Adobe Flex Datagrid: addEventListener MouseEvent.CLICK

    - by JonoB
    I have a datagrid with a custom label itemrenderer (basically it makes the label look like a traditional html hyperlink). <mx:DataGridColumn id="itemId"> <mx:itemRenderer> <mx:Component> <controls3:HyperlinkLabel text="{data.doc}" /> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> The above works perfectly. I'd like to try add an event listener to this itemrenderer, but I'm not sure how to do this given that I cant specify an id for the itemrendered itself. I tried the following, but it doesnt seem to work: itemId.addEventListener(MouseEvent.CLICK, onItemSelect);

    Read the article

  • Problem with Flash...help

    - by aarontb
    Hey Guys...need help. Working on a project and get this error on the Output Log TypeError: Error #1009: Cannot access a property or method of a null object reference. at FlashSite_fla::MainTimeline/frame16() Here's every frame that is on, begins, or crosses frame 16 Layer Name: Top Menu (4 Button named Home_btn, Works_btn, Tech_btn, Contact_btn) Code attached to frame: stop(); Home_btn.addEventListener(MouseEvent.CLICK, home); function home(event:MouseEvent):void { gotoAndStop(16); } Works_btn.addEventListener(MouseEvent.CLICK, works); function works(event:MouseEvent):void { gotoAndStop(17); } Tech_btn.addEventListener(MouseEvent.CLICK, tech); function tech(event:MouseEvent):void { gotoAndStop(18); } Contacts_btn.addEventListener(MouseEvent.CLICK, contact); function contact(event:MouseEvent):void { gotoAndStop(19); } Layer Name: Investment Opp (button named Invest_btn) Code attached to frame: Invest_btn.addEventListener(MouseEvent.CLICK, invest); function invest(event:MouseEvent):void { var link:URLRequest = new URLRequest('#'); navigateToURL(link); } Layer Name: MfgOpp (Button named Mfg_btn) Code attached to frame: Mfg_btn.addEventListener(MouseEvent.CLICK, mfg); function mfg(event:MouseEvent):void { var link:URLRequest = new URLRequest('#'); navigateToURL(link); } Layer Name: MarketResearch (button name Own_btn) Code attached to frame: Own_btn.addEventListener(MouseEvent.CLICK, own); function own(event:MouseEvent):void { var link:URLRequest = new URLRequest('#'); navigateToURL(link); } Layer Name: ActionScript Code attached to frame: import flash.events.MouseEvent; What am I doing wrong?!?!

    Read the article

  • sendmessage mouseevent not working

    - by kevin
    I have this code: Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Dim WindowHandle As Long = FindWindow(vbNullString, "Ultima Online") SendMessage(WindowHandle, MOUSEEVENTF_LEFTDOWN, 0, 0) SendMessage(WindowHandle, MOUSEEVENTF_LEFTUP, 0, 0) I know it is getting the windowhandle fine, because I made a conditional statment that pops up a messagebox if windowhandle = 0 The problem is that it is not sending the mouse click to the window.

    Read the article

  • Mouse event in Java

    - by Harish
    I am trying to move a JComponent say a label over a table.I am tracking this event using MouseMotionListener's mouseDragged method.This method perfectly helps me in tracking the item.Is there a way to track the mouse release after dragging is complete(.ie the dropping event). tktLabel1.addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent arg0) { tktLabel1.setBounds(tktLabel1.getX() + arg0.getX(), tktLabel1.getY() + arg0.getY(), width, height); } public void mouseMoved(MouseEvent arg0) { } });

    Read the article

  • How can you prevent both jumpiness, and interrupting tweens with animated Flash buttons?

    - by Kevin Suttle
    This is something I've never been able to figure out. You've got a button offscreen you want to animate in. We'll call it 'btn.' You've got a hit area that serves as the proximity sensor to trigger btn's animation. We'll call it 'hitZone' (as to not cause confusion with the hitArea property of display objects). Both btn and hitZone are MovieClips. The listeners go something like this. import com.greensock.*; import com.greensock.easing.*; import flash.events.MouseEvent; var endPoint:Number = 31; hitZone.addEventListener(MouseEvent.ROLL_OVER, onHitZoneOver); hitZone.addEventListener(MouseEvent.ROLL_OUT, onHitZoneOut); hitZone.addEventListener(MouseEvent.CLICK, onHitZoneClick); btn.addEventListener(MouseEvent.ROLL_OVER, onBtnOver); btn.addEventListener(MouseEvent.ROLL_OUT, onBtnOut); btn.addEventListener(MouseEvent.CLICK, onBtnClick); btn.mouseChildren = false; function onHitZoneOver(e:MouseEvent):void { TweenLite.to(btn, 0.75, {x:endPoint, ease:Expo.easeOut}); trace("over hitZone"); } function onHitZoneOut(e:MouseEvent):void { TweenLite.to(btn, 0.75, {x:-1, ease:Expo.easeOut}); trace("out hitZone"); } function onBtnOver(e:MouseEvent):void { hitZone.mouseEnabled = false; hitZone.removeEventListener(MouseEvent.ROLL_OVER, onHitZoneOver); hitZone.removeEventListener(MouseEvent.ROLL_OUT, onHitZoneOut); trace("over BTN"); // This line is the only thing keeping the btn animation from being fired continuously // causing jumpiness. However, calling this allows the animation to be interrupted // at any point. TweenLite.killTweensOf(btn); } function onBtnOut(e:MouseEvent):void { hitZone.mouseEnabled = true; hitZone.addEventListener(MouseEvent.ROLL_OVER, onHitZoneOver); hitZone.addEventListener(MouseEvent.ROLL_OUT, onHitZoneOut); trace("out BTN"); } function onBtnClick(e:MouseEvent):void { trace("click BTN"); } function onHitZoneClick(e:MouseEvent):void { trace("click hitZone"); } The issue is when your mouse is over both the hitZone and btn. The button continuously jumps unless you call TweenLite.killAllTweensOf(). This fixes the jumpiness, but it introduces a new problem. Now, it's very easy to interrupt the animation of the btn at any point, stopping it before it's totally visible on the stage. I've seen similar posts, but even they suffer from the same issue. Perhaps it's a problem with how Flash detects edges, because I've never once seen a workaround for this.

    Read the article

  • Is there a way to catch a MOUSE_UP Event over a static textfield in Flash?

    - by Jovica Aleksic
    When the user presses the mouse, and releases it over a static textfield with selectable text, no MOUSE_UP event is fired - not on the stage and also nowhere else. I experienced this when using a scrollbar class on a movieclip with a nested static textfield. When the user drags the scroll handle and releases the mouse over the textfield, the dragging/scrolling is stuck. To test this, create a new AS3 fla file, place a static textfield somewhere, and put in some text. Make sure the selectable property is checked in the properties panel. Add this script to the timeline: import flash.events.* function down(event:Event):void { trace('down'); } function up(event:Event):void { trace('up'); } stage.addEventListener(MouseEvent.MOUSE_DOWN, down) stage.addEventListener(MouseEvent.MOUSE_UP, up) Now test the movie and click the mouse. You will notice that trace('up') will not occur when you release the mouse over the textfield.

    Read the article

  • How to create custom MouseEvent.CLICK event in AS3 (pass parameters to function)?

    - by fromvega
    Hello, This question doesn't relate only to MouseEvent.CLICK event type but to all event types that already exist in AS3. I read a lot about custom events but until now I couldn't figure it out how to do what I want to do. I'm going to try to explain, I hope you understand: Here is a illustration of my situation: for(var i:Number; i < 10; i++){ var someVar = i; myClips[i].addEventListener(MouseEvent.CLICK, doSomething); } function doSomething(e:MouseEvent){ /* */ } But I want to be able to pass someVar as a parameter to doSomething. So I tried this: for(var i:Number; i < 10; i++){ var someVar = i; myClips[i].addEventListener(MouseEvent.CLICK, function(){ doSomething(someVar); }); } function doSomething(index){ trace(index); } This kind of works but not as I expect. Due to the function closures, when the MouseEvent.CLICK events are actually fired the for loop is already over and someVar is holding the last value, the number 9 in the example. So every click in each movie clip will call doSomething passing 9 as the parameter. And it's not what I want. I thought that creating a custom event should work, but then I couldn't find a way to fire a custom event when the MouseEvent.CLICK event is fired and pass the parameter to it. Now I don't know if it is the right answer. What should I do and how?

    Read the article

  • MouseMotionListener inside JTable

    - by Harish
    I am trying to add MouseMotion event to the label and move it based on the dragging of the mouse and make it move along with my mouse.However the mousemotion is very difficult to control making this action not usable. Here is the code import java.awt.Color; import java.awt.Component; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; public class TableTest { public TableTest() { String[] columnNames = { "FileName", "Integer" }; Object[][] data = { { new FileName("AAA.jpg", Color.YELLOW), new Integer(2) }, { new FileName("BBB.png", Color.GREEN), new FileName("BBB.png", Color.GREEN) }, { new FileName("CCC.jpg", Color.RED), new Integer(-1) }, }; DefaultTableModel model = new DefaultTableModel(data, columnNames) { public Class getColumnClass(int column) { System.out.println("column is" + column); return getValueAt(0, column).getClass(); } }; JTable table = new JTable(model); //JTable table = new JTable(data, columnNames); table.setDefaultRenderer(FileName.class, new FileNameCellRenderer()); final JLabel label = new JLabel("TESTING", SwingConstants.CENTER); label.setBackground(java.awt.Color.RED); label.setBounds(450, 100, 90, 20); label.setOpaque(true); label.setVisible(true); label.addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent arg0) { label.setBounds(arg0.getX(), arg0.getY(), 90, 20); } public void mouseMoved(MouseEvent arg0) { // TODO Auto-generated method stub } }); table.add(label); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(table); frame.setSize(800, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); } static class FileNameCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object v, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, v, isSelected, hasFocus, row, column); FileName fn = (FileName) v; setBorder(BorderFactory.createMatteBorder(0, 60, 0, 0, new java.awt.Color(143, 188, 143))); return this; } } static class FileName { public final Color color; public final String label; FileName(String l, Color c) { this.label = l; this.color = c; } public String toString() { return label; } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new TableTest(); } }); } } I just want to make the label follow the label follow my mouse and the label should be attached to the table.Is there an easy way than this.

    Read the article

  • Jdbc - Connect remote Mysql Database error

    - by Guilherme Ruiz
    I'm using JDBC to connect my program to a MySQL database. I already put the port number and yes, my database have permission to access. When i use localhost work perfectly, but when i try connect to a remote MySQL database, show this error on console. java.lang.ExceptionInInitializerError Caused by: java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:454) at java.lang.Integer.parseInt(Integer.java:527) at serial.BDArduino.<clinit>(BDArduino.java:25) Exception in thread "main" Java Result: 1 CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo) Thank you in Advance ! MAIN CODE /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package serial; import gnu.io.CommPort; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * * @author Ruiz */ public class BDArduino extends JFrame { static boolean connected = false; static int aux_sql8 = Integer.parseInt(Sql.getDBinfo("SELECT * FROM arduinoData WHERE id=1", "pin8")); static int aux_sql2 = Integer.parseInt(Sql.getDBinfo("SELECT * FROM arduinoData WHERE id=1", "pin2")); CommPort commPort = null; SerialPort serialPort = null; InputStream inputStream = null; static OutputStream outputStream = null; String comPortNum = "COM10"; int baudRate = 9600; int[] intArray = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; /** * Creates new form ArduinoTest */ public BDArduino() { //super("Arduino Test App"); initComponents(); } class Escrita extends Thread { private int i; public void run() { while (true) { System.out.println("Número :" + i++); } } } //public void actionPerformed(ActionEvent e) { // String arg = e.getActionCommand(); public static void writeData(int a) throws IOException { outputStream.write(a); } public void action(String arg) { System.out.println(arg); Object[] msg = {"Baud Rate: ", "9600", "COM Port #: ", "COM10"}; if (arg == "connect") { if (connected == false) { new BDArduino.ConnectionMaker().start(); } else { closeConnection(); } } if (arg == "disconnect") { serialPort.close(); closeConnection(); } if (arg == "p2") { System.out.print("Pin #2\n"); try { outputStream.write(intArray[0]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p3") { System.out.print("Pin #3\n"); try { outputStream.write(intArray[1]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p4") { System.out.print("Pin #4\n"); try { outputStream.write(intArray[2]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p5") { System.out.print("Pin #5\n"); try { outputStream.write(intArray[3]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p6") { System.out.print("Pin #6\n"); try { outputStream.write(intArray[4]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p7") { System.out.print("Pin #7\n"); try { outputStream.write(intArray[5]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p8") { System.out.print("Pin #8\n"); try { outputStream.write(intArray[6]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p9") { System.out.print("Pin #9\n"); try { outputStream.write(intArray[7]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p10") { System.out.print("Pin #10\n"); try { outputStream.write(intArray[8]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p11") { System.out.print("Pin #11\n"); try { outputStream.write(intArray[9]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p12") { System.out.print("Pin #12\n"); try { outputStream.write(intArray[10]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } if (arg == "p13") { System.out.print("Pin #12\n"); try { outputStream.write(intArray[11]); }//end try catch (IOException e12) { e12.printStackTrace(); System.exit(-1); }//end catch } } //******************************************************* //Arduino Connection *************************************** //****************************************************** void closeConnection() { try { outputStream.close(); } catch (Exception ex) { ex.printStackTrace(); String cantCloseConnectionMessage = "Can't Close Connection!"; JOptionPane.showMessageDialog(null, cantCloseConnectionMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } connected = false; System.out.print("\nDesconectado\n"); String disconnectedConnectionMessage = "Desconectado!"; JOptionPane.showMessageDialog(null, disconnectedConnectionMessage, "Desconectado", JOptionPane.INFORMATION_MESSAGE); }//end closeConnection() void connect() throws Exception { String portName = comPortNum; CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier.isCurrentlyOwned()) { System.out.println("Error: Port is currently in use"); String portInUseConnectionMessage = "Port is currently in use!\nTry Again Later..."; JOptionPane.showMessageDialog(null, portInUseConnectionMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } else { commPort = portIdentifier.open(this.getClass().getName(), 2000); if (commPort instanceof SerialPort) { serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); outputStream = serialPort.getOutputStream(); } else { System.out.println("Error: Only serial ports are handled "); String onlySerialConnectionMessage = "Serial Ports ONLY!"; JOptionPane.showMessageDialog(null, onlySerialConnectionMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } }//end else //wait some time try { Thread.sleep(300); } catch (InterruptedException ie) { } }//end connect //******************************************************* //*innerclasses****************************************** //******************************************************* public class ConnectionMaker extends Thread { public void run() { //try to make a connection try { connect(); } catch (Exception ex) { ex.printStackTrace(); System.out.print("ERROR: Cannot connect!"); String cantConnectConnectionMessage = "Cannot Connect!\nCheck the connection settings\nand/or your configuration\nand try again!"; JOptionPane.showMessageDialog(null, cantConnectConnectionMessage, "ERROR", JOptionPane.ERROR_MESSAGE); } //show status serialPort.notifyOnDataAvailable(true); connected = true; //send ack System.out.print("\nConnected\n"); String connectedConnectionMessage = "Conectado!"; JOptionPane.showMessageDialog(null, connectedConnectionMessage, "Conectado", JOptionPane.INFORMATION_MESSAGE); }//end run }//end ConnectionMaker /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { btnp2 = new javax.swing.JButton(); btncon = new javax.swing.JButton(); btndesc = new javax.swing.JButton(); btnp3 = new javax.swing.JButton(); btnp4 = new javax.swing.JButton(); btnp5 = new javax.swing.JButton(); btnp9 = new javax.swing.JButton(); btnp6 = new javax.swing.JButton(); btnp7 = new javax.swing.JButton(); btnp8 = new javax.swing.JButton(); btn13 = new javax.swing.JButton(); btnp10 = new javax.swing.JButton(); btnp11 = new javax.swing.JButton(); btnp12 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); btnp2.setText("2"); btnp2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp2MouseClicked(evt); } }); btncon.setText("Conectar"); btncon.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnconMouseClicked(evt); } }); btndesc.setText("Desconectar"); btndesc.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btndescMouseClicked(evt); } }); btnp3.setText("3"); btnp3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp3MouseClicked(evt); } }); btnp4.setText("4"); btnp4.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp4MouseClicked(evt); } }); btnp5.setText("5"); btnp5.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp5MouseClicked(evt); } }); btnp9.setText("9"); btnp9.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp9MouseClicked(evt); } }); btnp6.setText("6"); btnp6.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp6MouseClicked(evt); } }); btnp7.setText("7"); btnp7.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp7MouseClicked(evt); } }); btnp8.setText("8"); btnp8.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp8MouseClicked(evt); } }); btn13.setText("13"); btn13.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btn13MouseClicked(evt); } }); btnp10.setText("10"); btnp10.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp10MouseClicked(evt); } }); btnp11.setText("11"); btnp11.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp11MouseClicked(evt); } }); btnp12.setText("12"); btnp12.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { btnp12MouseClicked(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addComponent(btncon) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btndesc)) .addGroup(layout.createSequentialGroup() .addComponent(btnp6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp8, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(btnp10, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp11, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp12, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btn13, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(btnp2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnp5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btncon) .addComponent(btndesc)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnp2) .addComponent(btnp3) .addComponent(btnp4) .addComponent(btnp5)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnp6) .addComponent(btnp7) .addComponent(btnp8) .addComponent(btnp9)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnp10) .addComponent(btnp11) .addComponent(btnp12) .addComponent(btn13)) .addGap(22, 22, 22)) ); pack(); }// </editor-fold> private void btnp2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p2"); } private void btnconMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("connect"); } private void btndescMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("disconnect"); } private void btnp3MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p3"); } private void btnp4MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p4"); } private void btnp5MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here action("p5"); } private void btnp9MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p9"); } private void btnp6MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p6"); } private void btnp7MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p7"); } private void btnp8MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p8"); } private void btn13MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p13"); } private void btnp10MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p10"); } private void btnp11MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p11"); } private void btnp12MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: action("p12"); } /** * @param args the command line arguments */ public static void main(String args[]) throws IOException { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new BDArduino().setVisible(true); } }); //} while (true) { // int sql8 = Integer.parseInt(Sql.getDBinfo("SELECT * FROM arduinoData WHERE id=1", "pin8")); if (connected == true && sql8 != aux_sql8) { aux_sql8 = sql8; if(sql8 == 1){ writeData(2); }else{ writeData(3); } } int sql2 = Integer.parseInt(Sql.getDBinfo("SELECT * FROM arduinoData WHERE id=1", "pin2")); if (connected == true && sql2 != aux_sql2) { aux_sql2 = sql2; if(sql2 == 1){ writeData(4); }else{ writeData(5); } } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } // Variables declaration - do not modify private javax.swing.JButton btn13; private javax.swing.JButton btncon; private javax.swing.JButton btndesc; private javax.swing.JButton btnp10; private javax.swing.JButton btnp11; private javax.swing.JButton btnp12; private javax.swing.JButton btnp2; private javax.swing.JButton btnp3; private javax.swing.JButton btnp4; private javax.swing.JButton btnp5; private javax.swing.JButton btnp6; private javax.swing.JButton btnp7; private javax.swing.JButton btnp8; private javax.swing.JButton btnp9; // End of variables declaration }

    Read the article

  • Move multiple BufferedImage in Java2D?

    - by zo0mbie
    How can I mousedrag different BufferedImages in Java2D? For instance, if I have ten or more images, how can I move that images which my mouse is over? Now I'm importing an BufferedImage with BufferedImage img = new BufferdImage(new File("filename")); And I'm painting this with Graphics2D with public void paintComponent(Graphics g) { super.paintComponent(g); g2d = (Graphics2D) g; g2d.drawImage(img, x1, y1, null); g2d.drawImage(img2, x2, y2,null); } Everytime I'm moving on a image I'm repaint()-ing the entire screen. My mousemove class is as follows class MouseMotionHandler extends MouseMotionAdapter { @Override public void mouseDragged(MouseEvent e) { x1 = e.getX() - (img.getWidth() / 2); y1 = e.getY() - (img.getHeight() / 2); repaint(); } } With this method I'm able to "drag" one picture, but what to do when I will drag more individually?

    Read the article

  • Java MouseEvents not working

    - by billynomates
    This may be a stupid question, but I have to ask! I have the following code snippets that are supposed to run their corresponding methods when the user interacts with objects. For some reason, "foo" is never printed, but "bar" is. myJSpinner1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt() { System.out.println("foo"); //"foo" is not printed } }); myJSpinner2.addChangeListener(new java.awt.event.ChangeListener() { public void stateChanged(java.awt.event.ChangeEvent evt() { System.out.println("bar"); //"bar" is printed } }); I get no exceptions or stack trace. What am I missing in the MouseListener one? Thanks in advance.

    Read the article

  • Java Dragging an object from one area to another [on hold]

    - by user50369
    Hello I have a game where you drag bits of food around the screen. I want to be able to click on an ingredient and drag it to another part of the screen where I release the mouse. I am new to java so I do not really know how to do this please help me Here is me code. This is the class with the mouse listeners in it: public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { Comp.ml = true; // placing if (manager.title == true) { if (title.r.contains(Comp.mx, Comp.my)) { title.overview = true; } else if (title.r1.contains(Comp.mx, Comp.my)) { title.options = true; } else if (title.r2.contains(Comp.mx, Comp.my)) { System.exit(0); } } if (manager.option == true) { optionsMouse(e); } mouseinventory(e); } else if (e.getButton() == MouseEvent.BUTTON3) { Comp.mr = true; } } private void mouseinventory(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { } else if (e.getButton() == MouseEvent.BUTTON1) { } } @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { Comp.ml = false; } else if (e.getButton() == MouseEvent.BUTTON3) { Comp.mr = false; } } @Override public void mouseDragged(MouseEvent e) { for(int i = 0; i < overview.im.ing.toArray().length; i ++){ if(overview.im.ing.get(i).r.contains(Comp.mx,Comp.my)){ overview.im.ing.get(i).newx = Comp.mx; overview.im.ing.get(i).newy = Comp.my; overview.im.ing.get(i).dragged = true; }else{ overview.im.ing.get(i).dragged = false; } } } @Override public void mouseMoved(MouseEvent e) { Comp.mx = e.getX(); Comp.my = e.getY(); // System.out.println("" + Comp.my); } This is the class called ingredient public abstract class Ingrediant { public int x,y,id,lastx,lasty,newx,newy; public boolean removed = false,dragged = false; public int width; public int height; public Rectangle r = new Rectangle(x,y,width,height); public Ingrediant(){ r = new Rectangle(x,y,width,height); } public abstract void tick(); public abstract void render(Graphics g); } and this is a class which extends ingredient called hagleave public class HagLeave extends Ingrediant { private Image img; public HagLeave(int x, int y, int id) { this.x = x; this.y = y; this.newx = x; this.newy = y; this.id = id; width = 75; height = 75; r = new Rectangle(x,y,width,height); } public void tick() { r = new Rectangle(x,y,width,height); if(!dragged){ x = newx; y = newy; } } public void render(Graphics g) { ImageIcon i2 = new ImageIcon("res/ingrediants/hagleave.png"); img = i2.getImage(); g.drawImage(img, x, y, null); g.setColor(Color.red); g.drawRect(r.x, r.y, r.width, r.height); } } The arraylist is in a class called ingrediantManager: public class IngrediantsManager { public ArrayList<Ingrediant> ing = new ArrayList<Ingrediant>(); public IngrediantsManager(){ ing.add(new HagLeave(100,200,1)); ing.add(new PigHair(70,300,2)); ing.add(new GiantsToe(100,400,3)); } public void tick(){ for(int i = 0; i < ing.toArray().length; i ++){ ing.get(i).tick(); if(ing.get(i).removed){ ing.remove(i); i--; } } } public void render(Graphics g){ for(int i = 0; i < ing.toArray().length; i ++){ ing.get(i).render(g); } } }

    Read the article

  • C# Winforms Transparent Control allowing Clickthrough

    - by Erik Karlsson
    I have a problem, a bit related to: http://stackoverflow.com/questions/855826/c-winforms-transparent-control-allowing-clickthrough Contrary to him i would like to capture mouseevents on my program, while still retaining a "window" to whats behind my program. color.transparent doesnt work, and transparencykey just delivers mouse events to whatever is underneath. Using a panel with transparent backcolor or with a backcolor equal to transparencykey does not give the desired effect. Plz help me :)

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >