省略了head类代码...
import java.awt.*;
import java.awt.image.*;
import java.awt.MediaTracker;
import javax.swing.*;
import javax.imageio.*;
import java.io.*;
class Action_View extends JPanel {
BufferedImage buffer = null;
Action_View()
{
  buffer = new BufferedImage(1024,768, BufferedImage.TRANSLUCENT);
}
public void paintComponent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, 1024, 760);
g.drawImage(buffer,0,0, null);
}
public void update(Graphics g)
{
paint(g);
}

public void init(Graphics g)
{
g.drawImage(buffer,0,0, null);
}
public void walk_display(Graphics g)
{
g.drawImage(buffer,0,0, null);
}
public void action_display(Graphics g)
{
g.drawImage(buffer,0,0, null);
}
}
......................
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Arm {
    int x_pos = 400;
    int y_pos = 200;
    int type = 0;
    Arm(){}
    Arm(int x, int y, int t)
    {
     this.x_pos = x;
     this.y_pos = y;
     this.type = t;
    }
    public void draw_LeftHand(Graphics g)
    {
     g.drawLine(x_pos - 100, y_pos+160, x_pos-250, y_pos+160);
     g.drawLine(x_pos - 250, y_pos+160, x_pos-250, y_pos);
     g.drawLine(x_pos - 250, y_pos, x_pos-280, y_pos+10);
     g.drawLine(x_pos - 250, y_pos, x_pos-280, y_pos+40);
     g.drawLine(x_pos - 250, y_pos, x_pos-280, y_pos-40);
     g.drawLine(x_pos - 250, y_pos, x_pos-280, y_pos-70);
     g.drawLine(x_pos - 250, y_pos, x_pos-280, y_pos-100);
    }
    public void draw_RightHand(Graphics g)
    {
     g.drawLine(x_pos + 310, y_pos+160, x_pos+460, y_pos+160);
     g.drawLine(x_pos + 460, y_pos+160, x_pos+460, y_pos);
     g.drawLine(x_pos + 460, y_pos, x_pos+510, y_pos+10);
     g.drawLine(x_pos + 460, y_pos, x_pos+510, y_pos+40);
     g.drawLine(x_pos + 460, y_pos, x_pos+510, y_pos-40);
     g.drawLine(x_pos + 460, y_pos, x_pos+510, y_pos-70);
     g.drawLine(x_pos + 460, y_pos, x_pos+510, y_pos-100);
    }
}
...........................
import java.awt.Graphics;class Foot {
   int x_pos = 400;
   int y_pos = 400;
   int type = 0;
    Foot()
    {
    }
    Foot(int x, int y, int t)
    {
     this.x_pos = x;
     this.y_pos = y;
     this.type = t;
    }
    public void draw_LeftFoot(Graphics g)
    {
     g.drawLine(x_pos+50, y_pos+140, x_pos+50, y_pos+220);
     g.drawLine(x_pos+50, y_pos+220, x_pos-30, y_pos+320);
    }
    public void draw_RightFoot(Graphics g)
    {
     g.drawLine(x_pos+220, y_pos+140, x_pos+220, y_pos+220);
     g.drawLine(x_pos+220, y_pos+220, x_pos+180, y_pos+320);
    }
}
....................................
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
class MB_Controller extends JDesktopPane implements ActionListener{
int type = 0;
Timer time;
Graphics g;
MBC_Frame mbc_frame = null;
MBC_Frame mbc_frame_1 = null;
BufferedImage image = null;
Welcome_View view = null;
Action_View action_view = null;
Robot robot = null ;
JButton button = null;
JButton action_button = null;
JButton walk_button = null;
JPanel panel = null;
JPanel m_panel = null;
JPanel s_panel = null;
MB_Controller()
{
time=new Timer(1000,this);
view = new Welcome_View();
mbc_frame = new MBC_Frame();
this.add(mbc_frame);
panel = new JPanel();
button = new  JButton("Enter System");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
type = 1;
Add_View(type);
}
}
);
panel.setLayout(new BorderLayout());
panel.add(BorderLayout.CENTER,view);
panel.add(BorderLayout.SOUTH ,button);
mbc_frame.getContentPane().add(panel);
mbc_frame.setVisible(true);
this.Add_View(type);
}
public void actionPerformed(ActionEvent e)
{ int i=220;
if (e.getSource()==time)
    Arm arm=new Arm(50,50+i,0);     //////////为什么arm不能动呀????
    arm.draw_LeftHand(this.g);
    i=i+100;
}
 void Add_View(int t)
    {
 this.type = t;
 switch(type){
   case 0:
 break;
   case 1:
 action_view = new Action_View();
 s_panel = new JPanel();
 m_panel = new JPanel();  m_panel.setLayout(new BorderLayout());  m_panel.add(BorderLayout.CENTER,action_view);  walk_button = new JButton("Robot Walking Simulation");
 action_button = new JButton("Robot Action Simulation");  walk_button.addActionListener(new ActionListener()
 {
 public void actionPerformed(ActionEvent e)
 {
 robot = new Robot(action_view);
 robot.act= 1;
 action_view.repaint();
 }
 });
 action_button.addActionListener(new ActionListener()
 {
 public void actionPerformed(ActionEvent e)
 {
robot = new Robot(action_view);
robot.act= 2;
action_view.repaint();
 }
 });
 walk_button.addActionListener(new ActionListener()
 {
  public void actionPerformed(ActionEvent e)
  {
time.start();
}
 }
     );
 s_panel.add(walk_button);
 s_panel.add(action_button);
 m_panel.add(BorderLayout.SOUTH,s_panel);
 mbc_frame_1 = new MBC_Frame();
 this.add(mbc_frame_1);
 mbc_frame_1.setContentPane(m_panel);
 mbc_frame.dispose();
 mbc_frame_1.setVisible(true);
 break;
case 2:
 break;
default:
break;
 }
    }
}class MBC_Frame extends JInternalFrame
{
MBC_Frame()
{
super(null,false,false,false);
this.setSize(1024,748);
    this.setBorder(null);
}
}
..........................
import java.awt.*;
import javax.swing.*;class MB_Frame extends JFrame {

Container contentPane = null;
MB_Controller control = null;
MB_Frame()
{
  super("Software Architecture -- Mobile Robot Project Demo");
  try{
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
contentPane = this.getContentPane();
// this.setTitle("Software Architecture -- Mobile Robot Project Demo");
    // iconImage = Toolkit.getDefaultToolkit().getImage("rocket.jpg");   
this.LoadController();
this.setSize( new Dimension(1024, 780));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
//this.pack();
this.setVisible(true);
       }
   catch(Exception e)
   
   {
 e.printStackTrace();
   }
}
void LoadController()
{
        control = new MB_Controller();
       // control.setLayout (new GridLayout());
        control.setLayout(new BorderLayout());
        contentPane.add(control);
       
}

}
......................
class Mobile_Robot_Demo {
public static void main(String[] args) {
try{
        Mobile_Robot_Demo app = new Mobile_Robot_Demo( );
        app.Application();
}
catch(Exception e)
{
        e.printStackTrace();
}
}
void Application()
{
   MB_Frame frame = new MB_Frame();
}
}
.................
import java.awt.*;
import java.awt.image.*;
import java.awt.MediaTracker;
import javax.swing.*;
import javax.imageio.*;class Robot {
int act = 0;
BufferedImage image;
    Graphics g;
    Action_View panel = null;
    
Robot(Action_View pane)
{
   this.panel = pane;
   g = panel.buffer.getGraphics();
   g.setColor(Color.black);
   
   switch(act)
   {
case 0:
init(g);
break;
case 1:
walk_display(g);
break;
case 2:
action_display(g);
break;
default:
init(g);
break;
  }  
}
void init(Graphics g)
{
Head head = new Head();
Body body = new Body();
Arm arm = new Arm();
Foot foot = new Foot();
head.draw_Head(g);
body.draw_Body(g);
arm.draw_LeftHand(g);
arm.draw_RightHand(g);
foot.draw_LeftFoot(g);
foot.draw_RightFoot(g);
  
}
void walk_display(Graphics g)
{
}
void action_display(Graphics g)
{
}
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主截止到2008-06-19 17:31:48的汇总数据:
    注册日期:2008-6-19
    上次登录:2008-6-19
    发帖数:1
    结贴数:0
    结贴率: 0.00%
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    怎么看不出象多线程的啊?
    每次进来i都等于220。当然每次画出来的图形都是一样的。
    那怎么可能会动呢?public void actionPerformed(ActionEvent e) 
    { int i=220; 
    if (e.getSource()==time) 
        Arm arm=new Arm(50,50+i,0);    //////////为什么arm不能动呀???? 
        arm.draw_LeftHand(this.g); 
        i=i+100; 

      

  3.   

    可以考虑将int i=220;
    可以考虑将其修改为
    static int i=220;
      

  4.   

    改了还是不行呀,显示 Arm arm=new Arm(50,50+i,0);    这句有问题...编译后还不动...我把剩余代码也贴出来吧
    ....................
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class Body { int x_pos = 400;
    int y_pos = 300;
    int type =0;

    Body()
    {

    }

    Body(int x, int y, int t)
    {

    }

    void draw_Body(Graphics g)
    {
    g.drawRect(x_pos-100, y_pos-10, 410, 250);
    }
    }
    ..........................
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;class Head extends Thread { int x_pos = 500;
    int y_pos = 100;
    int type  = 0;

    Head()
    {

    }

    Head(int x, int y, int t)
    {
      this.x_pos = x;
      this.y_pos = y;
      this.type = t;
    }

    public void draw_Head(Graphics g)
    {
       g.drawArc(x_pos-40,y_pos - 20, 100, 180, 400, 400);
       g.drawLine(x_pos-25, y_pos + 40, x_pos, y_pos+40);
       g.drawLine(x_pos+15, y_pos + 40, x_pos+40, y_pos+40);
       g.drawLine(x_pos+10, y_pos + 70, x_pos+10, y_pos+ 100);
       g.drawLine(x_pos, y_pos + 120, x_pos+20, y_pos+ 120);
       g.drawLine(x_pos+10, y_pos + 160, x_pos+10, y_pos+ 190);
    }

    public void run()
    {
    while(true)
    {

    }

    }



    }
    ..........................
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.MediaTracker;
    import javax.swing.*;
    import javax.imageio.*;
    import java.io.*;class Welcome_View extends JPanel { BufferedImage image = null; Welcome_View()
    { } public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    this.LoadImage();
    g.drawImage(image, 0,0,image.getWidth(),image.getHeight(),this);
        g.setColor(Color.red);
        Font font = new Font("times",Font.BOLD,48);
        g.setFont(font);
        g.drawString("Mobile Robot Simulation System", 150, 200);
        font = new Font("times",Font.BOLD,28);
        g.setFont(font);
        g.drawString("Version 1.0", 450, 340);     font = new Font("times",Font.BOLD,38);
        g.setFont(font);
        g.drawString("School of Software Engineering, BJUT", 180, 600);
    } public void update(Graphics g)
    {
    paint(g);
    } protected void LoadImage()
    {
           try
       {
         image = ImageIO.read(new File("robot_1.jpg"));
       }
       catch(Exception e)
       {
     e.printStackTrace();
       } }
    }
    赐教....
      

  5.   

    :)看来只能靠自己啦!
    把代码自己走读一下吧.
    单步跟踪一下;
    偶还是比较落后形势,对java八瘦.
      

  6.   

    一般使用一个动画线程以一个固定时间间隔不断调用绘图组件的 repaint() 方法来实现动画。