- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class DragAndDrop extends JFrame
{
WATCanvas canvas;
public DragAndDrop()
{
super();
Container container = getContentPane();
setBackground(Color.WHITE);
canvas = new WATCanvas(800,600,45,40);
container.add(canvas);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 2));
container.add(panel, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setSize(1200,1000);
setVisible(true);
}
class WATCanvas extends JPanel
{
Cursor curSP, curCSF, curCDF, curUB, curPP, curMod, curKD, cur;
int buttonLeftBorder = 900;
int buttonTopBorder = 20;
double spX=buttonLeftBorder, spY=buttonTopBorder+10, spW=20, spH=20;//singlePallet coordinates
double csFX=buttonLeftBorder, csFY=buttonTopBorder+90, csFW=80, csFH=40;//caseFlow coordinates
double cdFX=buttonLeftBorder, cdFY=buttonTopBorder+150, cdFW=40, cdFH=40;//caddyFlow coordinates
double ubX=buttonLeftBorder, ubY=buttonTopBorder+210, ubW=80, ubH=20;//unloadBulk coordinates
double ppX=buttonLeftBorder, ppY=buttonTopBorder+250, ppW=80, ppH=20;//prePick coordinates
double modX=buttonLeftBorder, modY=buttonTopBorder+290, modW=40, modH=40;//module coordinates
double kdX=buttonLeftBorder, kdY=buttonTopBorder+350, kdW=20, kdH=20;//kd coordinates
int x1, y1, x2, y2;
int width, height, rows, cols;
Rectangle2D singlePallet;
Rectangle2D caseFlow;
Rectangle2D caddyFlow;
Rectangle2D unloadBulk;
Rectangle2D prePick;
Rectangle2D module;
Rectangle2D kd;
Rectangle2D selectedShape;
Rectangle2D boundingRec;
public WATCanvas(int w, int h, int r, int c)
{
setBackground(Color.white);
setSize(width = w, height = h);
rows = r;
cols = c;
addMouseListener(new MyMouseListener());
addMouseMotionListener(new MyMouseMotionListener());
setTitle("Warehouse Allocation Model");
}
public void paint(Graphics g)
{
Font insideDrawing = new Font("TimesRoman",Font.PLAIN, 9);
Font boldDescription = new Font("TimesRoman", Font.BOLD, 10);
Graphics2D g2 = (Graphics2D) g;
//single pallet location
singlePallet = new Rectangle2D.Double(spX,spY,spW,spW);
g2.draw(singlePallet);
g2.setFont(insideDrawing);
g2.drawString("xxx", buttonLeftBorder+05, buttonTopBorder+15);
g2.setFont(boldDescription);
g2.drawString("Single Pallet Lane", buttonLeftBorder+25, buttonTopBorder+20);
//Multiple Pallets
g2.setFont(insideDrawing);
g2.drawString("xxx",buttonLeftBorder+05,buttonTopBorder+55);
g2.drawRect(buttonLeftBorder, buttonTopBorder+50, 20, 20);
g2.drawRect(buttonLeftBorder+20, buttonTopBorder+50, 20, 20);
g2.drawRect(buttonLeftBorder+40, buttonTopBorder+50, 20, 20);
g2.drawRect(buttonLeftBorder+60, buttonTopBorder+50, 20, 20);
g2.setFont(boldDescription);
g2.drawString("Flow Lane (4-deep example)", buttonLeftBorder+85, buttonTopBorder+60);
//Case Flow
caseFlow = new Rectangle2D.Double(csFX,csFY,csFW,csFH);
g2.setFont(insideDrawing);
g2.drawString("Case Flow", buttonLeftBorder+20, buttonTopBorder+115);
g2.draw(caseFlow);
g2.setFont(boldDescription);
g2.drawString("Standard Case Flow Rack", buttonLeftBorder+85, buttonTopBorder+115);
//Caddy Flow
caddyFlow = new Rectangle2D.Double(cdFX,cdFY,cdFW,cdFH);
g2.setFont(insideDrawing);
g2.drawString("Caddy",buttonLeftBorder+10, buttonTopBorder+170);
g2.drawString("Flow",buttonLeftBorder+12,buttonTopBorder+180);
g2.draw(caddyFlow);
g2.setFont(boldDescription);
g2.drawString("Standard Caddy Flow Rack", buttonLeftBorder+45, buttonTopBorder+175);
//Unload Bulk Door
unloadBulk = new Rectangle2D.Double(ubX,ubY,ubW,ubH);
g2.setFont(insideDrawing);
g2.setColor(Color.BLACK);
g2.fill(unloadBulk);
g2.setColor(Color.WHITE);
g2.drawString("Unload/Bulk Door", buttonLeftBorder+3, buttonTopBorder+223);
g2.setColor(Color.BLACK);
g2.setFont(boldDescription);
g2.drawString("Unload/Bulk Door", buttonLeftBorder+85, buttonTopBorder+223);
//Pre-Pick Trad
prePick = new Rectangle2D.Double(ppX,ppY,ppW,ppH);
g2.setFont(insideDrawing);
g2.fill(prePick);
g2.setColor(Color.WHITE);
g2.drawString("PP/Trad",buttonLeftBorder+20, buttonTopBorder+263);
g2.setFont(boldDescription);
g2.setColor(Color.BLACK);
g2.drawString("Pre-Pick Module", buttonLeftBorder+85, buttonTopBorder+263);
//Module with spotted pattern
module = new Rectangle2D.Double(modX,modY,modW,modH);
g2.setFont(insideDrawing);
BufferedImage bi = new BufferedImage(5,5,BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
big.setColor(Color.WHITE);
big.fillRect(0, 0, 5, 5);
big.setColor(Color.LIGHT_GRAY);
big.fillOval(2, 2, 2, 2);
TexturePaint tp = new TexturePaint(bi, new Rectangle(5,5));
g2.setPaint(tp);
g2.fill(module);
g2.setFont(boldDescription);
g2.setColor(Color.BLACK);
g2.drawString("Module", buttonLeftBorder+04, buttonTopBorder+310);
g2.draw(module);
g2.setFont(boldDescription);
g2.drawString("Standard Caddy Flow Rack", buttonLeftBorder+45, buttonTopBorder+310);
//KD with spotted pattern
kd = new Rectangle2D.Double(kdX,kdY,kdW,kdH);
BufferedImage bi2 = new BufferedImage(5,5,BufferedImage.TYPE_INT_RGB);
Graphics2D big2 = bi2.createGraphics();
big2.setColor(Color.DARK_GRAY);
big2.fillRect(0, 0, 5, 5);
big2.setColor(Color.BLACK);
big2.fillOval(2, 2, 2, 2);
TexturePaint tp2 = new TexturePaint(bi2, new Rectangle(5,5));
g2.setPaint(tp2);
g2.fill(kd);
g2.setFont(boldDescription);
g2.setColor(Color.BLACK);
g2.drawString("KD", buttonLeftBorder+4, buttonTopBorder+365);
g2.draw(kd);
g.setFont(boldDescription);
g.drawString("KD Stands", buttonLeftBorder+25, buttonTopBorder+365);
width = 900;
height = 800;
int start = 25;
int rowHt = 20;
for(int j=0;j<=rows;++j)
g.drawLine(start, start + j*rowHt, height+start,start + j*rowHt);
int rowWid = 20;
for(int k=0;k<=cols;++k)
g.drawLine(start+k*rowWid, start, start + k*rowWid, width+start);
if (cur != null)
setCursor(cur);
}
class MyMouseListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
if (singlePallet.contains(e.getX(), e.getY()))
{
selectedShape = singlePallet;
if (boundingRec != null)
boundingRec = singlePallet.getBounds2D();
}
else if (caseFlow.contains(e.getX(), e.getY()))
{
selectedShape = caseFlow;
if (boundingRec != null)
boundingRec = caseFlow.getBounds2D();
}
else if (caddyFlow.contains(e.getX(), e.getY()))
{
selectedShape = caddyFlow;
if (boundingRec != null)
boundingRec = caddyFlow.getBounds2D();
}
else if (unloadBulk.contains(e.getX(), e.getY()))
{
selectedShape = unloadBulk;
if (boundingRec != null)
boundingRec = unloadBulk.getBounds2D();
}
else if (prePick.contains(e.getX(), e.getY()))
{
selectedShape = prePick;
if (boundingRec != null)
boundingRec = prePick.getBounds2D();
}
else if (module.contains(e.getX(), e.getY()))
{
selectedShape = module;
if (boundingRec != null)
boundingRec = module.getBounds2D();
}
else if (kd.contains(e.getX(), e.getY()))
{
selectedShape = kd;
if (boundingRec != null)
boundingRec = kd.getBounds2D();
}
else
{
boundingRec = null;
}
canvas.repaint();
x1 = e.getX();
y1 = e.getY();
}
public void mouseReleased(MouseEvent e)
{
if (singlePallet.contains(e.getX(), e.getY()))
{
boundingRec = singlePallet.getBounds2D();
selectedShape = singlePallet;
}
else if (caseFlow.contains(e.getX(), e.getY()))
{
boundingRec = caseFlow.getBounds2D();
selectedShape = caseFlow;
}
else if (caddyFlow.contains(e.getX(), e.getY()))
{
boundingRec = caddyFlow.getBounds2D();
selectedShape = caddyFlow;
}
else if (unloadBulk.contains(e.getX(), e.getY()))
{
boundingRec = unloadBulk.getBounds2D();
selectedShape = unloadBulk;
}
else if (prePick.contains(e.getX(), e.getY()))
{
boundingRec = prePick.getBounds2D();
selectedShape = prePick;
}
else if (module.contains(e.getX(), e.getY()))
{
boundingRec = module.getBounds2D();
selectedShape = module;
}
else if (kd.contains(e.getX(), e.getY()))
{
boundingRec = kd.getBounds2D();
selectedShape = kd;
}
//canvas.repaint();
}
public void mouseClicked(MouseEvent e)
{
if (singlePallet.contains(e.getX(), e.getY()))
{
selectedShape = singlePallet;
boundingRec = singlePallet.getBounds2D();
}
else if (caseFlow.contains(e.getX(), e.getY()))
{
selectedShape = caseFlow;
boundingRec = caseFlow.getBounds2D();
}
else if (caddyFlow.contains(e.getX(), e.getY()))
{
selectedShape = caddyFlow;
boundingRec = caddyFlow.getBounds2D();
}
else if (unloadBulk.contains(e.getX(), e.getY()))
{
selectedShape = unloadBulk;
boundingRec = unloadBulk.getBounds2D();
}
else if (prePick.contains(e.getX(), e.getY()))
{
selectedShape = prePick;
boundingRec = prePick.getBounds2D();
}
else if (module.contains(e.getX(), e.getY()))
{
selectedShape = module;
boundingRec = module.getBounds2D();
}
else if (kd.contains(e.getX(), e.getY()))
{
selectedShape = kd;
boundingRec = kd.getBounds2D();
}
else
{
if (boundingRec != null)
boundingRec = null;
}
canvas.repaint();
}
}
class MyMouseMotionListener extends MouseMotionAdapter
{
public void mouseDragged(MouseEvent e) {
if (singlePallet.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = singlePallet;
x2 = e.getX();
y2 = e.getY();
spX = spX + x2 - x1;
spY = spY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (caseFlow.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
csFX = csFX + x2 - x1;
csFY = csFY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (caddyFlow.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
cdFX = cdFX + x2 - x1;
cdFY = cdFY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (unloadBulk.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
ubX = ubX + x2 - x1;
ubY = ubY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (prePick.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
ppX = ppX + x2 - x1;
ppY = ppY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (module.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
modX = modX + x2 - x1;
modY = modY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
else if (kd.contains(e.getX(), e.getY()))
{
boundingRec = null;
selectedShape = caseFlow;
x2 = e.getX();
y2 = e.getY();
kdX = kdX + x2 - x1;
kdY = kdY + y2 - y1;
x1 = x2;
y1 = y2;
canvas.repaint();
}
}
public void mouseMoved(MouseEvent e)
{
if(singlePallet != null && caseFlow != null && caddyFlow != null && unloadBulk != null
&& prePick != null && module != null && kd != null)
{
if (singlePallet.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (caseFlow.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (caddyFlow.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (unloadBulk.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (prePick.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (module.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else if (kd.contains(e.getX(), e.getY()))
{
cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
else
{
cur = Cursor.getDefaultCursor();
}
}
canvas.repaint();
}
}
}
public static void main(String arg[])
{
new DragAndDrop();
}
}
问题是拖动的项目留下了如图所示的轨迹。我想要做的就是将项目拖到网格中,然后获取其在网格线中的坐标你能帮我阻止它在被拖动时留下痕迹
任何形式的帮助将不胜感激,谢谢。
最佳答案
自定义绘制是通过重写paintComponent()
而不是paint()来完成的。
不要忘记在方法开始时调用 super.paintComponent()
,以便在重新绘制之前清除背景。
关于java - 拖放程序项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945326/
我在这里有一个我想要做的事情的例子:http://jsbin.com/OwoYAlEQ/1/edit 这是我的 HTML: person one person two person three per
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在我的 Web 应用程序中使用 Ajax ControlToolkit 中的 ModalPopupExtender。我将其 Drag 属性设置为 true,但是当我拖动弹出面板并将其放到新位置时,它
所以,基于this answer ,我有一组可以拖放并卡入到位的 div。唯一的问题是,可拖动的 div 具有不同的高度,我需要它们始终捕捉到目标的底部,而不是顶部。 您可以在this JsFiddl
我一直在使用 Bea 的解决方案 here一段时间后发现它非常有帮助。现在我遇到的问题是,当我将项目拖放到另一个 ListView 控件中或拖放到另一个 ListView 控件中,并且我想在拖动“期间
我试图在使用 QTreeWidget.setItemWidget() 重新父级(拖放)后将小部件放入 QTreeWidgetItem 但是,如果编译以下代码,结果是 QTreeWidgetItem 内
这是场景,我使用的是prototype和scriptaculous,但我相信jquery也会有同样的问题。我在相对定位的 div 中有一个可拖动图像的列表。问题是我无法将图像拖出父 div...好吧.
我正在使用一个普通(Bootstrap)表,我想在其中包含可排序的行。我正在使用 Angular CDK (DragDropModule) 来实现排序/排序。但是,当拖动行时,它会扭曲宽度,因为 cd
我正在尝试在我的 UICollectionView 中实现拖放机制,这与在快捷方式应用程序中重新排序快捷方式的组件非常相似。 截至目前,行为是当您开始拖动时,会留下一个透明的单元格 View ,而另一
我有以下 Jquery UI 拖放 jsfiddle https://jsfiddle.net/zoojsfiddle/ud96jdcp/ 具有
我希望创建一个基于网络的“公告板”,可以这么说,用户可以在其中创建/删除/拖放“图钉”,而不允许重叠“图钉”。 这是一个图表,应该有助于说明我正在尝试创建的内容: 'pins' 可能已创建双击;他们会
我是一名优秀的程序员,十分优秀!