LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2011, 03:00 AM   #1
shivanchpun
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 0
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
 
Old 03-21-2011, 01:57 AM   #2
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with polish characters (ISO-8859-2) in java panels title bar. badbarba Red Hat 0 11-15-2010 05:17 AM
[SOLVED] Use Java scanner delimiters separate artist year title etc? (Java)? mitchell7man Programming 9 04-13-2010 07:24 PM
Edit Thread Title hope1 LQ Suggestions & Feedback 5 12-21-2006 08:39 PM
I need a better title for this javascript question. Squall Programming 6 02-16-2004 08:54 PM
fluxbox java awt no title bar Kman Linux - Software 0 06-18-2003 10:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration