我正在制作一个空当接龙游戏,我将卡放置在垂直面板中以用于各列,我需要能够拿起一张卡并将其移至另一列,但是我有很多弄不清楚拖放处理程序需要如何协同工作。我在处理程序及其工作方式上找不到太多文档。只要我一直在努力,我什至不知道这些处理程序在这一点上是否正确。还是他们在错误的地方? 感谢您的帮助!
卡
public class GWTCard extends HTML {
Card card = null;
public GWTCard(Card card) {
super();
this.card = card;
this.setHeight("12rem");
this.setWidth("7rem");
this.addStyleName("card");
if(this.card.getFace().equals("diamonds")) {
this.setHTML("<h2 style='margin-top:.5em;'>" + this.card.getValue() + "◆</h2>"
+"<h1 style='text-align:center; font-size: -webkit-xxx-large;'>◆</h1>"
+"<h2 style='text-align:right'>" + this.card.getValue() + "◆</h2>");
}
else if(this.card.getFace().equals("hearts")) {
this.setHTML("<h2 style='margin-top:.5em;'>" + this.card.getValue() + "♥</h2>"
+"<h1 style='text-align:center; font-size: -webkit-xxx-large;'>♥</h1>"
+"<h2 style='text-align:right'>" + this.card.getValue() + "♥</h2>");
}
else if(this.card.getFace().equals("spades")) {
this.setHTML("<h2 style='margin-top:.5em;'>" + this.card.getValue() + "♠</h2>"
+"<h1 style='text-align:center; font-size: -webkit-xxx-large;'>♠</h1>"
+"<h2 style='text-align:right'>" + this.card.getValue() + "♠</h2>");
}
else if(this.card.getFace().equals("clubs")) {
this.setHTML("<h2 style='margin-top:.5em;'>" + this.card.getValue() + "♣</h2>"
+"<h1 style='text-align:center; font-size: -webkit-xxx-large;'>♣</h1>"
+"<h2 style='text-align:right'>" + this.card.getValue() + "♣</h2>");
}
else {
this.setHTML(this.card.getFace());
}
this.getElement().getStyle().setColor(this.card.getColor());
this.getElement().getStyle().setBorderWidth(2, Unit.PX);
this.getElement().getStyle().setBorderColor("black");
this.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);;
this.getElement().getStyle().setMargin(5, Unit.PX);
this.getElement().setDraggable("true");
GWTCard GWTCard = this;
this.addDragStartHandler(new DragStartHandler() {
@Override
public void onDragStart(DragStartEvent event) {
event.setData("card", card.toString());
}
});
this.addDomHandler(new DragStartHandler(){
@Override
public void onDragStart(DragStartEvent event) {
// required: data to be transferred to the drop handler
event.setData("card", card.toString());
}}, DragStartEvent.getType()
);
}
}
列下降处理程序
private DropHandler dropVert(VerticalPanel target) {
return new DropHandler() {
@Override
public void onDrop(DropEvent e) {
e.preventDefault();
Widget sender = (Widget) e.getSource();
target.add(sender);
}
};
}
}