我开始在java中绘制正方形,我使用键侦听器来移动它们。 我似乎唯一的问题是,从一个方向移动到另一个方向之间的平滑过渡。我的意思是,例如,当我向右移动然后改变我的方向时,它停止一秒然后再次开始移动,但是向左移动。我试图顺利过渡到从右向左切换的地方,它会立即开始向那个方向发展而不是停止,然后继续前进。任何帮助都会很好,提前谢谢:)!
我的主要框架类:
postResult = function(list) {
//var nameList, i, glist;
glist = list;
if (list.length > 0) {
$("#result").html(list[0].name + "<br />" + list[0].salary);
}
postResult = function(list) {
//var namesDepartmentList, i, glist;
glist = list;
if (list.length > 0) {
$("#namesDepartment").html(list[0].name + "<br />" + list[0].department);
}
}
nameList = "";
for (i = 0; i < list.length; i += 1) {
nameList = nameList + list[i].name + "<br />";
}
$("#names").html(nameList);
namesDepartmentList = "";
for (i = 0; i < list.length; i += 1) {
namesDepartmentList = nameList + list[i].name + "<br />";
}
$("#namesDepartment").html(namesDepartmentList);
}
submit = function() {
var searchWord = document.getElementById("key-word").value;
query = new ChicagoEmployeesQuery(searchWord);
$("#result").html("waiting...");
query.getList(postResult);
if (key_word.isEmpty()) {
alert("No Matching Records Found");
}
}
submit = function() {
var searchWord = document.getElementById("key-word").value;
query = new ChicagoEmployeesQuery(searchWord);
$("#namesDepartment").html("waiting...");
query.getList(postResult);
}
$(function() {
$("#start").click(submit);
});
我的Screen类,我将广场绘制到JPanel
package mainpackages;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class Frame extends JFrame implements KeyListener{
Screen s;
public static void main(String[] args) {
new Frame();
}
public Frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setTitle("Drawing practice");
setResizable(false);
setLocationRelativeTo(null);
addKeyListener(this);
init();
}
public void init() {
s = new Screen();
add(s);
setVisible(true);
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == e.VK_UP) {
s.y -= s.deltay;
}
if(e.getKeyCode() == e.VK_DOWN) {
s.y += s.deltay;
}
if(e.getKeyCode() == e.VK_LEFT) {
s.x -= s.deltax;
}
if(e.getKeyCode() == e.VK_RIGHT) {
s.x += s.deltax;
}
repaint();
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}