Solved

implementing cut and paste

Posted on 2004-09-30
4
210 Views
Last Modified: 2010-03-31
how can i implement cut and paste to the system clipboard in a simple painter program?
0
Comment
Question by:Orlando15767
  • 2
4 Comments
 
LVL 6

Expert Comment

by:expertmb
ID: 12196872
0
 
LVL 1

Author Comment

by:Orlando15767
ID: 12197086
I tried putting the methods into the cut method created from implementing cutable and I was recieving errors at line marked **

      public void cut(ActionEvent evt) {
**          public static Image getClipboard() {
              Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
          
              try {
                  if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                      Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
                      return text;
                  }
              } catch (UnsupportedFlavorException e) {
              } catch (IOException e) {
              }
              return null;
          }
}

      Syntax error, insert ";" to complete BlockStatements                  
                Syntax error on token(s), misplaced construct(s)      

0
 
LVL 18

Expert Comment

by:armoghan
ID: 12197442
Is the above mentioned  code being used in program..
As it seems to have a method in a method

As you are missing some } somewhere
The below mentioend method is OK

       public static Image getClipboard() {
                Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
   
                try {
                    if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                        Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
                        return text;
                    }
                } catch (UnsupportedFlavorException e) {
                } catch (IOException e) {
                }
                return null;
            }
   }
0
 
LVL 6

Accepted Solution

by:
expertmb earned 125 total points
ID: 12197543
try this
   public void cut(ActionEvent evt) {
 getClipboard() ;
}

         public static Image getClipboard() {
             Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
         
             try {
                 if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                     Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
                     return text;
                 }
             } catch (UnsupportedFlavorException e) {
             } catch (IOException e) {
             }
             return null;
         }
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now