LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java? question [edit this title] (https://www.linuxquestions.org/questions/programming-9/java-question-%5Bedit-this-title%5D-869916/)

shivanchpun 03-18-2011 03:00 AM

Java? question [edit this title]
 
Sir,
I am making online Myproject using java in which you can make your porject online or with your team, my problem is that when i drag one component from one page it disappear from another frame & i am unable to solve the problem that if the user don't have install java than myproject in not useable i am giving a span sort of code of my project:
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;

public class DragDrop implements DragGestureListener,
DragSourceListener,
DropTargetListener, Transferable {

static final DataFlavor[] supportedFlavors = {null};


static {
try {
supportedFlavors[0] = new
DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Object object;
// Transferable methods.
public Object getTransferData(DataFlavor flavor) {
if (flavor.isMimeTypeEqual
(DataFlavor.javaJVMLocalObjectMimeType)) {
return object;
} else {
return null;
}
}

public DataFlavor[] getTransferDataFlavors() {
return supportedFlavors;
}

public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.isMimeTypeEqual
(DataFlavor.javaJVMLocalObjectMimeType);
}
// DragGestureListener method.
public void dragGestureRecognized(DragGestureEvent ev) {
ev.startDrag(null, this, this);
}
// DragSourceListener methods.
public void dragDropEnd(DragSourceDropEvent ev) {
}

public void dragEnter(DragSourceDragEvent ev) {
}

public void dragExit(DragSourceEvent ev) {
}

public void dragOver(DragSourceDragEvent ev) {
object = ev.getSource();
}

public void dropActionChanged(DragSourceDragEvent ev) {
}
// DropTargetListener methods.
public void dragEnter(DropTargetDragEvent ev) {
}

public void dragExit(DropTargetEvent ev) {
}

public void dragOver(DropTargetDragEvent ev) {
dropTargetDrag(ev);
}

public void dropActionChanged(DropTargetDragEvent ev) {
dropTargetDrag(ev);
}

void dropTargetDrag(DropTargetDragEvent ev) {
ev.acceptDrag(ev.getDropAction());
}

public void drop(DropTargetDropEvent ev) {
ev.acceptDrop(ev.getDropAction());
try {
Object target = ev.getSource();
Object source = ev.getTransferable().getTransferData
(supportedFlavors[0]);
Component component = ((DragSourceContext)
source).getComponent();
Container oldContainer = component.getParent();
Container container = (Container) ((DropTarget)
target).getComponent();
container.add(component);
oldContainer.validate();
oldContainer.repaint();
container.validate();
container.repaint();
}
catch (Exception ex) {
ex.printStackTrace();
}
ev.dropComplete(true);
}

public static void main(String[] arg) {
Button button = new Button("Drag this button");
Label label = new Label("Drag this label");
Checkbox checkbox = new Checkbox("Drag this check box");
CheckboxGroup radiobutton = new CheckboxGroup();
Checkbox checkbox1 = new Checkbox("Drag this check box",
radiobutton, false);
Choice country = new Choice();

// adding possible choices
country.add("India");
country.add("US");
country.add("Australia");

Frame source = new Frame("Source Frame");
source.setLayout(new FlowLayout());
source.add(button);
source.add(label);
source.add(checkbox);
source.add(checkbox1);
source.add(country);

Frame target = new Frame("Target Frame");
target.setLayout(new FlowLayout());

DragDrop dndListener = new DragDrop();

DragSource dragSource = new DragSource();
DropTarget dropTarget1 = new DropTarget(source,
DnDConstants.ACTION_COPY, dndListener);
DropTarget dropTarget2 = new DropTarget(target,
DnDConstants.ACTION_COPY,
dndListener);
DragGestureRecognizer dragRecognizer1 = dragSource.
createDefaultDragGestureRecognizer(button,
DnDConstants.ACTION_COPY, dndListener);
source.add(button);
DragGestureRecognizer dragRecognizer2 = dragSource.
createDefaultDragGestureRecognizer(label,
DnDConstants.ACTION_COPY, dndListener);
DragGestureRecognizer dragRecognizer3 = dragSource.
createDefaultDragGestureRecognizer(checkbox,
DnDConstants.ACTION_COPY, dndListener);
DragGestureRecognizer dragRecognizer4 = dragSource.
createDefaultDragGestureRecognizer(checkbox1,
DnDConstants.ACTION_COPY, dndListener);
DragGestureRecognizer dragRecognizer5 = dragSource.
createDefaultDragGestureRecognizer(country,
DnDConstants.ACTION_COPY, dndListener);

source.setBounds(0, 200, 200, 200);
target.setBounds(220, 200, 200, 200);
source.show();
target.show();
}
}

plz give help me

archtoad6 03-21-2011 01:57 AM

Moved from "Linux - Games : What games would you like to see ported to Linux?"

The title I gave this probably isn't ideal, you can edit it to be something better.

Please don't hijack existing threads w/ OT (off topic) posts.

Please put your code in Code: blocks or a pastebin -- it will make it more readable, & more readable will get you better answers.


All times are GMT -5. The time now is 06:40 AM.