在ai里面,用键盘方向键移动东西时,每按一次移动我想要的数值,应该怎么设置?说详细点,初学ai。 20
4个回答
展开全部
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class DrawRectTest extends JFrame {
int oldx =40,x=40;
int y=30, oldy =40;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public void moveOval(){
Graphics g = this.getGraphics();
Color c = g.getColor();
g.setColor(this.getBackground());
g.fillOval(oldx, oldy, 40, 40);
g.setColor(c);
g.fillOval(x, y, 40, 40);
this.oldx = x;
this.oldy = y;
}
public DrawRectTest() {
this.setSize(500, 500);
this.setVisible(true);
addKeyListener(new A(this));
}
public void paint(Graphics g) {
super.paint(g);
int w = 0;
int h = 30;
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
g.drawRect(w = w + 40, h, 40, 40);
}
w = 0;
h += 40;
}
g.fillOval(x, y, 40, 40);
}
public static void main(String[] args) {
new DrawRectTest();
}
}
class A implements KeyListener {
DrawRectTest j;
public A(DrawRectTest jp){
this.j=jp;
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:
j.setX(j.getX());
j.setY(j.getY()+40);
//j.repaint();
j.moveOval();
break;
case KeyEvent.VK_UP:
break;
case KeyEvent.VK_LEFT:
break;
case KeyEvent.VK_RIGHT:
break;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class DrawRectTest extends JFrame {
int oldx =40,x=40;
int y=30, oldy =40;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public void moveOval(){
Graphics g = this.getGraphics();
Color c = g.getColor();
g.setColor(this.getBackground());
g.fillOval(oldx, oldy, 40, 40);
g.setColor(c);
g.fillOval(x, y, 40, 40);
this.oldx = x;
this.oldy = y;
}
public DrawRectTest() {
this.setSize(500, 500);
this.setVisible(true);
addKeyListener(new A(this));
}
public void paint(Graphics g) {
super.paint(g);
int w = 0;
int h = 30;
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
g.drawRect(w = w + 40, h, 40, 40);
}
w = 0;
h += 40;
}
g.fillOval(x, y, 40, 40);
}
public static void main(String[] args) {
new DrawRectTest();
}
}
class A implements KeyListener {
DrawRectTest j;
public A(DrawRectTest jp){
this.j=jp;
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:
j.setX(j.getX());
j.setY(j.getY()+40);
//j.repaint();
j.moveOval();
break;
case KeyEvent.VK_UP:
break;
case KeyEvent.VK_LEFT:
break;
case KeyEvent.VK_RIGHT:
break;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在变换面板里,在X轴或Y轴,加上或减去你想要的数值,回车就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
右键单击你想移动的图形,选择变换〉移动,或直接按快捷键ctrl+shift+m。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编辑 -》 首选项 -》 常规 -》 键盘增量
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询