The Artima Developer Community
Sponsored Link

Java Answers Forum
Thread Animation Problem PLS HELP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Thread Animation Problem PLS HELP Posted: Dec 3, 2006 3:59 AM
Reply to this message Reply
Advertisement
I have made an animation with the help of JAVA Thread.There is a main JFrame where an animated JPanel is added in the center of container.But the problem is when I made the animation, I used a JFrame. In that JFrame my Animation acts like what I wanted,But later when I converted the JFrame to JPanel and add this JPanel to another JFrame,an anomoly occurs.I dont know why,I hav given my code with a main JFrame where the Animated
JPanel is added.But I request u to Convert the Aniamted JPanel to a JFrame and see how it works(using another class).Just convert the "Animation" class to a JFrame and see the difference.Why does it act differenly if added to another container.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.EventListener.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.*;
 
public class MainAnimationForm extends JFrame {
  	
 
  public MainAnimationForm()
  {
  	this.setSize(800,600);
  	this.getContentPane().add(new Animation(),BorderLayout.CENTER);
    
  }
  
  public static void main(String[] args) {
    MainAnimationForm anm= new MainAnimationForm();
    anm.setVisible(true);
  }
  
  }
  
  
 class Animation extends JPanel {
  JScrollPane jScrollPane1 = new JScrollPane();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  //ImageIcon img=new ImageIcon("./Data/Sunset.jpg");
int lblX=800;   //800
int lbl2Y=400;  //600
int lbl3Y=0;	
 
  public Animation()
  {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    Animation anm= new Animation();
    anm.setVisible(true);
  }
  private void jbInit() throws Exception {
 
   this.setBackground(new Color(205, 164, 200));
       
   jLabel1.setText("TANVIR");
   jLabel1.setForeground(Color.red);
   jLabel1.setFont(new Font("",Font.BOLD,80));
  
   jLabel2.setText("PROJECT");
   jLabel2.setForeground(Color.blue);
   jLabel2.setFont(new Font("",Font.ITALIC,80));
   
   jLabel3.setText("Management");
   jLabel3.setForeground(Color.CYAN);
   jLabel3.setFont(new Font("",Font.BOLD,80));
  
  this.add(jLabel1,null);
  this.add(jLabel2,null);
  this.add(jLabel3,null);
  
   setAnimation();
 
}  
	public void setAnimation()
	{
 
		Thread thr1 = new Thread(new Runnable(){
 
			public void run()
			{
							SimpleDateFormat sdf = new SimpleDateFormat();
							String s="";
 
							while(true)
							{
								
												
							Animation.this.jLabel1.setBounds(lblX,100,300,60);
							lblX=lblX-10;	
							
							
							if(lblX==0)
							{
							
							for(int a=0;(a=lblX)==0;a++)
							 {
							Animation.this.jLabel2.setBounds(170,lbl2Y,550,60);	
							lbl2Y=lbl2Y-10;	
							if(lbl2Y==200)
							{ 
						
						
						for(int i=0;(i=lbl2Y)==200;i++)
							 {
							Animation.this.jLabel3.setBounds(270,lbl3Y,550,90);	
							lbl3Y=lbl3Y+10;	
						
							if(lbl3Y==300)
							{
								
							try{ Thread.sleep(1200);}catch(Exception ee){}	
								
								for(int p=0;p<=4;p++)	
								
								{
									
							Animation.this.jLabel1.setVisible(false);
							Animation.this.jLabel2.setVisible(false);
							Animation.this.jLabel3.setVisible(false);
					
							
							try{ Thread.sleep(700);}catch(Exception ee){}
												
							Animation.this.jLabel1.setVisible(true);
							Animation.this.jLabel2.setVisible(true);
							Animation.this.jLabel3.setVisible(true);
					
							try{ Thread.sleep(700);}catch(Exception ee){}
								}
										
								lblX=800;
								lbl2Y=400;
								lbl3Y=0;
							try{Thread.currentThread().sleep(1000);}
							catch(Exception ee){}															
							Animation.this.jLabel1.setBounds(0,0,0,0);	
							Animation.this.jLabel2.setBounds(0,0,0,0);	
							Animation.this.jLabel3.setBounds(0,0,0,0);	
								
								
							}
						
												
						try{ Thread.sleep(90);}catch(Exception ee){}
						    }
					
							}
							
							try{ Thread.sleep(90);}catch(Exception ee){}
						     }
						    
						    }
							
							try{ Thread.sleep(50);}catch(Exception ee){}
						}
 
			}
		});
 
		thr1.start();
 
}//End of Method ge
 
}

PLS HELP ME, THNX

Topic: Thread Animation Problem PLS HELP Previous Topic   Next Topic Topic: Storing Object into Database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use