绝地无双
你用纯JAVA做UI界面要实现动态效果就必须不断刷新画面。你的函数的参数也要不断的改变,将参数的值和你需要移动的质点坐标建立关系。应该就可以。Java UI本来就是一个坐标系。就不知道你要的什么效果。不然可以帮你构建一下代码。你先参考我以前学习时做的一个简单移动质点的程序(可直接运行),希望对你有帮助。/** 功能:加深对事件处理机制的理解* 键盘方向键控制小球的运动*/package JavaBase13_ActionListerner;import java.awt.*;import javax.swing.*;import java.awt.event.*;public class DemoB extends JFrame{MyPanel mp = null;public static void main(String[] args) {// TODO Auto-generated method stubDemoB w51 = new DemoB();}public DemoB(){mp = new MyPanel();this.add(mp);//实现监听this.addKeyListener(mp);this.setSize(300, 300);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}}class MyPanel extends JPanel implements KeyListener{int x = 10;int y = 10;public void paint(Graphics g){super.paint(g);g.fillOval(x, y, 10, 10);}@Overridepublic void keyPressed(KeyEvent e) {// TODO Auto-generated method stub//System.out.println("被按下"+e.getKeyChar());if(e.getKeyCode()==KeyEvent.VK_DOWN){y+=5;}else if(e.getKeyCode()==KeyEvent.VK_UP){y-=5;}else if(e.getKeyCode()==KeyEvent.VK_LEFT){x-=5;}else if(e.getKeyCode()==KeyEvent.VK_RIGHT){x+=5;}//调用repaint函数 来重绘界面this.repaint();}@Overridepublic void keyTyped(KeyEvent e) {// TODO Auto-generated method stub}@Overridepublic void keyReleased(KeyEvent e) {// TODO Auto-generated method stub}}