DnD and MouseMotionListener

Hi,
I am trying to move one panel(1) inside another one -
panel(2) with DnD. I think that everything works good, but only one problem. Can't change positioning (x,y) of panel(1) inside the panel(2). I am trying to use MouseMotionListener-mouseDragged(), but no help.
May be I am doing something wrong. How to coonect action of MouseMotionListener with DnD.
Here is my code.
class DNDPanel extends JPanel implements
DropTargetListener, MouseMotionListener {
int x;
int y;
public DNDPanel() {
super();
setBackground(Color.black);
setLayout(null);
add(new DraggablePanel()).setLocation(x, y);
addMouseMotionListener(this);
DropTarget dt = new DropTarget(this, this);
public void mouseDragged(MouseEvent e) {
x = e.getX();
y = e.getY(); // I think that problem hides somewhere here.
public void drop(DropTargetDropEvent dtde) {
if(isValidDragDrop(dtde.getDropAction(), dtde.getCurrentDataFlavors())) {
dtde.acceptDrop(dtde.getDropAction());
try {
Transferable xfer = dtde.getTransferable();
Object obj = xfer.getTransferData(MyFlavors.draggablePanelFlavor);
if(obj instanceof JComponent) {
add(new DraggablePanel()).setLocation(x, y);
// or here???
revalidate();
catch(Exception exc) {
System.err.println(exc);
exc.printStackTrace();
dtde.dropComplete(false);
else {dtde.rejectDrop();}
class DraggablePanel extends JPanel implements DragSourceListener,
DragGestureListener,
Transferable {
public DraggablePanel() {
super();
setBackground(Color.red);
setPreferredSize(new Dimension(100,100));
setBounds(0,0,100,100);
JButton button = new JButton("Beep");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
add(button);
DragSource ds = DragSource.getDefaultDragSource();
DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(
this, DnDConstants.ACTION_COPY_OR_MOVE, this);
Thank you. I really need HELP!
DM.

hi,
I dont completely understand your question, but if you are trying to get the coordinates of the component with respect to the parent panel, try methods from SwingUtilities, like converPoint,.....
Am not sure if that completely answers your question, but I had a similiar problem, ad then used this. Hope this helps!
Sri.

Similar Messages

  • Do I use DnD or MouseMotionListener ?

    I am wondering about the pros and cons of using dnd api vs. MouseListener/MouseMotionListener.
    I am experimenting with drag-and-drop using a simple app that allows components to be rearranged by dragging.
    Here is a description of desired test program behavior:
    For instance, if 5 rectangular panel components [A,B,C,D,E] are in a vertical row, and B is dragged onto D, then it is meant that B should be moved to before D, so the components will jump to new order [A,C,B,D,E]. (This is a simple test app for my learning, so I am ignoring that nothing can be moved to after E.)
    There is a visual indicator during the drag operation. In the above example where B, the dragsource, is dragged to D:
    - When drag begins, dragsource is on B, so indicator is a little notch arrow between A and B.
    - When drag moves onto C, notch arrow jumps to between B and C.
    - When drag moves onto D, notch arrow jumps to between C and D.
    - When drag released on D, components jump to rearrage themselves as user would expect from indicator arrow position.
    If drag goes outside the 5 components, the indicator arrow will stay where it was (i.e. it only updates at enter not exit)
    If mouse released outside the 5 components (or outside app window), the drag/move operation is aborted: the indicator goes away and no components move.
    The dragged-into component listener calls to parent panel to update the indicator arrow.
    The dropped-onto component listener calls to parent panel to reorder children.
    This description is pretty sound and simple in theory, but I am new to MouseMotionListener and java.awt.dnd. Which is better for this purpose?
    DND:
    - Can use listener to tell me about the enter, drop, and dragEnded events.
    - Since my app is not truly performing datatransfer, I would need to fool it with adding new action or dataflavor type (so not to mix up with other types of dragsources and targets).
    - I don't know how to discover the dragged component from a DropTargetDragEvent
    MouseMotion:
    - Would probably simplify everything and shorten my code.
    - Can use listener to tell me about the drag, enter, and release events.
    - Don't know how I would detect/handle the cases where mouse moved/released outside the application or outside the listening components.
    /Mel
    I will post the so-far-source if anyone is actually interested to see it.

    Hi,
    I know it kinda very late as its been a while since you posted your question, but i realized that is exavtly what i am trying to achieve in my project. Move labels within a panel among themselves. I was wondering if you might still have to code and if so, can you please send it to me?? my email id is [email protected]
    or if ou dont, and you do read this email, I would really appreciate it if you can let me know how?
    thanks very mucg,
    Sri.

  • Differentiate between DND and "Off Hook" status

    We have several directors and assistants on staff where it would be helpful to the assistant if their phone displayed and differentiated between off hook or dnd. Currently, both off hook status and dnd report the same indicator for the assistant.
    UC560 environment, ip phone 514G and 7965G
    Thanks for the help.
    Blessings,
    John J

    Hello John,
    You may try to use BLF.
    This is not supported with CCA.
    HTH,
    Alex
    *Please rate helpful posts

  • DnD with 2D scaled drop target

    This is more a strategy question than a code question - although code examples will be muchly appreciated.
    I have a model drawing component (ModelDrawingComponent extends JInternalFrame) that contains child components ( ie. ClassNode extends JInternalFrame). I need to be able to drop information into the child component (ClassNode). My description is greatly simplified leaving out several layers such as JScrollPanes, JPanels, etc.
    I have overridden the main JPanel's paintComponent() method to allow 2D drawing of lines and scale transformations of the entire model component resultant view. To provide mouse event interactions for this I use a GlassPane which transforms the mouse point to a scaled component adjusted point.
    My problem is implementing a DropTarget for Drag and Drop with 2D scaling - the mouse gestures reference points that are not adjusted for the scaling. So I need to transform the point geometry to determine whether the drag is over one of the ClassNode components.
    Does anyone have experience with DnD and 2D transformed targets they would like to share - ie. what is the best strategy for managing the transformation of the current drag point to the transformed / scaled point? I am assuming that the DropTarget should be the GlassPane. If so, how do you manage only showing a Drop OK Cursor when the cursor is over a child (ie. ClassNode) instead of over the GlassPane? What event listeners do I need to override to accomplish this?
    Thanks in advance.

    I don't know why your DropTarget implementation doesn't work, but an alternative, more high-level way of doing what you want is to use a TransferHandler:
            canvas.setTransferHandler(new TransferHandler() {
                @Override
                public boolean canImport(TransferSupport support) {
                    if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                        support.setDropAction(DnDConstants.ACTION_COPY);
                        return true;
                    return false;
                @Override
                public boolean importData(TransferSupport support) {
                    try {
                        String text = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
                        System.out.println(text);
                        return true;
                    catch (Exception ex) {
                        ex.printStackTrace();
                        return false;
            });

  • Drag and drop help (urgent)

    I need to write a program where I can drag and drop icons between and within a split pane. Any suggestion of what package I should look into? thanks

    Java provides two separate packages for drag and drop. java.awt.dnd and java.awt.datatransfer. These packages contain interfaces and classes for drag and drop. So pls go thru these classes.

  • Dnd - an email attachment onto a JTable

    Hello all - I really hope someone can help with the following : I have a Java swing application, which contains a JTable. The table holds data in rows which the users can persist (save as XML).
    One of our users asked to know if it is possible for him when he gets an email with a saved attachment to drag and attachment into the application rather than having to save it to file and then load it.
    I am new to Dnd. For the past 2-3 days I have been looking for examples for such functionality (searched for "dnd", "dnd email attachment", "dnd and outlook" and more and more. I used the examples to try and drag an attachment from my inbox onto the application and it seems the data flavor is text\rtf. Tried to read the attachment byte by byte , however had no success in successfully reading the attachment.
    I have come across reported bugs in the past on the site regarding dnd and outlook, but was wondering if anyone can possibly explain or point me in the direction of where I can read how to do this and\or find an example.
    If this has already been solved in the past and posted here, apologies in advance! Thanks

    You can save an attachment into an app which handles the attachment. Photos to the Photo App. Documents to Pages or Goodreader, etc.

  • Does JTree support multiple DnD?

    I'm working on an applet which displays a JTree tree, which has to support multiple DnD.
    i mean, user has to be capable of selecting several nodes at a time and drag all of them, dropping them into a target.
    Though i have asked about it, and somebody told me about it, the solution was with a JFrame, and all the examples which work and i've read, arre with JFrame.
    So i guess that maybe JTree does not support multiple DnD, and moreover, there is a website
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4165577
    in which someone says that, in fact, JTree does not support it. But it's and old page, so i want to know if at present, Jtree still has this debug.
    Thanks in advance!

    http://www.java-forum.org/de/viewtopic.php?p=139820#139820

  • DnD exception when Draging a component

    Hi,
    I am trying to implement a Drag n Drop feature for our application and always get the following exception, when drag a node from JTree and try to drop it another instance of the same JTree. this happens as soon as I call the startDrag method from the TransferHandler.
    java.awt.dnd.InvalidDnDOperationException: The operation requested cannot be performed by the DnD system since it is not in the appropriate state
         at sun.awt.dnd.SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(SunDropTargetContextPeer.java:105)
         at sun.awt.windows.WDragSourceContextPeer.startDrag(WDragSourceContextPeer.java:82)
         at java.awt.dnd.DragSource.startDrag(DragSource.java:260)
         at java.awt.dnd.DragSource.startDrag(DragSource.java:326)
    For some other reasons, I am limited to using JDK 1.3.1 on NT.
    I understand this a very uncommon problem but I get this exception every time.
    Anybody have any ideas as what is wrong or whats the workaround? Any help in this matter would be highly appreciated.
    Thanks,
    N.

    Check out the link shown below:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=296255
    If that doesn't answer your question, search the forum with "deudeu +dnd" and you'll find a lot of posts by this person on JTree DnD.
    ;o)
    V.V.

  • Cropping only righ and bottom

    Hi all,
    I'm, as many of the thread writers :), kind of new to java, but everyday i like this language more :) I'm trying to make an image crop with variables the user can input themselves, it works now but not completely. The image displays on screen but when the cropping starts only pixels from the right and from the bottom dissolve. I used the next code to accomplish this.
    public Image Crop()
              int iw = this.image.getWidth(null);
              int ih = this.image.getHeight(null);
              BufferedImage buffImg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB);
              Graphics2D CropIg = buffImg.createGraphics();
              buffImg = buffImg.getSubimage(1, 1, iw-HorCropVar, ih-VertCropVar);
              CropIg.drawImage(this.image, 0,0, this.label);
              setImage(Toolkit.getDefaultToolkit().createImage(buffImg.getSource()));
                            return Toolkit.getDefaultToolkit().createImage(buffImg.getSource());
           }Can anyone help me out with it? And does anyone know if i can (the way i use the crop method now) add a mouselistener to it, to decide the region to crop??
    Thanks all!!

    Well, when you do
    buffImg = buffImg.getSubimage(1, 1, iw-HorCropVar, ih-VertCropVar);you are only adjusting the width and height, as your x,y position is
    fixed at 1,1. So you only lose pixels on the right and bottom.
    To use the mouse to select the region, you'll probably want to use a
    MouseInputAdapter, which implements both MouseListener and
    MouseMotionListener. You can use the mousePressed() method to determine
    when the selection of an area has been started, the mouseDragged()
    method to determine the area being swept out, and the mouseReleased()
    method to determine when the selection has completed.
    In your mouseDragged() method, you'll probably want to provide some
    visual feedback that the selection is occurring; you can look [url http://java.sun.com/docs/books/tutorial/2d/index.html]here for
    some possibilities on how to do this.
    Good luck.
    : jay

  • Drag and drop in jscrollpane

    Hi all
    I have 2 different scrollpanes setup in 2 different panels. one of them contains a rdf graph structure which is generated by me using several other APIs. Now I want to drag and drop some of the nodes from one scroll pane to another. The nodes have features to be selected. I am totally new to java drag n drop. Can some one help me by providing some basic code to move stuff between scrollpanes??

    No, I do not (and cannot) use TransferHandler and such. The Drag and Drop is done manually by using MouseListener and MouseMotionListener.
    And also, my problem is not the drag and drop functionality. The problem is only the scrolling.

  • Drag and Drop doubt!

    Im a new bie to DND (and not Swing!). Is that a Drag source can be only one component always or I can have multiple component as the drag source?
    (im kind of doing win explorer where the DND should work on both the Tree and the Table).
    Thanks,
    ananth

    You can utilize the same Transferable from your tree and table. The DragSource is just a mechanism to initiate the DnD.
    -B

  • Tabs with 'swappable position'

    Hello,
    many applications that display tabs have this feature, i.e. Firefox or Total Commander:
    if you have say two tabs, and you drag the right one to the left side of the other one, they swap their positions. If you have more tabs, the dragged tab will move between the two tabs where it was dropped. I need this functionality in my app using JTabbedPane. Right now I have no idea how to do it. Any thoughts? :)

    ok I'm returning to this problem after a break.
    Since the drag'n'drop is happening in a single component - the JTabbedPane subclass, (those tab icons up there are no 'Components') the JTabbedPane instance listens for mouse events there,
    I'll use the mouseListener and mouseMotionListener api:
    public void mousePressed(java.awt.event.MouseEvent e) {
    denotes start of dnd gesture
    where I get the old tab index by TabbedPanePlus.this.indexAtLocation(e.getX(), e.getY()));
    public void mouseReleased(java.awt.event.MouseEvent e) {   
                        if(wasDragged)
    I get the new tab index the same way. To determine if drag is occuring I'll use
    public void mouseDragged(java.awt.event.MouseEvent e) {
    wasDragged = true;
    here I'd like to change the mouse icon so that it would indicate whether the target can be dropped in the current location (new index != old index and != -1)
    or can not be dropped (old index == new index, or is -1 - outside the area with tabs)
    So I guess my new question is: how do I change mouse icon?

  • MouseDragged Event donot Happen when startDrag method is called

    Hi
    I am developing a component (JLabel), which is DragSourceListener and MouseMotionListener at the same time.
    When DragGestureRecognize starts drag ,mouseDragged event don't happend
    Seems a Bug

    No thoughts from anyone on this? Seems to me, this means that true full-app window drag images aren't realistically possible with Swing when the OS doesn't natively support it, even if you want to try to code it yourself.
    It is an absolute must to always be notified of the mouse position so you'll know where to draw the ghosted drag image. The only way I can think of is to glass pane your whole JFrame but that won't work because then you lose the response of all your drop targets.
    Please take a second to share if you know of any listener at all that can be added so that an event is fired wherever the mouse is dragged within the JFrame- regardless of what component it is dragged over. Anything short of the glass pane approach since we can't have the glass pane catching all the events or the whole DnD system is foobar'ed.

  • How do I convert this Applet to launch from a JFrame instead??

       A simple program where the user can sketch curves and shapes in a
       variety of colors on a variety of background colors.  The user selects
       a drawing color form a pop-up menu at the top of the
       applet.  If the user clicks "Set Background", the background
       color is set to the current drawing color and the drawing
       area is filled with that color.  If the user clicks "Clear",
       the drawing area is just filled with the current background color.
       The user selects the shape to draw from another pop-up menu at the
       top of the applet.  The user can draw free-hand curves, straight
       lines, and one of six different types of shapes.
       The user's drawing is saved in an off-screen image, which is
       used to refresh the screen when repainting.  The picture is
       lost if the applet changes size, however.
       This file defines two classes, SimplePaint3,class, and
       class, SimplePaint3$Display.class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SimplePaint3 extends JApplet {
            // The main applet class simply sets up the applet.  Most of the
            // work is done in the Display class.
       JComboBox colorChoice, figureChoice;  // Pop-up menus, defined as instance
                                             // variables so that the Display
                                             // class can see them.
       public void init() {
          setBackground(Color.gray);
          getContentPane().setBackground(Color.gray);
          Display canvas = new Display();  // The drawing area.
          getContentPane().add(canvas,BorderLayout.CENTER);
          JPanel buttonBar = new JPanel();       // A panel to hold the buttons.
          buttonBar.setBackground(Color.gray);
          getContentPane().add(buttonBar, BorderLayout.SOUTH);
          JPanel choiceBar = new JPanel();       // A panel to hole the pop-up menus
          choiceBar.setBackground(Color.gray);
          getContentPane().add(choiceBar, BorderLayout.NORTH);
          JButton fill = new JButton("Set Background");  // The first button.
          fill.addActionListener(canvas);
          buttonBar.add(fill);
          JButton clear = new JButton("Clear");   // The second button.
          clear.addActionListener(canvas);
          buttonBar.add(clear);
          colorChoice = new JComboBox();  // The pop-up menu of colors.
          colorChoice.addItem("Black");
          colorChoice.addItem("Red");
          colorChoice.addItem("Green");
          colorChoice.addItem("Blue");
          colorChoice.addItem("Cyan");
          colorChoice.addItem("Magenta");
          colorChoice.addItem("Yellow");
          colorChoice.addItem("White");
          colorChoice.setBackground(Color.white);
          choiceBar.add(colorChoice);
          figureChoice = new JComboBox();  // The pop-up menu of shapes.
          figureChoice.addItem("Curve");
          figureChoice.addItem("Straight Line");
          figureChoice.addItem("Rectangle");
          figureChoice.addItem("Oval");
          figureChoice.addItem("RoundRect");
          figureChoice.addItem("Filled Rectangle");
          figureChoice.addItem("Filled Oval");
          figureChoice.addItem("Filled RoundRect");
          figureChoice.setBackground(Color.white);
          choiceBar.add(figureChoice);
       }  // end init()
       public Insets getInsets() {
              // Specify how wide a border to leave around the edges of the applet.
          return new Insets(3,3,3,3);
       private class Display extends JPanel
                  implements MouseListener, MouseMotionListener, ActionListener {
               // Nested class Display represents the drawing surface of the
               // applet.  It lets the user use the mouse to draw colored curves
               // and shapes.  The current color is specified by the pop-up menu
               // colorChoice.  The current shape is specified by another pop-up menu,
               // figureChoice.  (These are instance variables in the main class.)
               // The panel also listens for action events from buttons
               // named "Clear" and "Set Background".  The "Clear" button fills
               // the panel with the current background color.  The "Set Background"
               // button sets the background color to the current drawing color and
               // then clears.  These buttons are set up in the main class.
          private final static int
                      BLACK = 0,
                      RED = 1,            // Some constants to make
                      GREEN = 2,          // the code more readable.
                      BLUE = 3,           // These numbers code for
                      CYAN = 4,           // the different drawing colors.
                      MAGENTA = 5,
                      YELLOW = 6,
                      WHITE = 7;
          private final static int
                     CURVE = 0,
                     LINE = 1,
                     RECT = 2,               // Some constants that code
                     OVAL = 3,               // for the different types of
                     ROUNDRECT = 4,          // figure the program can draw.
                     FILLED_RECT = 5,
                     FILLED_OVAL = 6,
                     FILLED_ROUNDRECT = 7;
          /* Some variables used for backing up the contents of the panel. */
          Image OSI;  // The off-screen image (created in checkOSI()).
          int widthOfOSI, heightOfOSI;  // Current width and height of OSI.  These
                                        // are checked against the size of the applet,
                                        // to detect any change in the panel's size.
                                        // If the size has changed, a new OSI is created.
                                        // The picture in the off-screen image is lost
                                        // when that happens.
          /* The following variables are used when the user is sketching a
             curve while dragging a mouse. */
          private int mouseX, mouseY;   // The location of the mouse.
          private int prevX, prevY;     // The previous location of the mouse.
          private int startX, startY;   // The starting position of the mouse.
                                        // (Not used for drawing curves.)
          private boolean dragging;     // This is set to true when the user is drawing.
          private int figure;    // What type of figure is being drawn.  This is
                                 //    specified by the figureChoice menu.
          private Graphics dragGraphics;  // A graphics context for the off-screen image,
                                          // to be used while a drag is in progress.
          private Color dragColor;  // The color that is used for the figure that is
                                    // being drawn.
          Display() {
                 // Constructor.  When this component is first created, it is set to
                 // listen for mouse events and mouse motion events from
                 // itself.  The initial background color is white.
             addMouseListener(this);
             addMouseMotionListener(this);
             setBackground(Color.white);
          private void drawFigure(Graphics g, int shape, int x1, int y1, int x2, int y2) {
                // This method is called to do ALL drawing in this applet!
                // Draws a shape in the graphics context g.
                // The shape paramter tells what kind of shape to draw.  This
                // can be LINE, RECT, OVAL, ROUNTRECT, FILLED_RECT,
                // FILLED_OVAL, or FILLED_ROUNDRECT.  (Note that a CURVE is
                // drawn by drawing multiple LINES, so the shape parameter is
                // never equal to CURVE.)  For a LINE, a line is drawn from
                // the point (x1,y1) to (x2,y2).  For other shapes,  the
                // points (x1,y1) and (x2,y2) give two corners of the shape
                // (or of a rectangle that contains the shape).
             if (shape == LINE) {
                   // For a line, just draw the line between the two points.
                g.drawLine(x1,y1,x2,y2);
                return;
             int x, y;  // Top left corner of rectangle that contains the figure.
             int w, h;  // Width and height of rectangle that contains the figure.
             if (x1 >= x2) {  // x2 is left edge
                x = x2;
                w = x1 - x2;
             else {          // x1 is left edge
                x = x1;
                w = x2 - x1;
             if (y1 >= y2) {  // y2 is top edge
                y = y2;
                h = y1 - y2;
             else {          // y1 is top edge.
                y = y1;
                h = y2 - y1;
             switch (shape) {   // Draw the appropriate figure.
                case RECT:
                   g.drawRect(x, y, w, h);
                   break;
                case OVAL:
                   g.drawOval(x, y, w, h);
                   break;
                case ROUNDRECT:
                   g.drawRoundRect(x, y, w, h, 20, 20);
                   break;
                case FILLED_RECT:
                   g.fillRect(x, y, w, h);
                   break;
                case FILLED_OVAL:
                   g.fillOval(x, y, w, h);
                   break;
                case FILLED_ROUNDRECT:
                   g.fillRoundRect(x, y, w, h, 20, 20);
                   break;
          private void repaintRect(int x1, int y1, int x2, int y2) {
                // Call repaint on a rectangle that contains the points (x1,y1)
                // and (x2,y2).  (Add a 1-pixel border along right and bottom
                // edges to allow for the pen overhang when drawing a line.)
             int x, y;  // top left corner of rectangle that contains the figure
             int w, h;  // width and height of rectangle that contains the figure
             if (x2 >= x1) {  // x1 is left edge
                x = x1;
                w = x2 - x1;
             else {          // x2 is left edge
                x = x2;
                w = x1 - x2;
             if (y2 >= y1) {  // y1 is top edge
                y = y1;
                h = y2 - y1;
             else {          // y2 is top edge.
                y = y2;
                h = y1 - y2;
             repaint(x,y,w+1,h+1);
          private void checkOSI() {
               // This method is responsible for creating the off-screen image.
               // It should be called before using the OSI.  It will make a new OSI if
               // the size of the panel changes.
             if (OSI == null || widthOfOSI != getSize().width || heightOfOSI != getSize().height) {
                    // Create the OSI, or make a new one if panel size has changed.
                OSI = null;  // (If OSI already exists, this frees up the memory.)
                OSI = createImage(getSize().width, getSize().height);
                widthOfOSI = getSize().width;
                heightOfOSI = getSize().height;
                Graphics OSG = OSI.getGraphics();  // Graphics context for drawing to OSI.
                OSG.setColor(getBackground());
                OSG.fillRect(0, 0, widthOfOSI, heightOfOSI);
                OSG.dispose();
          public void paintComponent(Graphics g) {
               // Copy the off-screen image to the screen,
               // after checking to make sure it exists.  Then,
               // if a shape other than CURVE is being drawn,
               // draw it on top of the image from the OSI.
             checkOSI();
             g.drawImage(OSI, 0, 0, this);
             if (dragging && figure != CURVE) {
                g.setColor(dragColor);
                drawFigure(g,figure,startX,startY,mouseX,mouseY);
          public void actionPerformed(ActionEvent evt) {
                  // Respond when the user clicks on a button.  The
                  // command must be either "Clear" or "Set Background".
             String command = evt.getActionCommand();
             checkOSI();
             if (command.equals("Set Background")) {
                    // Set background color before clearing.
                    // Change the selected color so it is different
                    // from the background color.
                setBackground(getCurrentColor());
                if (colorChoice.getSelectedIndex() == BLACK)
                   colorChoice.setSelectedIndex(WHITE);
                else
                   colorChoice.setSelectedIndex(BLACK);
             Graphics g = OSI.getGraphics();
             g.setColor(getBackground());
             g.fillRect(0,0,getSize().width,getSize().height);
             g.dispose();
             repaint();
          private Color getCurrentColor() {
                   // Check the colorChoice menu to find the currently
                   // selected color, and return the appropriate color
                   // object.
             int currentColor = colorChoice.getSelectedIndex();
             switch (currentColor) {
                case BLACK:
                   return Color.black;
                case RED:
                   return Color.red;
                case GREEN:
                   return Color.green;
                case BLUE:
                   return Color.blue;
                case CYAN:
                   return Color.cyan;
                case MAGENTA:
                   return Color.magenta;
                case YELLOW:
                   return Color.yellow;
                default:
                   return Color.white;
          public void mousePressed(MouseEvent evt) {
                  // This is called when the user presses the mouse on the
                  // panel.  This begins a draw operation in which the user
                  // sketches a curve or draws a shape.  (Note that curves
                  // are handled differently from other shapes.  For CURVE,
                  // a new segment of the curve is drawn each time the user
                  // moves the mouse.  For the other shapes, a "rubber band
                  // cursor" is used.  That is, the figure is drawn between
                  // the starting point and the current mouse location.)
             if (dragging == true)  // Ignore mouse presses that occur
                 return;            //    when user is already drawing a curve.
                                    //    (This can happen if the user presses
                                    //    two mouse buttons at the same time.)
             prevX = startX = evt.getX();  // Save mouse coordinates.
             prevY = startY = evt.getY();
             figure = figureChoice.getSelectedIndex();
             dragColor = getCurrentColor();        
             dragGraphics = OSI.getGraphics();
             dragGraphics.setColor(dragColor);
             dragging = true;  // Start drawing.
          } // end mousePressed()
          public void mouseReleased(MouseEvent evt) {
                  // Called whenever the user releases the mouse button.
                  // If the user was drawing a shape, we make the shape
                  // permanent by drawing it to the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              dragging = false;
              mouseX = evt.getX();
              mouseY = evt.getY();
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs
                  drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                  repaintRect(prevX,prevY,mouseX,mouseY);
              else if (figure == LINE) {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX || mouseY != startY) {
                       // Draw the line only if it has non-zero length.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              else {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX && mouseY != startY) {
                       // Draw the shape only if both its height
                       // and width are both non-zero.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              dragGraphics.dispose();
              dragGraphics = null;
          public void mouseDragged(MouseEvent evt) {
                   // Called whenever the user moves the mouse while a mouse button
                   // is down.  If the user is drawing a curve, draw a segment of
                   // the curve on the off-screen image, and repaint the part
                   // of the panel that contains the new line segment.  Otherwise,
                   // just call repaint and let paintComponent() draw the shape on
                   // top of the picture in the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              mouseX = evt.getX();   // x-coordinate of mouse.
              mouseY = evt.getY();   // y=coordinate of mouse.
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs.
                 drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                 repaintRect(prevX,prevY,mouseX,mouseY);
              else {
                    // Repaint two rectangles:  The one that contains the previous
                    // version of the figure, and the one that will contain the
                    // new version.  The first repaint is necessary to restore
                    // the picture from the off-screen image in that rectangle.
                 repaintRect(startX,startY,prevX,prevY);
                 repaintRect(startX,startY,mouseX,mouseY);
              prevX = mouseX;  // Save coords for the next call to mouseDragged or mouseReleased.
              prevY = mouseY;
          } // end mouseDragged.
          public void mouseEntered(MouseEvent evt) { }   // Some empty routines.
          public void mouseExited(MouseEvent evt) { }    //    (Required by the MouseListener
          public void mouseClicked(MouseEvent evt) { }   //    and MouseMotionListener
          public void mouseMoved(MouseEvent evt) { }     //    interfaces).
       } // end nested class Display
    } // end class SimplePaint3

    Im quite the novice, how exactly do I go about doing that. What I did was to put both in diff files but I got errors saying that they cant find colorChoice, figureChoice in the Display class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Simple extends JFrame implements Display{
            // The main applet class simply sets up the applet.  Most of the
            // work is done in the Display class.
       JComboBox colorChoice, figureChoice;  // Pop-up menus, defined as instance
                                             // variables so that the Display
                                             // class can see them.
       public void init() {
          setBackground(Color.gray);
          getContentPane().setBackground(Color.gray);
          Display canvas = new Display();  // The drawing area.
          getContentPane().add(canvas,BorderLayout.CENTER);
          JPanel buttonBar = new JPanel();       // A panel to hold the buttons.
          buttonBar.setBackground(Color.gray);
          getContentPane().add(buttonBar, BorderLayout.SOUTH);
          JPanel choiceBar = new JPanel();       // A panel to hole the pop-up menus
          choiceBar.setBackground(Color.gray);
          getContentPane().add(choiceBar, BorderLayout.NORTH);
          JButton fill = new JButton("Set Background");  // The first button.
          fill.addActionListener(canvas);
          buttonBar.add(fill);
          JButton clear = new JButton("Clear");   // The second button.
          clear.addActionListener(canvas);
          buttonBar.add(clear);
          colorChoice = new JComboBox();  // The pop-up menu of colors.
          colorChoice.addItem("Black");
          colorChoice.addItem("Red");
          colorChoice.addItem("Green");
          colorChoice.addItem("Blue");
          colorChoice.addItem("Cyan");
          colorChoice.addItem("Magenta");
          colorChoice.addItem("Yellow");
          colorChoice.addItem("White");
          colorChoice.setBackground(Color.white);
          choiceBar.add(colorChoice);
          figureChoice = new JComboBox();  // The pop-up menu of shapes.
          figureChoice.addItem("Curve");
          figureChoice.addItem("Straight Line");
          figureChoice.addItem("Rectangle");
          figureChoice.addItem("Oval");
          figureChoice.addItem("RoundRect");
          figureChoice.addItem("Filled Rectangle");
          figureChoice.addItem("Filled Oval");
          figureChoice.addItem("Filled RoundRect");
          figureChoice.setBackground(Color.white);
          choiceBar.add(figureChoice);
       }  // end init()
    } // end class SimplePaint3
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Display extends JPanel
                  implements MouseListener, MouseMotionListener, ActionListener {
               // Nested class Display represents the drawing surface of the
               // applet.  It lets the user use the mouse to draw colored curves
               // and shapes.  The current color is specified by the pop-up menu
               // colorChoice.  The current shape is specified by another pop-up menu,
               // figureChoice.  (These are instance variables in the main class.)
               // The panel also listens for action events from buttons
               // named "Clear" and "Set Background".  The "Clear" button fills
               // the panel with the current background color.  The "Set Background"
               // button sets the background color to the current drawing color and
               // then clears.  These buttons are set up in the main class.
          private final static int
                      BLACK = 0,
                      RED = 1,            // Some constants to make
                      GREEN = 2,          // the code more readable.
                      BLUE = 3,           // These numbers code for
                      CYAN = 4,           // the different drawing colors.
                      MAGENTA = 5,
                      YELLOW = 6,
                      WHITE = 7;
          private final static int
                     CURVE = 0,
                     LINE = 1,
                     RECT = 2,               // Some constants that code
                     OVAL = 3,               // for the different types of
                     ROUNDRECT = 4,          // figure the program can draw.
                     FILLED_RECT = 5,
                     FILLED_OVAL = 6,
                     FILLED_ROUNDRECT = 7;
          /* Some variables used for backing up the contents of the panel. */
          Image OSI;  // The off-screen image (created in checkOSI()).
          int widthOfOSI, heightOfOSI;  // Current width and height of OSI.  These
                                        // are checked against the size of the applet,
                                        // to detect any change in the panel's size.
                                        // If the size has changed, a new OSI is created.
                                        // The picture in the off-screen image is lost
                                        // when that happens.
          /* The following variables are used when the user is sketching a
             curve while dragging a mouse. */
          private int mouseX, mouseY;   // The location of the mouse.
          private int prevX, prevY;     // The previous location of the mouse.
          private int startX, startY;   // The starting position of the mouse.
                                        // (Not used for drawing curves.)
          private boolean dragging;     // This is set to true when the user is drawing.
          private int figure;    // What type of figure is being drawn.  This is
                                 //    specified by the figureChoice menu.
          private Graphics dragGraphics;  // A graphics context for the off-screen image,
                                          // to be used while a drag is in progress.
          private Color dragColor;  // The color that is used for the figure that is
                                    // being drawn.
          Display() {
                 // Constructor.  When this component is first created, it is set to
                 // listen for mouse events and mouse motion events from
                 // itself.  The initial background color is white.
             addMouseListener(this);
             addMouseMotionListener(this);
             setBackground(Color.white);
          private void drawFigure(Graphics g, int shape, int x1, int y1, int x2, int y2) {
                // This method is called to do ALL drawing in this applet!
                // Draws a shape in the graphics context g.
                // The shape paramter tells what kind of shape to draw.  This
                // can be LINE, RECT, OVAL, ROUNTRECT, FILLED_RECT,
                // FILLED_OVAL, or FILLED_ROUNDRECT.  (Note that a CURVE is
                // drawn by drawing multiple LINES, so the shape parameter is
                // never equal to CURVE.)  For a LINE, a line is drawn from
                // the point (x1,y1) to (x2,y2).  For other shapes,  the
                // points (x1,y1) and (x2,y2) give two corners of the shape
                // (or of a rectangle that contains the shape).
             if (shape == LINE) {
                   // For a line, just draw the line between the two points.
                g.drawLine(x1,y1,x2,y2);
                return;
             int x, y;  // Top left corner of rectangle that contains the figure.
             int w, h;  // Width and height of rectangle that contains the figure.
             if (x1 >= x2) {  // x2 is left edge
                x = x2;
                w = x1 - x2;
             else {          // x1 is left edge
                x = x1;
                w = x2 - x1;
             if (y1 >= y2) {  // y2 is top edge
                y = y2;
                h = y1 - y2;
             else {          // y1 is top edge.
                y = y1;
                h = y2 - y1;
             switch (shape) {   // Draw the appropriate figure.
                case RECT:
                   g.drawRect(x, y, w, h);
                   break;
                case OVAL:
                   g.drawOval(x, y, w, h);
                   break;
                case ROUNDRECT:
                   g.drawRoundRect(x, y, w, h, 20, 20);
                   break;
                case FILLED_RECT:
                   g.fillRect(x, y, w, h);
                   break;
                case FILLED_OVAL:
                   g.fillOval(x, y, w, h);
                   break;
                case FILLED_ROUNDRECT:
                   g.fillRoundRect(x, y, w, h, 20, 20);
                   break;
          private void repaintRect(int x1, int y1, int x2, int y2) {
                // Call repaint on a rectangle that contains the points (x1,y1)
                // and (x2,y2).  (Add a 1-pixel border along right and bottom
                // edges to allow for the pen overhang when drawing a line.)
             int x, y;  // top left corner of rectangle that contains the figure
             int w, h;  // width and height of rectangle that contains the figure
             if (x2 >= x1) {  // x1 is left edge
                x = x1;
                w = x2 - x1;
             else {          // x2 is left edge
                x = x2;
                w = x1 - x2;
             if (y2 >= y1) {  // y1 is top edge
                y = y1;
                h = y2 - y1;
             else {          // y2 is top edge.
                y = y2;
                h = y1 - y2;
             repaint(x,y,w+1,h+1);
          private void checkOSI() {
               // This method is responsible for creating the off-screen image.
               // It should be called before using the OSI.  It will make a new OSI if
               // the size of the panel changes.
             if (OSI == null || widthOfOSI != getSize().width || heightOfOSI != getSize().height) {
                    // Create the OSI, or make a new one if panel size has changed.
                OSI = null;  // (If OSI already exists, this frees up the memory.)
                OSI = createImage(getSize().width, getSize().height);
                widthOfOSI = getSize().width;
                heightOfOSI = getSize().height;
                Graphics OSG = OSI.getGraphics();  // Graphics context for drawing to OSI.
                OSG.setColor(getBackground());
                OSG.fillRect(0, 0, widthOfOSI, heightOfOSI);
                OSG.dispose();
          public void paintComponent(Graphics g) {
               // Copy the off-screen image to the screen,
               // after checking to make sure it exists.  Then,
               // if a shape other than CURVE is being drawn,
               // draw it on top of the image from the OSI.
             checkOSI();
             g.drawImage(OSI, 0, 0, this);
             if (dragging && figure != CURVE) {
                g.setColor(dragColor);
                drawFigure(g,figure,startX,startY,mouseX,mouseY);
          public void actionPerformed(ActionEvent evt) {
                  // Respond when the user clicks on a button.  The
                  // command must be either "Clear" or "Set Background".
             String command = evt.getActionCommand();
             checkOSI();
             if (command.equals("Set Background")) {
                    // Set background color before clearing.
                    // Change the selected color so it is different
                    // from the background color.
                setBackground(getCurrentColor());
                if (colorChoice.getSelectedIndex() == BLACK)
                   colorChoice.setSelectedIndex(WHITE);
                else
                   colorChoice.setSelectedIndex(BLACK);
             Graphics g = OSI.getGraphics();
             g.setColor(getBackground());
             g.fillRect(0,0,getSize().width,getSize().height);
             g.dispose();
             repaint();
          private Color getCurrentColor() {
                   // Check the colorChoice menu to find the currently
                   // selected color, and return the appropriate color
                   // object.
             int currentColor = colorChoice.getSelectedIndex();
             switch (currentColor) {
                case BLACK:
                   return Color.black;
                case RED:
                   return Color.red;
                case GREEN:
                   return Color.green;
                case BLUE:
                   return Color.blue;
                case CYAN:
                   return Color.cyan;
                case MAGENTA:
                   return Color.magenta;
                case YELLOW:
                   return Color.yellow;
                default:
                   return Color.white;
          public void mousePressed(MouseEvent evt) {
                  // This is called when the user presses the mouse on the
                  // panel.  This begins a draw operation in which the user
                  // sketches a curve or draws a shape.  (Note that curves
                  // are handled differently from other shapes.  For CURVE,
                  // a new segment of the curve is drawn each time the user
                  // moves the mouse.  For the other shapes, a "rubber band
                  // cursor" is used.  That is, the figure is drawn between
                  // the starting point and the current mouse location.)
             if (dragging == true)  // Ignore mouse presses that occur
                 return;            //    when user is already drawing a curve.
                                    //    (This can happen if the user presses
                                    //    two mouse buttons at the same time.)
             prevX = startX = evt.getX();  // Save mouse coordinates.
             prevY = startY = evt.getY();
             figure = figureChoice.getSelectedIndex();
             dragColor = getCurrentColor();        
             dragGraphics = OSI.getGraphics();
             dragGraphics.setColor(dragColor);
             dragging = true;  // Start drawing.
          } // end mousePressed()
          public void mouseReleased(MouseEvent evt) {
                  // Called whenever the user releases the mouse button.
                  // If the user was drawing a shape, we make the shape
                  // permanent by drawing it to the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              dragging = false;
              mouseX = evt.getX();
              mouseY = evt.getY();
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs
                  drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                  repaintRect(prevX,prevY,mouseX,mouseY);
              else if (figure == LINE) {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX || mouseY != startY) {
                       // Draw the line only if it has non-zero length.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              else {
                 repaintRect(startX,startY,prevX,prevY);
                 if (mouseX != startX && mouseY != startY) {
                       // Draw the shape only if both its height
                       // and width are both non-zero.
                    drawFigure(dragGraphics,figure,startX,startY,mouseX,mouseY);
                    repaintRect(startX,startY,mouseX,mouseY);
              dragGraphics.dispose();
              dragGraphics = null;
          public void mouseDragged(MouseEvent evt) {
                   // Called whenever the user moves the mouse while a mouse button
                   // is down.  If the user is drawing a curve, draw a segment of
                   // the curve on the off-screen image, and repaint the part
                   // of the panel that contains the new line segment.  Otherwise,
                   // just call repaint and let paintComponent() draw the shape on
                   // top of the picture in the off-screen image.
              if (dragging == false)
                 return;  // Nothing to do because the user isn't drawing.
              mouseX = evt.getX();   // x-coordinate of mouse.
              mouseY = evt.getY();   // y=coordinate of mouse.
              if (figure == CURVE) {
                     // A CURVE is drawn as a series of LINEs.
                 drawFigure(dragGraphics,LINE,prevX,prevY,mouseX,mouseY);
                 repaintRect(prevX,prevY,mouseX,mouseY);
              else {
                    // Repaint two rectangles:  The one that contains the previous
                    // version of the figure, and the one that will contain the
                    // new version.  The first repaint is necessary to restore
                    // the picture from the off-screen image in that rectangle.
                 repaintRect(startX,startY,prevX,prevY);
                 repaintRect(startX,startY,mouseX,mouseY);
              prevX = mouseX;  // Save coords for the next call to mouseDragged or mouseReleased.
              prevY = mouseY;
          } // end mouseDragged.
          public void mouseEntered(MouseEvent evt) { }   // Some empty routines.
          public void mouseExited(MouseEvent evt) { }    //    (Required by the MouseListener
          public void mouseClicked(MouseEvent evt) { }   //    and MouseMotionListener
          public void mouseMoved(MouseEvent evt) { }     //    interfaces).
       } // end nested class Display

  • CUPC 8.6.1 with red cross which means no ringing

    Hello!
    In some way, we have the problem, that cupc change it's presence status from DND to available. The red presence indicators changes from red to green, but sometimes, the red cross on the handset icon didn't change, so I have the setup that I have a green presence indicator, but a red cross which means that I cannot hear incoming calls. If you change status back to DND and then back to available brings no success, also restarting the cupc client is unsuccessfull. I do not know when exactly this happens, a lot of users are telling me about this issue. I then have to manually onhook the DND status in device settings of the framework services client of the cupc endpoint to get it running again, that user hear the sound of incoming calls.
    Can someone help? Any idea? Someone aware of this issue/bug?
    We are using CUPC 8.6.1 and CUCM 8.6.2
    Thanks!

    No one an idea?

Maybe you are looking for

  • I had to re-download itunes; while I can see the music on my iPod, I cannot access or listen to it through itunes. any help? Thank you!

    I've done the transfer files thing... I've also authorized my computer to play the files.  I can see my list of songs, I just can't hear them through the computer.  The individual songs aren't click able. Thank you!!

  • Previous Available date in a column

    I Have a colum date and a amount. If select a date i need to fetch the previous avaialble amount In the below case WITH table_1 AS (select '700' amount,'01/01/2011' date1 from dual union all select '800' amount ,'12/23/2010' date1 from dual union all

  • Down loading photos.

    I generally use a 512MB SD card for photos. I routinely shot about 100 photos and then down load to iPhoto. I occasionally will save those photos on the SD card and the shot another 100 pics. When I down load the second batch of 100, iPhoto will ask

  • How to share a bind variable across multiple view objects?

    Hi, Can someone tell me if it's possible to share a bind variable among multiple view objects within an application module? My web page displays data from different VOs on different regions. But all data should be controlled by the same bind variable

  • Fiscal year change not yet made error message

    We have done all of the year-end tasks including AJRW and have been using asset reports since January. All of a sudden, today, we cannot get any asset reports for one of our 70+ company codes. Table ANLC looks like it has the appropriate entries for