例如,当我按下向上键时,它将为左箭头键运行一次代码,暂停一会儿,然后重复该代码。我想更改代码的第一次运行到它开始重复之间的时间。我应该怎么做才能做到这一点?
这是我当前正在使用的代码:
JFrame thing=new JFrame();
thing.setTitle("thing");
thing.setResizable(false);
thing.setSize(500,500);
JPanel panel=(JPanel) thing.getContentPane();
panel.setLayout(null);
JLabel thing2=new JLabel("thing");
panel.add(thing2);
thing2.setBounds(x,y,50,50);
thing2.setFocusable(true);
thing2.requestFocusInWindow();
thing2.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
thing2.setLocation(x-10,y);
thing2.repaint();
x-=10;
}
}
});
thing.setVisible(true);