Use of Vector in undo operation ?

Hello,
I am developing simple paint program. And want to use undo redo operation for drawing in drawing canvas. Actually I have done it with the help of Vector. But the problem is that it is not working properly. The first drawn shape is not removing with this operation and also the problem is that When i am using CTRL+Z for undoing last drawing. It is not removing last drawn shape with first undo operation. Let me know that what is the exact problem in my coding. I am not fully java programmer. So please tell me what to do for that. I want to draw n level of drawing on drawing canvas and also want to perform n level (first drawn shape) undo actions. And also want to know how to make redo button for same coding only use of Vector or ArrayList.
My code is here:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.util.*;
public class PaintUndo extends JFrame
     Display pan = new Display();
public PaintUndo()
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
          {     dispose();
               System.exit(0);}});
     getContentPane().add("Center",pan);
       setBounds(1,1,600,400);
     JMenuBar  menu = new JMenuBar();;
     JMenu     submenu;
     JMenuItem item, redo;
     submenu = new JMenu("Edit");     
     item = new JMenuItem("UnDo");
    item.setMnemonic(KeyEvent.VK_Z);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
     item.addActionListener((ActionListener)pan);
     submenu.add(item);   
     menu.add(submenu);
     getContentPane().add("North",menu);
     setVisible(true);
public class Display extends JComponent implements MouseMotionListener, MouseListener, ActionListener
     Vector   saves = new Vector();
     BufferedImage image = null;
     Graphics ig;
     Graphics pg;
     Point point;
    int x1=0;
    int y1=0;
public Display()
     setBackground(Color.pink);
     addMouseMotionListener(this);
    addMouseListener(this);
public void paintComponent(Graphics g)
     if (image == null)
          image = (BufferedImage) createImage(800,600);
          ig = image.createGraphics();
          ig.setColor(Color.white);
          ig.fillRect(0,0,800,600);
          ig.setColor(Color.blue);
          pg = getGraphics();
          pg.setColor(Color.blue);
     g.drawImage(image,0,0,this);
public void mouseDragged(MouseEvent e)
        int x2 = e.getX(); int y2 = e.getY();
            Graphics gr = image.getGraphics();
               gr.drawLine(x1, y1, x2, y2);
            repaint();
            x1 = x2; y1 = y2;
public void mouseMoved(MouseEvent e)
public void actionPerformed(ActionEvent a)
     if (a.getActionCommand().equals("UnDo") && saves.size() > 0)
          ig.drawImage((Image)saves.remove(saves.size()-1),0,0,null);
          repaint();
        public void mouseClicked(MouseEvent e) {
            System.out.println("mouse clicked....");
        public void mousePressed(MouseEvent e) {
            System.out.println("mouse pressed....");
            x1 = e.getX();
               y1 = e.getY();
        public void mouseReleased(MouseEvent e) {
            System.out.println("mouse released....");
           Image tmg = createImage(800,600);
          Graphics tg = tmg.getGraphics();
          tg.drawImage(image,0,0,null);
          saves.add(tmg);
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
public static void main (String[] args)
     new PaintUndo();
}This is complete code for undoing.
Any help will be appreciated.
Thanks in advance.
Manveer

The example code is set up for a protocol completely different than what you are doing, so you can't simply copy it and hope it works.  The example code expects that the other side will send a 4-byte header containing the number of data bytes that follow, then send the data.  The example code first reads that 4-byte header, casts it to an integer, and reads that number of bytes (the second Bluetooth Read).
When you run this with your device, the first read gets your 4 bytes - FF FF 22 33 - and converts that to an integer.  0xFFFF2233 is decimal 4294910515.  So you then try to read this huge number of bytes and you get an error - looks like error 1, an input parameter is invalid, because you can't read 4GB at once.  You can probably get your code working with a single Bluetooth Read, with a 1 second timeout (because you have a 1 second delay between packets).  You'll want to wire in some number of bytes to read that is at least the size of the largest packet you ever expect, but don't use a ridiculously huge number that generates an error.  LabVIEW will return as many bytes as are available when the timeout expires, even if it isn't as many as you asked to read (you might also get a timeout error, though, which you'll need to clear).  You can then do whatever you need to do with that data - search for FF FF, typecast anything after that to array of U16, display it. 
The output of the Bluetooth Read is a string, but it's not text - it's exactly the bytes that were sent.  The Y with the dots over it is the way ASCII 255 (0xFF) displays (at least in that font).  ASCII 34 (0x22) is ", and ASCII 51 (0x33) is the number 3.

Similar Messages

  • Redo and undo operations in lingo.

    I wanted to know how you people develop redo and undo method in a director project using lingo? Is there any standard function which keeps track of user interactions and provide the traditional method of redo and undo? Else should i develop a own logic? I'm new to lingo programming, so asking you experienced people how to go about it?

    Thanks, finally i was able to create undo operation in lingo! Lists are very helpfull in lingo, i got to know these just after coding undo action, i was able to create with counters and two lists.
    Here is just sample i did, not too great though!
    global clicklist, counter, undolist, undocounter
    on mouseUp me
    -- store values in variables for undo operation
      spriteName = undolist.getAt(undocounter - 2)
      spriteX = undolist.getAt(undocounter - 1)
      spriteY = undolist.getlast(undocounter) 
      sprite(spriteName).loc = point(spriteX, spriteY)
      undolist.deleteAt(undocounter)
      undolist.deleteAt(undocounter-1)
      undolist.deleteAt(undocounter-2)
      undocounter = undocounter - 3
    end

  • [Microsoft][SQL Server Native Client 11.0][SQL Server]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.  'Items' (OITM) (OITM)

    Dear Experts,
    i am getting the below error when i was giving * (Star) to view all the items in DB
    [Microsoft][SQL Server Native Client 11.0][SQL Server]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.  'Items' (OITM) (OITM)
    As i was searching individually it is working fine
    can any one help me how to find this..
    Regards,
    Meghanath.S

    Dear Nithi Anandham,
    i am not having any query while finding all the items in item master data i am giving find mode and in item code i was trying to type *(Star) and enter while typing enter the above issue i was facing..
    Regards,
    Meghanath

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • I am currently using Lightroom 5.6 and operating on a Mac with OSX Ver 10.9.5. I am receiving an error problem when doing the following -  I am exporting selected photos from a particular Catalogue saved on Drive 1 to a folder created on another Drive whe

    Hi, I am having a little trouble with exporting images to another drive and Catalogue and need some help if anyone can give me some advice
    I am currently using Lightroom 5.6 and operating on a Mac with OSX Ver 10.9.5.
    I am receiving an error problem when doing the following -
    I am exporting selected photos from a particular Catalogue saved on Drive 1 to a folder created on another Drive where a Lightroom Catalogue has been created. In this Catalogue I have arranged for the images once exported to be moved to a different folder - I used the Auto Import process under the File dialogue box.
    When processing the Export I receive an error message for each of the images being exported indicating the following -
    Heading Import Results
    Some import operations were not performed
    Could not move a file to requested location. (1)
    then a description of the image with file name
    Box Save As                                  Box  OK
    If I click the OK button to each image I can then go to the other Catalogue and all images are then transferred to the file as required.
    To click the OK button each time is time consuming, possibly I have missed an action or maybe you can advise an alternative method to save the time in actioning this process.
    Thanks if you can can help out.

    Thank You, but this is a gong show. Why is something that is so important to us all so very, very difficult to do?

  • How to create spark skins using fxg vector graphics&how to switch b/w spark skins at runtime/via XML

    Hi,
    I want to create a number of Spark Skins using some vector images that I have with me. I can obtain the vector images in FXG format-- but what I am looking for is some way to quickly create multiple skins for various UI elements like buttons, menus, radio button, checkboxes, etc -- not by converting the fxg->mxml but by using fxg files directly (after including them in the skins project in Flash Builder 4.6). Since I want to create many such skins (atleast 8-10) what is the fastest way of accomplishing this?
    Also, once I create multiple Spark Skins, how do I switch from one skin to another, in a running app? -- something like a template switcher, where the user viewing the flex app chooses a color, and the spark skin is immediately changed to the skin of that color (I would have already created the skin...). And can I store this skin template value in an XML? So that the end user can simply change this param in XML to change the design of the flex app?
    Arvind.

    Follow-up:
    Out of pure wishful thinking I decided I would just see what happened if I pretended 'exportFXG' was already a part of JSFL. Based on the signature of 'exportPNG', i tried the following lines:
      var success = fl.getDocumentDOM().exportFXG("file:///C:/mySymbol.fxg"); 
      fl.trace("success:"+success); // output: success:true 
    It worked! Fantastic! I'm not sure if exportFXG is considered still in "beta" and therefore intentionally excluded from the docs, or if it was just an oversight. But at least it gives us something to experiment with.

  • Recommended tutorials for using paths/vector art in Photoshop?

    Hi all!
    Can you recommend any good tutorials for using paths/vector art in Photoshop?
    Honestly, I've had a good look for even one - without much success.
    I Have lots of experience with paths/vector art in Illustrator, Fireworks and InDesign but I believe you really can do great things with them in Photoshop now for illustration work.
    i'm just baffled by it. I can fill and stroke and edit a vector shape in PS - but if I custom DRAW a vector path or shape, things get confusing!
    Hoping someone can point me in a helpful direction
    John

    John,
    I wouldn't claim to know everything there is to know, but I'm reasonably certain it hasn't changed.
    Are the 'shapes' just vector masks with a raster element inside?
    Yes. That's an accurate enough description.
    And if you apply a colour to a path that you've drawn - does it rasterise?
    It doesn't have to rasterize. If you see color, it's pixels.
    I was definitely of the impression that a lot more could be done in PS these days that might formerly have been done in ILLUSTRATOR.
    The shape/path tools in Photoshop have been enhanced and improved in recent years, but the product of their use still differs from Illustrator's true vector output.

  • I'm using mac with the newest operating system (snow leopard 10.6.7). since I've updated to Firefox 4 It doesn't display Hebrew fonts- I didn't have any problems with it before the upgrade and in safari I don't have this problem.

    Hello, I'm using Mac with the newest operating system (snow leopard 10.6.7). since I've updated to Firefox 4 It doesn't display Hebrew fonts… I didn't have any problems with it before the upgrade and in safari I have no problem with it. please help me- I don't like to use safari a my browser...

    elly903 wrote:
    Before commenting - I CANNOT install Mavericks because it'll mess up the versions of Filemaker Pro and Quicken that I use regularly...
    Quicken 2007 for Intel (Snow Leopard, Lion, Mt. Lion and Mavericks) for $15:
    http://quicken.intuit.com/personal-finance-software/quicken-2007-osx-lion.jsp
    It will input your Quicken PPC data file directly if it was Quicken 2005 through 2007.  If older you need Quicken 2006 or 2007 PPC first to convert your data file; and this update must be done BEFORE you upgrade to Mavericks:
    http://quicken.intuit.com/support/help/patching/quicken-2006-manual-updates--mac -/GEN82200.html
    Filemaker Pro PPC (in this case 7) running in Snow Leopard Server installed into Parallels for use in Lion, Mt. Lion and Mavericks:
                                  [click on image to enlarge]
    Snow Leopard Server: 1.800.MYAPPLE (1.800.692.7753) - Apple Part Number: MC588Z/A (telephone orders only)
    This solution allows you to run your Photoshop Elements in Mavericks concurrently with Filemaker Pro PPC.  Mavericks is a free download.

  • Undo operation on iPad..

    Has anyone noticed that the Undo operation on iPad is same as iPhone, which means you have to shake the device to undo? Shaking an iPhone is fine but very awkward for iPad give the size of the device. Needless to say, Shake to Undo is not intuitive for the first time user, even on iPhone. Very bizarre UI from Apple. I hope Apple will address this issue in the future release.

    There is a little-known gestural capability built into the keyboard on the iPad. If you simply touch and hold the "123" button, the number keyboard will come up immediately and you can just slide your finger to "Undo". When you lift your finger, the keyboard immediately returns to the alphabetic version. This sounds complicated, but it's not at all...and it's one quick, fluid motion. Like this:
    Touch "123", slide to "Undo", lift. There's no waiting for anything. Try it.

  • Using a vector graphic for a button

    Adobe Photoshop, Illustrator, and Encore CS5, everything is patched, Windows 7 64-bit
    I have been reading various posts, and either not seeing or not understanding something about using a vector graphic as a button on a menu.
    I drew a one-color shape in Illustrator, saved it as EPS and PNG and used it in a menu designed in Photoshop. When I preview it in Encore or burn a DVD, the graphic looks awful. And I'd like to use highlighting with it so it changes color when selected but that is another problem....
    To start the menu, I used the Photoshop preset NTSC DV Widescreen which has a pixel aspect ratio of 1.21. Then I added background graphics and so on. Each button is contained in a layer group named (+)PlayAll, etc. In each layer group is a text layer that doesn't have a prefix (e.g., Play All) and another layer with the vector or PNG named (=1)kv, which is the name of the EPS or PNG file.
    The behavior is fine. The graphic moves to indicate which menu item is selected, the text is constant, never changes.
    In Photoshop, the graphic looks fine but when I preview it in Encore it looks crappy and pixelated. What do I do?

    Part of the problem is I have no idea what some of these terms mean ... "2-bit indexed", ... The first one might mean an object that has one color,
    It is not the same as one color, and yes, it probably means more than any of us intend.  See  Encore help regarding button subpictures, in particular the part regarding using Photoshop to create button subpictures.
    The latter includes "(Technically, the subpicture overlay is a two‑bit indexed image.)," but you don't need to understand the technical meaning (they don't explain it anyway).  You do need to understand the liimitations they explain there,  For example, under "solid colors only," they say "Elements on these layers must use solid colors and sharp edges. Use one solid color per layer. Do not use gradients, feathering, or anti-aliasing on the subpicture layers. Color gradations are not possible in subpictures."
    "sub-picture highlight" ... the second one is probably made up.
    Heh, heh.  Searching that in Encore help (which I often find lacking) finds the page on Button Subpictures.  I agree that some of the terms, whether they are from the DVD specs or Sonic's applications (on which Encore is based), can make it difficult to look things up.
    "vector layer".... I searched Photoshop help for "vector layer" and got nothing. There is such a thing as a vector mask on a layer but I have no clue what a vector layer is.
    You're correct - vector mask.  Within a button group, the vector mask will be part of a layer, so I think of it as the button group "vector mask" layer.  That's part of why I pointed to using a library menu and editing in photoshop so you could compare what you have to what a template looks like.
    Please suggest which Encore library menu I can try. I opened a couple and couldn't figure out how they worked.
    In the General set, pick the Sunset menu.  Edit in Photoshop.  Expand the "(+) play movie" layer.  The "button vector mask" (the dark area) is in the layer called "button."  Notice that it does not have a (=1) or other indicator that it is a highlight.  In other words, it will just sit there, in whatever color is defined, and will not be a highlight.  If you put it in a layer that has one of the highlight indicators (the =1, =2 etc), it will then be subject to the subpicture highlight limitations.
    You might try your graphic in such a non-subpicture layer, and compare its appearance to putting it in a subpicture layer.
    Jeff Bellune's book (he's a moderator here) is still very applicable.  While some things have change, the basics haven't.
    But, hey, Jeff.  Why haven't you updated your book yet?  Inquiring minds want to know!

  • How to use a vector to navigate my database? please help me.. ty

    how to use a vector to navigate my database? please help me.. ty

    Quite unclear request�
    Can you provide more details?

  • Can't use a vector as dataprovider in a datagrid

    It appears that you can't use a vector as dataprovider in a datagrid. Am I correct?

    You are correct.
    A class must have a certain functionality to be able to work as a dataprovider for the flex components. Vector is not one of them unfortunately.
    You can replace your vector with an ArrayCollection or convert it to an ArrayCollection right before setting it as the dataprovider.
    I'm not aware of another way of doing this.

  • Using a vector in Java IDL...URGENT!

    How can I use a vector in Java IDL? I am trying to have a function return a vector.
    From what I have read, I should use a sequence. Therefore I tried the following code:
         struct ItemDB {
              long ItemNumber;
              long Quantity;
              double Price;
    typedef sequence <ItemDB> ItemList;
         interface ProductOperations{          
              ItemList listItems();
    When the equivalent Java is generated for the interface I am forced to return an array instead. This is what is generated:
    public interface ProductOperationsOperations
    ItemDB[] listProducts ();
    However, this is an array, which is bounded. I want to use an unbounded storage device.
    Can someone please please assist me. I appreciate it.
    Thanks
    RG

    This is already an unbounded sequence
    typedef sequence <ItemDB> ItemList;
    Checkout the read/write methods in the Helper class and you can see that the above list is unbounded.

  • How can I use a vector image to stretch with the backgrounds in Muse master pages?

    How can I use a vector image to stretch with the backgrounds in Muse master pages?

    Maybe there's a bug.  I think it's only showing it when it wants to because look:

  • Can someone tell me how I can use a Vector to access my class?

    I wrote a class that will need to be instantiated with unknown instances later. I decided to use a Vector to do this. However when I created the vector:
    <CODE>
    Vector user = new Vector(1,1);
    user.addElement(Users());
    user.elementAt(0).name="Test";
    </CODE>
    I'm really not sure how I can set this. The class is of course Users and I want to set user as the Vector but specify Users as the Object Type. Any help? By the way I heard Java has a dynamic array feature is this true? I heard you had to use Vectors for Java. Also how can I free up the memory when I'm done with the class?

    Suppose class User looks like this:
    public class User
      public String name;
    }then you could do:Vector users = new Vector(1,1);
    users.addElement(new User());
    ((User)users.elementAt(0)).name="Test";BTW - Java is NOT C++, you always need to use the new keyword for object creation!

Maybe you are looking for

  • Cant boot after shutdown

    Hi i was trying the unlocked sempron 140 and after i shutdown the pc i wasnt able to boot the next day. this has happened before but now after i try to reset the bios the system still fails to boot. all i get is black screen. and no matter how many t

  • Exporting text without the background?

    Hi all, I am working on an awards project using keynote and Livetype, I would like to export specific text livefonts without the generic background. For example, after exporting, being able to drag them onto a keynote slide without the black backgrou

  • Master data in query

    I matained master data by manual input,but in the query,I set a characteristic as a row,and several key figure as columns.The result are only key figures displayed,characteristic was empty.Why?Thanks for hints.

  • Weird Image Processor Behaviour

    The image processor has started acting really weird a couple of hours ago. I have been trying to figure the problem out since then, but to no avail. It all started when I tried to run batch processor from the Bridge with a really simple action that i

  • Switched fromgs3 to a 5s.now all my music appears twice in itunes and on phone. How to correct

    switched fromgs3 to a 5s.now all my music appears twice in itunes and on phone. How to correct