我需要在大学课程设计园区里做。 我搜索了很多关于拖动图片但没有直接影响我的问题。 在这种情况下我需要帮助。程序通过拖放运行,但不知道如何执行此操作。请帮忙
我发现了一些例子,但它们是图片的常量路径,没有从复合材料拖动到某个面板,拖动的图片不会停留在起始位置
this http://i40.tinypic.com/opz67t.jpg是我的计划:
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Button;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Composite;
import java.awt.Frame;
import org.eclipse.swt.awt.SWT_AWT;
import java.awt.Component;
import java.awt.Panel;
import java.awt.BorderLayout;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ResourceBundle.Control;
import javax.swing.JComponent;
import javax.swing.JRootPane;
import javax.swing.JTable;
import javax.swing.TransferHandler;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
public class ogrod {
protected Shell shlProjectgarden;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
ogrod window = new ogrod();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shlProjectgarden.open();
shlProjectgarden.layout();
while (!shlProjectgarden.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shlProjectgarden = new Shell();
shlProjectgarden.setSize(794, 515);
shlProjectgarden.setText("projectGARDEN");
shlProjectgarden.setLayout(new GridLayout(8, false));
Menu menu = new Menu(shlProjectgarden, SWT.BAR);
shlProjectgarden.setMenuBar(menu);
MenuItem mntmPlik = new MenuItem(menu, SWT.NONE);
mntmPlik.setText("File");
MenuItem mntmEdycja = new MenuItem(menu, SWT.NONE);
mntmEdycja.setText("Edit");
MenuItem mntmNarzedzia = new MenuItem(menu, SWT.NONE);
mntmNarzedzia.setText("Tools");
MenuItem mntmWidok = new MenuItem(menu, SWT.NONE);
mntmWidok.setText("View");
MenuItem mntmPomoc = new MenuItem(menu, SWT.NONE);
mntmPomoc.setText("Help");
Button btnOtwrz = new Button(shlProjectgarden, SWT.NONE);
btnOtwrz.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\Open-icon.png"));
btnOtwrz.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnOtwrz.setText("Open");
Button btnZapisz = new Button(shlProjectgarden, SWT.NONE);
btnZapisz.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnZapisz.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\Save-icon.png"));
btnZapisz.setText("Save");
Button btnCofnij = new Button(shlProjectgarden, SWT.NONE);
btnCofnij.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnCofnij.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\Undo-icon.png"));
btnCofnij.setText("Undo");
Button btnUsu = new Button(shlProjectgarden, SWT.NONE);
btnUsu.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\delete-icon.png"));
btnUsu.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnUsu.setText("Delete");
Button btnObr = new Button(shlProjectgarden, SWT.NONE);
btnObr.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnObr.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\rotate1.png"));
btnObr.setText("Turn");
Button button = new Button(shlProjectgarden, SWT.NONE);
button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
button.setText("Turn");
button.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\rotate2.png"));
Button btnKolor = new Button(shlProjectgarden, SWT.NONE);
btnKolor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnKolor.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\gradient.png"));
btnKolor.setText("Color");
Button btnWyjd = new Button(shlProjectgarden, SWT.NONE);
btnWyjd.setImage(SWTResourceManager.getImage("D:\\PROJEKT PROGRAMOWANIE\\icons\\exit.png"));
btnWyjd.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnWyjd.setText("Exit");
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
//First EXPAND BAR
ExpandBar expandBar = new ExpandBar(shlProjectgarden, SWT.NONE);
GridData gd_expandBar = new GridData(SWT.FILL, SWT.TOP, false, true, 2, 1);
gd_expandBar.widthHint = 178;
expandBar.setLayoutData(gd_expandBar);
// item Rosliny
Composite compositePlants = new Composite(expandBar, SWT.NONE);
RowLayout layout = new RowLayout();
compositePlants.setLayout(layout);
Label ros1 = new Label(compositePlants,SWT.PUSH);
ros1.setAlignment(SWT.CENTER);
ros1.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\drzewo.png"));
ExpandItem item0 = new ExpandItem(expandBar, SWT.NONE, 0);
item0.setText("Plants");
item0.setHeight(compositePlants.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
item0.setControl(compositePlants);
Label label = new Label(compositePlants, SWT.NONE);
label.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\flowers1.png"));
Label label_5 = new Label(compositePlants, SWT.NONE);
label_5.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\flowers3.png"));
item0.setExpanded(true);
ExpandItem furnitures = new ExpandItem(expandBar, SWT.NONE);
furnitures.setExpanded(true);
furnitures.setText("Garden Furniture");
ExpandBar expandBar_5 = new ExpandBar(expandBar, SWT.BORDER | SWT.V_SCROLL);
furnitures.setControl(expandBar_5);
Composite composite = new Composite(expandBar, SWT.NONE);
furnitures.setControl(composite);
composite.setLayout(new RowLayout());
Label label_1 = new Label(composite, SWT.NONE);
label_1.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\stol1.png"));
label_1.setAlignment(SWT.CENTER);
Label label_2 = new Label(composite, SWT.NONE);
label_2.setAlignment(SWT.CENTER);
label_2.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\lawka1.png"));
furnitures.setHeight(furnitures.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
ExpandItem paths = new ExpandItem(expandBar, SWT.NONE);
paths.setExpanded(true);
paths.setText("Paths");
ExpandBar expandBar_6 = new ExpandBar(expandBar, SWT.BORDER | SWT.V_SCROLL);
paths.setControl(expandBar_6);
Composite composite_1 = new Composite(expandBar, SWT.NONE);
paths.setControl(composite_1);
composite_1.setLayout(new RowLayout());
Label label_3 = new Label(composite_1, SWT.NONE);
label_3.setImage(SWTResourceManager.getImage("D:\\Krzysiek\\workspace\\GardenProject\\sciezka2.png"));
label_3.setAlignment(SWT.CENTER);
paths.setHeight(paths.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
Canvas canvas = new Canvas(shlProjectgarden, SWT.NONE);
canvas.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
GridData gd_canvas = new GridData(SWT.FILL, SWT.FILL, false, true, 6, 1);
gd_canvas.heightHint = 227;
canvas.setLayoutData(gd_canvas);
new Label(shlProjectgarden, SWT.NONE);
new Label(shlProjectgarden, SWT.NONE);
Scale scale = new Scale(shlProjectgarden, SWT.NONE);
GridData gd_scale = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 6, 1);
gd_scale.heightHint = 36;
scale.setLayoutData(gd_scale);
}
}