How to code 2 buttons with mouse events

I am trying to code two buttons, both with mouse down events, but perform different functions. When I coded the script, I received the following error message:
1021: Duplicate function definition.

use different function names.

Similar Messages

  • How make menu button with unrolling thumbnails in as 3.0??

    Hello
    I need help with doing a menu with unrolling and rolling up buttons with thumbnails;  now I have someting like that (attachments) this was made by as 2.0 but I need help with changing this on as 3.0.
    if samobody have some ideas how can I do this or somting similar using as 3.0 I will be grateful

    The only way to convert it to AS3 is to go thru it and replace the code as needed.  While some code may not have to change, quite a bit of it will.  Your best bet for getting thru it is to build it up from scratch one object at a time and get each coded as you go.  Otherwise you will be overwhelmed with error messages.  Here's a few pointers.
    All code is AS3 has to be placed on the timeline.  You cannot place code "on()" objects.  So each object needs an instance name.
    Any interaction or event handling such as mouse controls and file loading involve event listener/event handler pairs.  So you will want to start with looking into the addEventListener() method, which is pretty much used globally for any/all event processing.
    When it comes to loading external swf files, you want to use the Loader class.
    To determinine how to make the code work, I recommend using a practice file.  A file that you can implement one codig sequence in at a time just to determine what works.
    Converting this to AS3 will be a good exercise for you on the road to learning it.  When I wanted to start learning AS3 that's pretty much what I did, though with the sole purpose of the learning as my goal.  I took a fairly complicated menu design that I had created first in AS2, and then rebuilt it from the ground up using AS3.

  • Working with mouse events in Strobe's Widget classes

    I'm adding a caption on/off toggle button (classname CaptionButton) to the ControlBar class of Strobe Media Playback 1.5.1, and I'm having a difficult time understanding how mouse events are passed to child widgets of a ButtonWidget. In my CaptionButton class (which extends ButtonWidget), I add an instance of another widget, ListWidget, that extends Widget, and I show/hide this ListWidget with a mouse click event in the CaptionButton. The ListWidget is a composite class with a List component from Flash CS5, and the cell renderers in the List component do not respond to mouse events (over, selected, etc). How do I enable this type of mouse interaction within a Widget class? With the VolumeWidget, it looks like all mouse events are recreated and then controls are manually positioned according to the event properties, but this would be rather difficult with a component that has a virtual layout like List component. Any suggestions would be greatly appreciated.
    -Robert

    Ok, found that WidgetHint sets mouseChildren = false, etc. But I have a new problem---how do I stop autoHide timer while the user is interacting with a child widget? I was looking at the VolumeWidget that is used from the MuteButton widget, but I don't see how it stops the autoHide timer from enacting.

  • Trying to create a surface  with multiple images with mouse events

    novice programmer (for a applet program)
    hi trying to create a surface i.e jpanel, canvas, that allows multiple images to be created.
    Each object is to contain a image(icon) and a name associated with that particular image. Then each image+label has a mouse event that allows the item to be dragged around the screen.
    I have tried creating own class that contains a image and string but I having problems.
    I know i can create a labels with icons but having major problems adding mouse events to allow each newly created label object to moved by the users mouse?
    if any one has any tips of how to acheive this it would be much appreciated. Thanks in advance.
    fraser.

    This should set you on the right track:- import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        public class DragTwoSquares extends JApplet implements MouseListener, MouseMotionListener {  
           int x1, y1;   // Coords of top-left corner of the red square.
           int x2, y2;   // Coords of top-left corner of the blue square.
           /* Some variables used during dragging */
           boolean dragging;      // Set to true when a drag is in progress.
           boolean dragRedSquare; // True if red square is being dragged, false                              //    if blue square is being dragged.                            
           int offsetX, offsetY;  // Offset of mouse-click coordinates from
                                  //   top-left corner of the square that was                           //   clicked.
           JPanel drawSurface;    // This is the panel on which the actual
                                  // drawing is done.  It is used as the
                                  // content pane of the applet.  It actually                      // belongs to an anonymous class which is
                                  // defined in place in the init() method.
            public void init() {
                 // Initialize the applet by putting the squares in a
                 // starting position and creating the drawing surface
                 // and installing it as the content pane of the applet.
              x1 = 10;  // Set up initial positions of the squares.
              y1 = 10;
              x2 = 50;
              y2 = 10;
              drawSurface = new JPanel() {
                        // This anonymous inner class defines the drawing
                        // surface for the applet.
                    public void paintComponent(Graphics g) {
                           // Draw the two squares and a black frame
                           // around the panel.
                       super.paintComponent(g);  // Fill with background color.
                       g.setColor(Color.red);
                       g.fillRect(x1, y1, 30, 30);
                       g.setColor(Color.blue);
                       g.fillRect(x2, y2, 30, 30);
                       g.setColor(Color.black);
                       g.drawRect(0,0,getSize().width-1,getSize().height-1);
              drawSurface.setBackground(Color.white);
              drawSurface.addMouseListener(this);
              drawSurface.addMouseMotionListener(this);
              setContentPane(drawSurface);
           } // end init();
           public void mousePressed(MouseEvent evt) {
                  // Respond when the user presses the mouse on the panel.
                  // Check which square the user clicked, if any, and start
                  // dragging that square.
              if (dragging)  // Exit if a drag is already in progress.
                 return;           
              int x = evt.getX();  // Location where user clicked.
              int y = evt.getY();        
              if (x >= x2 && x < x2+30 && y >= y2 && y < y2+30) {
                     // It's the blue square (which should be checked first,
                     // since it's in front of the red square.)
                 dragging = true;
                 dragRedSquare = false;
                 offsetX = x - x2;  // Distance from corner of square to (x,y).
                 offsetY = y - y2;
              else if (x >= x1 && x < x1+30 && y >= y1 && y < y1+30) {
                     // It's the red square.
                 dragging = true;
                 dragRedSquare = true;
                 offsetX = x - x1;  // Distance from corner of square to (x,y).
                 offsetY = y - y1;
           public void mouseReleased(MouseEvent evt) {
                  // Dragging stops when user releases the mouse button.
               dragging = false;
           public void mouseDragged(MouseEvent evt) {
                   // Respond when the user drags the mouse.  If a square is
                   // not being dragged, then exit. Otherwise, change the position
                   // of the square that is being dragged to match the position
                   // of the mouse.  Note that the corner of the square is placed
                   // in the same position with respect to the mouse that it had
                   // when the user started dragging it.
               if (dragging == false)
                 return;
               int x = evt.getX();
               int y = evt.getY();
               if (dragRedSquare) {  // Move the red square.
                  x1 = x - offsetX;
                  y1 = y - offsetY;
               else {   // Move the blue square.
                  x2 = x - offsetX;
                  y2 = y - offsetY;
               drawSurface.repaint();
           public void mouseMoved(MouseEvent evt) { }
           public void mouseClicked(MouseEvent evt) { }
           public void mouseEntered(MouseEvent evt) { }
           public void mouseExited(MouseEvent evt) { }  
        } // end class

  • How to Create Buttons With some operation

    Hello friends How can create button so that when i click that button it should open another new window so that i can select some options in that new window and do some calculations.
    Kindly help me .
    byee

    Hi JN,
    I have created a Frame which has some checkboxes , a button and text field. when i check some checkboxes and press the Button (ie in my program Metrics level Button ) it should display the result as number of checkboxes that are checked divided by total number of chechboxes. ie if i check some 6 check boxes and press the Metrics level button it should display 6 divided by 12 ie 0.5 in the Result Textfield.
    I am sending the code i have written.
    Thanks in advance.
    public class Frame extends java.awt.Frame {
    /** Creates new form Frame */
    public Frame() {
    initComponents();
    setSize(800, 800);
    private void initComponents() {
    label1 = new java.awt.Label();
    checkbox1 = new java.awt.Checkbox();
    checkbox2 = new java.awt.Checkbox();
    checkbox3 = new java.awt.Checkbox();
    checkbox4 = new java.awt.Checkbox();
    checkbox5 = new java.awt.Checkbox();
    checkbox6 = new java.awt.Checkbox();
    checkbox7 = new java.awt.Checkbox();
    checkbox8 = new java.awt.Checkbox();
    checkbox9 = new java.awt.Checkbox();
    checkbox10 = new java.awt.Checkbox();
    checkbox11 = new java.awt.Checkbox();
    checkbox12 = new java.awt.Checkbox();
    button1 = new java.awt.Button();
    textField1 = new java.awt.TextField();
    setLayout(null);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    label1.setText("Select the Metrics below");
    add(label1);
    label1.setBounds(320, 20, 136, 20);
    checkbox1.setLabel("Architecture Metrics");
    add(checkbox1);
    checkbox1.setBounds(240, 80, 84, 20);
    checkbox2.setLabel("Runtime Metrics");
    add(checkbox2);
    checkbox2.setBounds(240, 200, 115, 20);
    checkbox3.setLabel("Documentation Metrics");
    add(checkbox3);
    checkbox3.setBounds(240, 320, 152, 20);
    checkbox4.setLabel("Size");
    add(checkbox4);
    checkbox4.setBounds(280, 110, 49, 20);
    checkbox5.setLabel("Structure");
    add(checkbox5);
    checkbox5.setBounds(280, 130, 75, 20);
    checkbox6.setLabel("Complexity");
    add(checkbox6);
    checkbox6.setBounds(280, 150, 86, 20);
    checkbox7.setLabel("Size");
    add(checkbox7);
    checkbox7.setBounds(290, 230, 49, 20);
    checkbox8.setLabel("Structure");
    add(checkbox8);
    checkbox8.setBounds(290, 250, 75, 20);
    checkbox9.setLabel("Complexity");
    add(checkbox9);
    checkbox9.setBounds(290, 270, 86, 20);
    checkbox10.setLabel("Size");
    add(checkbox10);
    checkbox10.setBounds(300, 350, 49, 20);
    checkbox11.setLabel("Structure");
    add(checkbox11);
    checkbox11.setBounds(300, 370, 75, 20);
    checkbox12.setLabel("Complexity");
    add(checkbox12);
    checkbox12.setBounds(300, 390, 86, 20);
    button1.setLabel("Metrics level");
    add(button1);
    button1.setBounds(290, 470, 83, 24);
    textField1.setText("Result");
    textField1.setName("Result");
    add(textField1);
    textField1.setBounds(400, 470, 60, 20);
    pack();
    public void actionPerformed(ActionEvent e) {
    ****** I think code should be added here for the button pressed event*******
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
    * @param args the command line arguments
    public static void main(String args[]) {
    new Frame().show();
    // Variables declaration - do not modify
    private java.awt.Button button1;
    private java.awt.Checkbox checkbox1;
    private java.awt.Checkbox checkbox10;
    private java.awt.Checkbox checkbox11;
    private java.awt.Checkbox checkbox12;
    private java.awt.Checkbox checkbox2;
    private java.awt.Checkbox checkbox3;
    private java.awt.Checkbox checkbox4;
    private java.awt.Checkbox checkbox5;
    private java.awt.Checkbox checkbox6;
    private java.awt.Checkbox checkbox7;
    private java.awt.Checkbox checkbox8;
    private java.awt.Checkbox checkbox9;
    private java.awt.Label label1;
    private java.awt.TextField textField1;
    // End of variables declaration
    this is the output when i execute the program

  • I recently bought Macbook pro  and i don't how to download Mp3 from the internet browser. it's easy on PC as you how to clickright button on mouse and then chosse save link or file. any idea how to do this?

    Hi.
    I recenly bought Macbook and as I am new to Apple word I don't know anything about the OS.
    I was trying to download Mp3 from the internet today and I just could not. when I am using PC I just click the right button and save the link or file.
    Please help me. Any idea how to download MP3?

    I had been downloading from that site for many times but from PC. When I use the left button on mouse it will take me to the internet player on my PC but if I use the right button I have to choose 'save file as' and then I save it.
    But on MACbook when I use two fingers on my trackpad there is only few options like and one of them is 'save link as' but not 'save file as'

  • How to control timleline with mouse x coordinates

    Hi,
    Does anyone know a good tutorial on how to create a movie with a sequence of pictures and controlling the timeline frames with mouse x-coordinates?
    Regards,
    MH

    basiclly,these swfs didn't work in mailtimeline movies.some of them were created by  flash3D .
    the point is some functions what created mouseX & DisplayMovies mapping like this
    function mouseMoveH(e){
              displayrender()
    function mapping(){
         return  fun(mouseX)
    function displayrender(){
        showFrame(mapping)

  • How can I disable any mouse event while is another is processing?

    Hi!
    I've a problem and I need some help.
    I'm downloading an image in the MouseAdapter's mouseClicked method. So I need to disable any other mouse events produced durring this download. These events can be removed from the queue or is there is any way to disable entering mouse events to the queue while another one is processing?
    If anyone can halp me, thanks a lot.

    Interesting situation. I would suggest that the downloading be done on another thread; long processes shouldn't be handled on the swing thread in most situations. Then to stop the mouse events you'd simply disable the component that has the mouse listener until the image has finished loading. That way these events will be processed and discarded while the image is loading.
    ie,
    public void mouseClicked(MouseEvent e)
      final Component source =  (Component)e.getSource;
      source.setEnabled(false); //stop further mouse events.
      new Thread()
          public void run()
             loadImage(); //should not return until image is loaded
             source.setEnabled(true);
    }Hope that helps. :)

  • How make menu button with unrolling and rolling up thumbnails

    Hello
    I need help with doing a menu with unrolling and rolling up buttons woth thumbnails;  now I have this made by as 2.0 but I need help with changing this on as 3.0. or if samobody have some ideas how can I do this using as 3.0 I will be grateful

    The only way to convert it to AS3 is to go thru it and replace the code as needed.  While some code may not have to change, quite a bit of it will.  Your best bet for getting thru it is to build it up from scratch one object at a time and get each coded as you go.  Otherwise you will be overwhelmed with error messages.  Here's a few pointers.
    All code is AS3 has to be placed on the timeline.  You cannot place code "on()" objects.  So each object needs an instance name.
    Any interaction or event handling such as mouse controls and file loading involve event listener/event handler pairs.  So you will want to start with looking into the addEventListener() method, which is pretty much used globally for any/all event processing.
    When it comes to loading external swf files, you want to use the Loader class.
    To determinine how to make the code work, I recommend using a practice file.  A file that you can implement one codig sequence in at a time just to determine what works.
    Converting this to AS3 will be a good exercise for you on the road to learning it.  When I wanted to start learning AS3 that's pretty much what I did, though with the sole purpose of the learning as my goal.  I took a fairly complicated menu design that I had created first in AS2, and then rebuilt it from the ground up using AS3.

  • How to add buttons with links to different pages in my flash document?

    Hi I created a template for my flash animation which is a simple content box and a scroll bar beside it.. Anyway at the top I also have 3 pages (they are currently just part of the png background image so they are not buttons of any sort).. My question is how can I make links to these different pages so when clicked in the flash animation they will just open normally like they would in like a website..
    I am a flash beginner so I'm not too technical with it... I don't know if I would have to create 3 seperate documents for my 3 pages or something else?
    Thanks!

    Do you expect the loaded SWF to load "into" the SWF that contains the buttons or are you expecting it to overwrite the existing SWF you're already in (similar to a web page)?
    Loading a SWF inside is pretty straight forward, as long as the SWF is on the same domain or the domain you're loading from has a crossdomain.xml policy allowing it and the SWF is set to publish with the networking sandbox:
    import flash.display.Loader;
    import flash.net.URLRequest; 
    import flash.events.Event;
    var myLoader:Loader = new Loader();
    // listen for completion
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleCompleteF);
    // usually add some IOErrorEvent or SecurityErrorEvent handlers here
    // button hook here
    myButtonInstanceName.addEventListener(MouseEvent.CLICK, loadPageF);
    function loadPageF(e:MouseEvent):void
         // try to load
         try
              myLoader.load(new URLRequest('another.swf'));
         catch (e:*)
              // catch any error, trace it to flash IDE for debugging
              trace("Error loading SWF: " + e);
    function handleCompleteF(e:Event):void
         // success, add to display list
         addChild(myLoader);
    Season to taste, like moving the position of the Loader object. The Loader will contain the SWF in the .content property (e.g. myLoader.content) and is a display object so you can just add it directly to the display list.
    If you add a second button you can re-use the myLoader to .load() a different SWF, just point it to a new function. You could re-use the same function but you'd need to detect the different buttons (possibly via the .name property). I presume you might want to do "different things" when different pages are loaded so I'm assuming you'd probably use a different function rather than make a huge reused branching function.
    More info on Loader with sample code here:
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.ht ml#includeExamplesSummary

  • How to highlight Icon with mouse click ?

    This program will open up a JFileChooser, Select one or more than one images from your computer. It will display them as Icons.
    I am trying to highlight any icon with mouseclick from the program below but I am not able to do it. Please help. Thanks in advance.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class IconIllustrate extends JFrame implements ActionListener, MouseListener
    JLabel[] lblimage = new JLabel[10];
    JPanel panAttachment = new JPanel();
    JPanel panButton = new JPanel();
    JButton bAdd = new JButton("Add");
    Component comp = null;
    Component c = null;
    boolean bolVal = false;
    public IconIllustrate()
    // TODO Auto-generated constructor stub
    panButton.add(bAdd);
    bAdd.addActionListener(this);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(panAttachment, BorderLayout.CENTER);
    this.getContentPane().add(panButton, BorderLayout.SOUTH);
    * @param args
    public static void main(String[] s)
    // TODO Auto-generated method stub
    IconIllustrate ii = new IconIllustrate();
    ii.setLocation(300, 200);
    ii.setTitle("Testing Highlight Icon");
    ii.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ii.setSize(400, 300);
    ii.setVisible(true);
    public void actionPerformed(ActionEvent ae)
    // TODO Auto-generated method stub
    if(ae.getSource().equals(bAdd))
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(true);
    int answer = chooser.showOpenDialog(this);
    File[] file = null;
    String[] fileName = new String[10];
    if(answer == JFileChooser.OPEN_DIALOG)
    file = chooser.getSelectedFiles();
    ImageIcon icon;
    try
    for(int i = 0; i < file.length; i++)
    icon = new ImageIcon(file.toString());
    ImageIcon thumbnailIcon = new ImageIcon(getScaledImage(icon.getImage(), 50, 40));
    lblimage = new JLabel[10];
    lblimage[i] = new JLabel();
    lblimage[i].addMouseListener(this);
    lblimage[i].setName("" + i);
    lblimage[i].setBorder(BorderFactory.createEmptyBorder());
    lblimage[i].setVerticalTextPosition(JLabel.BOTTOM);
    lblimage[i].setHorizontalTextPosition(JLabel.CENTER);
    lblimage[i].setHorizontalAlignment(JLabel.CENTER);
    lblimage[i].setIcon(thumbnailIcon);
    panAttachment.add(lblimage[i]);
    panAttachment.revalidate();
    catch(Exception ex )
    ex.printStackTrace();
    private Image getScaledImage(Image srcImg, int w, int h)
    BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = resizedImg.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.drawImage(srcImg, 0, 0, w, h, null);
    g2.dispose();
    return resizedImg;
    public void mouseClicked(MouseEvent me)
    // TODO Auto-generated method stub
    int clickCount = me.getClickCount();
    if(clickCount == 1 || clickCount == 2)
    Component comp = me.getComponent();
    Component c = comp.getComponentAt(me.getX(), me.getY());
    // c.setPreferredSize(new Dimension(100, 100));
    c.setBackground(Color.CYAN);
    System.out.println("clickCount");
    repaint();
    this.panAttachment.revalidate();
    public void mouseEntered(MouseEvent arg0)
    // TODO Auto-generated method stub
    public void mouseExited(MouseEvent arg0)
    // TODO Auto-generated method stub
    public void mousePressed(MouseEvent arg0)
    // TODO Auto-generated method stub
    public void mouseReleased(MouseEvent arg0)
    // TODO Auto-generated method stub

    Hi,
    phungho2000 wrote:
    Thank you for the Code. Now I am able to set the label border. I need to figure out how keep track of the last selected component so that I can reset the border.**g**
    No, you have still fundamental misunderstood how listeners are working. You add a listener to a component. From this time on, this listener is watching this component. It listens if something occurs with this component therefor it is competent. If so, then it will pay attention to this. So the listener always knows the components it is in charge of. There is no need for you to "keep track of the last selected component" because the listener is doing this for you already.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridLayout;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import javax.swing.*;
    public class FocusTesting extends JFrame implements FocusListener, MouseListener
      // There is no need for JLabel fields here.
      //JLabel labelA = new JLabel("Label A");
      //JLabel labelB = new JLabel("Label B");
      public FocusTesting()
        super("FocusTesting");
        JPanel paneFirst = new JPanel();
        JPanel paneSecond = new JPanel();
        paneSecond.setBackground(Color.gray);
        //use simply FlowLayout for testing this
        //paneFirst.setLayout(new BorderLayout());
        paneFirst.setBorder(BorderFactory.createBevelBorder(2));
        // pane.setBackground(Color.blue);
        JLabel labelA = new JLabel("Label A");
        // give the labelA a name only to show you, that the listener knows about the compontent it ist added to
        labelA.setName(labelA.getText());
        labelA.addMouseListener(this);
        labelA.addFocusListener(this);
        labelA.setFocusable(true);
        JLabel labelB = new JLabel("Label B");
        // give the labelB a name only to show you, that the listener knows about the compontent it ist added to
        labelB.setName(labelB.getText());
        labelB.addMouseListener(this);
        labelB.addFocusListener(this);
        labelB.setFocusable(true);
        paneFirst.add(labelA);
        paneFirst.add(labelB);
        this.getContentPane().setLayout(new GridLayout(2, 1));
        this.getContentPane().add(paneFirst);
        this.getContentPane().add(paneSecond);
      public static void main(String[] s)
        //separate the initial thread form the event dispatch thread
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            FocusTesting ft = new FocusTesting();
            ft.setLocation(300, 200);
            ft.setSize(300, 200);
            ft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            ft.setVisible(true);
      public void focusGained(FocusEvent fe)
        // TODO Auto-generated method stub
        JComponent jcomp = (JComponent)fe.getComponent();
        jcomp.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
        System.out.println("focusGained " + jcomp.getName());
      public void focusLost(FocusEvent fe) 
        // TODO Auto-generated method stub
        JComponent jcomp = (JComponent)fe.getComponent();
        jcomp.setBorder(BorderFactory.createEmptyBorder());
        System.out.println("focusLost " + jcomp.getName());
      public void mouseClicked(MouseEvent me)
        Component comp = me.getComponent();
        comp.requestFocusInWindow();
        System.out.println("mouseClicked " + comp.getName());
      public void mouseEntered(MouseEvent arg0)
        // TODO Auto-generated method stub
      public void mouseExited(MouseEvent arg0)
        // TODO Auto-generated method stub
      public void mousePressed(MouseEvent arg0)
        // TODO Auto-generated method stub
      public void mouseReleased(MouseEvent arg0)
        // TODO Auto-generated method stub
    } You also should read again the Java Tutorial about Concurrency in Swing. Especially why and how to separate the initial thread form the event dispatch thread. [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html]
    Also have a look on [http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html], especially [http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#focusable] for why use the MouseListener too.
    And if you have understood that all, then you may think about in what way it would be much easier to use JButton's instead of JLabel's for your clickable and focusable thumbnails.
    best regards
    Axel

  • JSwing code errors with mouse over

    Basically this code is set up to change the background of Jtextfield when the Jtextfield contains the cursor. But, it seems that i have issues because it only works if the cursor is in the upper corner of my window frame. I think it has something to do with my hiearchy, but am unsure how to fix.. help will greatly be apreciated.
    its in two seperate class files by the way.
    import javax.swing.*;
    public class yahtzeeTest
          public static void main(String[] args)
         tes menu=new yahtzee();
         JFrame appFrame=new JFrame();
         appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         appFrame.setContentPane(menu);
         appFrame.pack();
         appFrame.show();     
    // seperate file
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class testeld extends JPanel implements ActionListener, MouseMotionListener
         private static int      panelW = 400,
                                  panelH=350;
         JTextField tf[]=new JTextField[2];
           Point cursor;
         public testeld()
         setPreferredSize(new Dimension(panelW, panelH));
         setLayout(null);
         addMouseMotionListener(this);
         setBackground(Color.red);
              for(int i=0; i<2;i++)
              tf=new JTextField( "",i);
              tf[i].setBounds(200, (30+(26*i)), 30,20);
              tf[i].setEnabled(false);
              add(tf[i]);
              tf[i].addActionListener(this);     
         public void actionPerformed(ActionEvent ae)
              Object src = ae.getSource();
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2=(Graphics2D)g;
         public void mouseMoved(MouseEvent me)
         int x=me.getX();
         int y=me.getY();
         this.cursor =new Point(x, y);     
         for(int i=0; i<tf.length; i++)
              if(tf[i].contains(cursor))
                   tf[i].setBackground(Color.yellow);
              else
                   tf[i].setBackground(Color.white);
         public void mouseDragged(MouseEvent me){}

    1) Swing related questions should be posted in the Swing forum.
    2) I would use the mouseEntered, mouseExited events to set/reset the background.
    3) Why did you overried paintComponent()

  • How do you map a mouse events coordinate​s to the coordinate​s of a chart or graph?

    I'm using LabView 6.1 on Win XP Pro. I'm trying to highlight points on a graph picked (by using a mouse click) by a user. The mouse click event returns x,y in pixels relative to the upper left corner. I know the upper left corner of my control. I also know the width and height of the plotting area within the control, but I don't know the position of the plotting area within the control. Without that piece of info, I can't do the mapping.

    Hi,
    You May Want to do this a bit Differently but achieve the same Goal i.e. the user Picks Points on a Graph and you highlight these points and Draw A graph or impart some other functionality.
    Here is an idea -
    1. Let the User Position the Cursor on the Point they want. To aid the user you can make the cursor legend visible which shows the X and Y Axis values for the cursor. To accuartely Position the User can use the the 4 Buttons that are a part of the Cursor Legend.
    2. Put a Button next to the graph saying "Select this Point"
    3. After Positioning the Cursor when the user Clicks this Button you use the "Cursor Position" Property of the graph to extract the value of the cursor.
    4. Next you may want to add this Point to Cluster Array which displays
    the Points on the Graph. If this Array is Empty and you add this one Element to the Graph then this Point will be Visible. The User may now reposition to another Point and Repeat the Process.
    5. To aid the user you may want to Provide " Delete last Point" and "Clear All" Buttons. The Functionality is to Delete Last Element in array or Clear all Elements in the Array.
    The Structure of this whole routine probably is Event Structure(to trap Button Clicks "Select", "Delete" etc) Inside a Case Structure (State Machine to Perform the Operations User Clicked) All Inside a While Loop.
    This is a Short Description of how this Functionality can be Built. To Automatically Extract Cursor position from the Graph and then try to Map it to Coordiante Axis For a Point is More Involved and a Little Convoluted.
    Why not keep it simple? IF anything is unclear, I will be glad to explain or post an example (Only if time permits!!)
    Good Luck
    Mache
    Good Luck!
    Mache

  • How to Code SWFObject with Alternate Content

    I've read umpteen tutorials and articles on embedding Flash
    with alternate content, and they're all too different, confusing,
    and unsuccessful. All I want to do is insert a JPEG to replace my
    Flash movie on non-Flash browsers but have no idea how or where to
    code it. I don't want to get into xml or div IDs (if I don't have
    to)... just a simple-as-possible, idiot-proof solution for a
    beginner like myself.
    Here is my Flash object...
    <td width="400" height="240">
    <object
    classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
    http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
    height="240" width="400">
    <param name="movie" value="images/flashintro.swf" />
    <param name="quality" value="best" />
    <param name="play" value="true" />
    <embed height="240" pluginspage="
    http://www.macromedia.com/go/getflashplayer"
    src="images/flashintro.swf" type="application/x-shockwave-flash"
    width="400" quality="best" play="true"></embed>
    </object>
    </td>
    Thanks.

    docmentation:
    http://code.google.com/p/swfobject/
    AIR app that generates it for you:
    http://code.google.com/p/swfobject/downloads/list
    The body code will look like something like this:
    <div id="flashContent">
    <center><p>Please update to the latest version
    of <a href="
    http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
    target="_blank" title="Flash Player">FLASH</a>, and enable
    <a href="
    http://gsaauctions.gov/brow_details/IE6instr.htm"
    title="Enable Javascript"
    target="_blank">JAVASCRIPT</a><br /> or view site as
    <a
    href="index2.php">HTML</a></p></center></div>
    <script type="text/javascript">
    // <![CDATA[var so = new SWFObject("flash.swf", "mymovie",
    "950", "600", "8", "#FFFFFF");
    so.write("flashContent");
    </script>

  • How create a button with a certain size??

    hi
    the button I create need to have a image icon, and the size of it should remain the same no matter what happen to the size of the frame or panel. by the way, how do I calculate the size of a image I need to set to a button at run time? thank you.

    first copy and run this code, may sure u r connected to internet..
    import javax.swing.*;
    import java.awt.*;
    import java.net.*;
    public class JButtonExample extends JFrame {
      JPanel jPanel1 = new JPanel();
      JButton jButton1 = new JButton();
      public JButtonExample() {
        try {
           jButton1.setMargin(new Insets(0, 0, 0, 0));
           URL r = new URL("http://developer.java.sun.com/images/javalogo52x88.gif");
           jButton1.setIcon(new ImageIcon(r));
           jPanel1.add(jButton1);
           this.getContentPane().add(jPanel1, BorderLayout.NORTH);
        catch(Exception e) {
          e.printStackTrace();
        pack();
        show();
      public static void main(String[] args) {
        JButtonExample JButtonExample1 = new JButtonExample();
    }good luck

Maybe you are looking for

  • Ensemble with L8

    Good evening all.. My current setup is a MIC into SSL alpha channel then from the SSL to the Ensemble channel 1 in. I am finding I'm getting a better quality with the MIC is connected directly to the Ensemble, so my question is: Is there a way to dis

  • Open File - Security Warning - minor annoyance

    Ever since I installed SQL Developer 1.5.5 I get an Open File - Security Warning. The publisher could not be verified. I can still run the software, but it is something I haven't seen with SQL Developer before and I have been running it since 1.2 Any

  • EAC loses connect to Mailbox Database Server

    I am having a weird issue with EAC.  We have 2 mailbox databases but only 1 is used as the main production, on a separate server.  The other database was the first one in the implementation.  It hosts system attendant and a couple of administrative a

  • Help please, class starts yesterday, and I need to know if Lr 5.6 64 bit can be reset to "like new" or default. Like it's never been used!

      Hello, I need to know if it is possible to reset Lr 5.6 64 bit to default or like it was when I first downloaded it. Clean/empty/fresh. As an online college student, and using Lr for a while now, without being "Detailed Oriented," and "Methodic", I

  • Method call before visual web jsf page loads

    Hi All..... I have written a method in a java class that accesses the mysql backend db to check if a process is still running. If the process is still running, a JOptionPane is produced informing the user of this and offers an <ok> option(to check th