Link to home
Start Free TrialLog in
Avatar of Orlando15767
Orlando15767

asked on

implementing cut and paste

how can i implement cut and paste to the system clipboard in a simple painter program?
Avatar of expertmb
expertmb

Avatar of Orlando15767

ASKER

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)      

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;
            }
   }
ASKER CERTIFIED SOLUTION
Avatar of expertmb
expertmb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial