Total members 11895 |It is currently Sun Dec 22, 2024 9:28 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





PLEASE HELP ME..
THE ABOVE PROGRAMS MOVE A TANK(picture) IN RANDOM DIRECTION FOR RANDOM No OF TIMES
BUT WHEN I CREATE TWO THREADS THEN THEY ARE RU[Description]NNING ONE AFTER THE OTHER ANIMATION
ALSO THEY ARE DISPLAYING SEPARATE WINDOW FOR EACH THREAD.....I WANT THAT THEY BOTH APPEAR IN THE SAME WINDOW AND MOVE SIMULTANEOUSLY....
PLZ HELP ME FAST
(i m not good in java programing)
PLZ HELP ME FAST ...
Code:

import java
.awt.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.util.Map;
import java.util.Random;
import java.awt.image.ImageObserver;
import java.awt.event.*;
import java.awt.Window;
import java.awt.DisplayMode;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.GraphicsDevice;



public class Screen{
    public GraphicsDevice vc;
    public Screen(){
        GraphicsEnvironment evn=GraphicsEnvironment.getLocalGraphicsEnvironment();
        vc=evn.getDefaultScreenDevice();
    }
    
    public void setFullScreen
(DisplayMode dm,JFrame window){
     window.setUndecorated(false);
     window.setResizable(true);
     vc.setFullScreenWindow(window);
     if(dm!=null && vc.isDisplayChangeSupported()){
         try{
             vc.setFullScreenWindow(window);
              }catch(Exception ex){}
     }
}
    public Window getFullScreen(){
      return vc.getFullScreenWindow();
    }
    public void restoreScreen(){
        Window w=vc.getFullScreenWindow();
        if(w!=null){
            w.dispose();
        }
    }   
}


/////////////////////////////////

public class Tank extends JFrame{
    static Screen s;
    public Tank(){
       
    
}
    public static void main(String[] args){      
        DisplayMode dm
=new DisplayMode(200,200,8,DisplayMode.REFRESH_RATE_UNKNOWN);
        Tank t=new Tank();
         Screen s =new Screen();
        Tank_thread ab=new Tank_thread(dm);
        Tank_thread ab1=new Tank_thread(dm);
        ab1.start();
        ab.start();
    }
    
}
////////////////////////////////
public class Tank_thread extends Tank implements Runnable{
    DisplayMode dm;
    private Image bg;
    private Image TANK_OPP;
    private boolean loaded;
    int mov_time,direction,xx=100,yy=100,width,height,scr_Width=700,scr_Height=700;
    Random r=new Random();
    Screen s=new Screen();
    Thread thread;
    Tank_thread(DisplayMode dm){
        this.dm=dm;
        //this.s=s;
        s.setFullScreen(dm,this);       
        thread 
=new Thread(this);
        thread.start();        
    
}
       
    public void run
(){
        loaded=false;
        
        repaint
();
    }
    
    public void start
(){
        thread.start();
    }
      public void stop(){
        thread.stop();
    }
    public void paint(Graphics g){
    //Window w=s.getFullScreen();
    //RENDERING IF CONDITION MISSING
       int n=0;
       while(n<10){
          n++;
          int x=0;
            direction=r.nextInt(4);
            loadPics(direction);
            mov_time=r.nextInt(250);
            if(loaded==true){
               while(x<(mov_time)){
                    if(direction==0){
                        yy--;
                     }else if(direction==1){
                        xx++; 
                     
}else if(direction==2){
                        yy++; 
                     
}else{
                        xx--;
                    }
                    width=TANK_OPP.getWidth(null);
                    height=TANK_OPP.getHeight(null);
                    if(xx<20 || (xx+width)>scr_Width || yy<20 || (yy+height)>scr_Height){
                        direction=r.nextInt(4);
                        loadPics(direction);
                        continue;
                    }
                  g.drawImage(bg,0,0,null);
                  g.drawImage(TANK_OPP,xx,yy,null);
                   try{
                       Thread.sleep(20);
                   }catch(Exception ex){}
                    x++;           
            
}
        } 
     
}
              dispose();
  }
    
    public void loadPics
(int x){
        bg=new ImageIcon("C:\\A BATTLE\\WHITE_BG.JPG").getImage();
        if(x==0){
         TANK_OPP=new ImageIcon("C:\\A BATTLE\\P1.JPG").getImage();
        }else if(x==1){
            TANK_OPP=new ImageIcon("C:\\A BATTLE\\P2.JPG").getImage();
        }else if(x==2){
            TANK_OPP=new ImageIcon("C:\\A BATTLE\\P3.JPG").getImage();
        }else{
            TANK_OPP=new ImageIcon("C:\\A BATTLE\\P4.JPG").getImage();
        }
         loaded=true;
    }   

}
 





Attachments:
File comment: PLEASE HELP ME..
THE ABOVE PROGRAMS MOVE A TANK(picture) IN RANDOM DIRECTION FOR RANDOM No OF TIMES
BUT WHEN I CREATE TWO THREADS THEN THEY ARE RU[Description]NNING ONE AFTER THE OTHER ANIMATION
ALSO THEY ARE DISPLAYING SEPARATE WINDOW FOR EACH THREAD.....I WANT THAT THEY BOTH APPEAR IN THE SAME WINDOW AND MOVE SIMULTANEOUSLY....
PLZ HELP ME FAST
(i m not good in java programing)
PLZ HELP ME FAST ...

QUESTION.txt [4.15 KiB]
Downloaded 751 times
P1.jpg
P1.jpg [ 4.15 KiB | Viewed 4669 times ]
P2.jpg
P2.jpg [ 4.45 KiB | Viewed 4669 times ]
P3.jpg
P3.jpg [ 4.29 KiB | Viewed 4669 times ]
Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Draw Tank with animation and using threads too
 Tank game code     -  
 threads block on I/O     -  
 visual c++ MFC background threads     -  
 Introduction to threads in Java     -  
 Implementing synchronization in C++ with threads     -  
 Flashing Graphics animations with threads     -  
 Sprite Animation     -  
 cloud animation     -  
 Simple animation     -  
 animation using Photoshop     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com