我想通过摇摆轮流(延迟 40 秒)移动图像。你能帮我吗?我写了这段代码,但它不起作用。“本垒打”有形象
public void doSomething() {
frame.add(homer);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 600);
frame.setTitle("Homer with thread");
frame.setVisible(true);
ActionListener ac = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(KeyEvent.VK_DOWN))
homer.setColumn(homer.getColumn() + 3);
}
};
new Timer(40000, ac).start();
}