java - How to make a horizontal moving applet panel? -
i want implement game similar copter. i'm trying develop it's background can me how make horizontally (left side) moving panel inside applet? initial code have written.
any ideas appreciated!
testing.java
package firstgame; import javax.swing.*; import java.awt.event.*; import java.applet.*; import java.awt.*; import java.util.timertask; public class testing extends applet implements runnable{ int y; thread thread; int count=0; int width = toolkit.getdefaulttoolkit().getscreensize().width; public void init() { this.setbackground(color.black); this.setsize(600, 400); } runs 1 time , draws graphic on visible applet
public void initialpaint() { int i=0; graphics g = getgraphics(); g.setcolor(color.green); // using fill rectangle command while(i<=getwidth()) { g.fillrect(i-1, 0 , 10, this.randompixel()); g.fillrect(i-1, this.getheight()-this.getheight()/5, 10,randompixel()); i+=10; } } public void start() { if(thread==null) { thread = new thread(this); thread.start(); } } public int randompixel() { int z = (int)(math.random()*this.getheight()/5+1); //system.out.println(z); return z; } public void run() { try{ while(true) { repaint(); } }catch(exception e) {} } public void paint(graphics g) { g.setcolor(color.green); try{ while(true) { if(count == 0) { this.initialpaint(); } setlocation(-count,0); //screen moves left thread.sleep(100); count++; } }catch(interruptedexception e ) { system.out.println("oops ho gya"); } } }
Comments
Post a Comment