Boa Tarde Luiz, Se voce quiser um em exemplo em run-time e que use serializacao, aqui vai um:
//DRAGFRAME import java.awt.*; import java.awt.dnd.*; import java.awt.datatransfer.*; import javax.swing.*; import java.io.*; public class DragFrame extends JFrame implements DragSourceListener, DragGestureListener { private List lFiles; private JTextField NButton; private JButton SButton, LButton, RButton; private JPanel myDragObject; public DragFrame(){ setLocation(0,0); setSize(400,300); setTitle("Drag Frame"); myDragObject = new JPanel(new BorderLayout()); setContentPane(myDragObject); /* NButton = new JTextField("NORTH"); myDragObject.add(NButton,BorderLayout.NORTH); SButton = new JButton("NORTH"); myDragObject.add(SButton,BorderLayout.SOUTH); RButton = new JButton("NORTH"); myDragObject.add(RButton, BorderLayout.WEST); LButton = new JButton("NORTH"); myDragObject.add(LButton, BorderLayout.EAST); */ File[] files = new File("C:\\").listFiles(); lFiles = new List(); for (int x=0;x < files.length; x++) lFiles.add(files[x].getName()); Font f = new Font("Dialog", Font.ROMAN_BASELINE, 10); lFiles.setFont(f); myDragObject.add(lFiles); setVisible(true); DragSource d = DragSource.getDefaultDragSource(); d.createDefaultDragGestureRecognizer(lFiles,DnDConstants.ACTION_MOVE,this); /* d.createDefaultDragGestureRecognizer(SButton ,DnDConstants.ACTION_MOVE,this); d.createDefaultDragGestureRecognizer(RButton ,DnDConstants.ACTION_MOVE,this); d.createDefaultDragGestureRecognizer(LButton ,DnDConstants.ACTION_MOVE,this); */ } //DragSourceListener public void dragEnter(DragSourceDragEvent dsde){} public void dragOver(DragSourceDragEvent dsde){} public void dropActionChanged(DragSourceDragEvent dsde){} public void dragExit(DragSourceEvent dse){} public void dragDropEnd(DragSourceDropEvent dsde){ if (dsde.getDropSuccess()){ //myDragObject.remove(dsde. ); //lFiles.remove(lFiles.getSelectedIndex()); System.out.println("Sucess!!"); } } //DragGestureListener public void dragGestureRecognized(DragGestureEvent dge){ try{ ByteArrayOutputStream by = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(by); oOut.writeObject(lFiles); byte[] arrayBytes = by.toByteArray(); oOut.close(); StringSelection selection = new StringSelection(new String(arrayBytes)); dge.startDrag(null,selection, this); System.out.println("Drag start"); }catch(Exception __e){ System.out.println(__e); } } public static void main(String[] args){ new DragFrame(); new DropFrame(); } } /* Back ByteArrayOutputStream by = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(by); oOut.writeObject(lFiles); byte[] arrayBytes = by.toByteArray(); oOut.close(); StringSelection selection = new StringSelection(new String(arrayBytes)); dge.startDrag(null,selection, this); System.out.println("Drag start"); */ // END DRAGFRAME // DROPFRAME import java.awt.*; import java.awt.dnd.*; import java.awt.datatransfer.*; import javax.swing.*; import java.io.*; public class DropFrame extends JFrame implements DropTargetListener{ private List lFiles; public DropFrame(){ setSize(400,300); setTitle("Drop Frame"); getContentPane().setLayout(null); /* lFiles = new List(); Font f = new Font("Dialog", Font.BOLD & Font.ITALIC, 10); lFiles.setFont(f); getContentPane().add(lFiles); */ DropTarget d = new DropTarget(getContentPane(),DnDConstants.ACTION_COPY_OR_MOVE, this); setLocation(624,0); setVisible(true); } //DropTargetListener public void dragEnter(DropTargetDragEvent dtde){} public void dragOver(DropTargetDragEvent dtde){} public void dropActionChanged(DropTargetDragEvent dtde){} public void dragExit(DropTargetEvent dte){} public void drop(DropTargetDropEvent dtde){ try{ String value = (String)dtde.getTransferable().getTransferData(DataFlavor.stringFlavor); ObjectInputStream in = new ObjectInputStream( new StringBufferInputStream(value)); lFiles = (List)in.readObject(); lFiles.setLocation(dtde.getLocation()); getContentPane().add(lFiles); /*String value = (String)dtde.getTransferable().getTransferData(DataFlavor.stringFlavor); lFiles.add(value); */ dtde.dropComplete(true); }catch(Exception __e){ System.out.println(__e); } } } // END DROPFRAME -----Mensagem original----- De: Luiz Fernando Estivalet <[EMAIL PROTECTED]> Para: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Data: Sábado, 12 de Janeiro de 2002 13:23 Assunto: [java-list] drag e drop >Quer ter seu próprio endereço na Internet? >Garanta já o seu e ainda ganhe cinco e-mails personalizados. >DomíniosBOL - http://dominios.bol.com.br > > > > > >Ola, >Estou querendo fazer um prototipo que use drag&drop. >A ideia eh fazer tipo um frontpage em Java, arrastando os >componentes (text, combo box, check box) para montar uma >pagina HTML. >Alguem tem algum exemplo de como fazer isso? > >Obirgado, >Luiz Fernando > >------------------------------ LISTA SOUJAVA ---------------------------- >http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP >dúvidas mais comuns: http://www.soujava.org.br/faq.htm >regras da lista: http://www.soujava.org.br/regras.htm >para sair da lista: envie email para [EMAIL PROTECTED] >------------------------------------------------------------------------- > > ------------------------------ LISTA SOUJAVA ---------------------------- http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm para sair da lista: envie email para [EMAIL PROTECTED] -------------------------------------------------------------------------