Click here to Skip to main content
15,889,512 members
Home / Discussions / Java
   

Java

 
QuestionThread Creation Pin
Sarita S9-Mar-15 23:21
Sarita S9-Mar-15 23:21 
AnswerRe: Thread Creation Pin
Richard MacCutchan10-Mar-15 21:51
mveRichard MacCutchan10-Mar-15 21:51 
AnswerRe: Thread Creation Pin
Eli Zaslavchik13-Apr-15 3:11
Eli Zaslavchik13-Apr-15 3:11 
QuestionMethod Calling Pin
William O'Neil9-Mar-15 7:05
William O'Neil9-Mar-15 7:05 
AnswerRe: Method Calling Pin
Richard MacCutchan9-Mar-15 7:56
mveRichard MacCutchan9-Mar-15 7:56 
GeneralRe: Method Calling Pin
William O'Neil9-Mar-15 8:35
William O'Neil9-Mar-15 8:35 
GeneralRe: Method Calling Pin
Richard MacCutchan9-Mar-15 8:40
mveRichard MacCutchan9-Mar-15 8:40 
QuestionNeed Help Adding Image onto Applet Pin
VietAnh1627-Mar-15 10:09
VietAnh1627-Mar-15 10:09 
I'm having problem adding an image to my applet. Can someone tell me what I did wrong??

Errors in Second Class
URL Cannot Be resolved to a type. Line 10/14/15

First Class
Java
import java.applet.*;
import java.awt.*;
public class MainClass extends Applet implements Runnable {

	private static final long serialVersionUID = 1L;
	Thread thread = new Thread(this);
	boolean running=true;
	Player p;
	Image dbImage;
	Graphics dbg;
	public void init()
	{
		setSize(800,800);
		p = new Player(this);
	}
	public void start(){thread.start();}
	public void destroy(){running=false;}
	public void stop(){running=false;}
	public void run()
	{
		while(running)
		{
			repaint();
			p.update(this);
			try
			{
				Thread.sleep(5);
				
			}
			catch(InterruptedException e)
			{
				System.out.println("ERROR HAS OCCURED");
		}
		}
		
		}
	public void update(Graphics g){
		dbImage = createImage(400,400);
		dbg = dbImage.getGraphics();
		paint(dbg);
		g.drawImage(dbImage,0,0,this);
	}
	public void paint(Graphics g){
			p.paint(g, this);
		}
	}


Second Class
Java
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Player implements KeyListener {
	private int x=200;
	private int y=200;
	private int radius=20;
	private int velX=0;
	private int velY=0;
	private URL url;
	private Image player;
	
	public Player(MainClass mc){
		url = mc.getDocumentBase();
		player = mc.getImage(url,"mario.jpg");
	}
	
	public void update(MainClass mc){
		mc.addKeyListener(this);
		x+=velX;
		y+=velY;
	}
	public void paint(Graphics g, MainClass mc){
	g.drawImage(player, x, y, mc);
	}
	@Override
	public void keyTyped(KeyEvent e) {
	
		
	}
	@Override
	public void keyPressed(KeyEvent e) {
		switch(e.getKeyCode()){
		case KeyEvent.VK_RIGHT:{
			velX=5;
			break;
		}
		case KeyEvent.VK_LEFT:{
			velX=-5;
			break;
		}
		case KeyEvent.VK_UP:{
			velY=-5;
			break;
		}
		case KeyEvent.VK_DOWN:{
			velY=5;
			break;
		}
		
		}
		
		
	}
	@Override
	public void keyReleased(KeyEvent e) {
		switch(e.getKeyCode()){
		case KeyEvent.VK_RIGHT:{
			velX=0;
			break;
		}
		case KeyEvent.VK_LEFT:{
			velX=-0;
			break;
		}
		case KeyEvent.VK_UP:{
			velY=-0;
			break;
		}
		case KeyEvent.VK_DOWN:{
			velY=0;
			break;
		}
		
	}
		
	}

}

AnswerRe: Need Help Adding Image onto Applet Pin
Richard MacCutchan7-Mar-15 22:17
mveRichard MacCutchan7-Mar-15 22:17 
AnswerRe: Need Help Adding Image onto Applet Pin
PeraDll14-Mar-15 9:42
PeraDll14-Mar-15 9:42 
Question7 Pin
VietAnh1626-Mar-15 15:44
VietAnh1626-Mar-15 15:44 
AnswerRe: Need Help Adding Image onto Applet Pin
Richard MacCutchan6-Mar-15 21:43
mveRichard MacCutchan6-Mar-15 21:43 
QuestionMAC theme used at java interface in Windows Pin
Member 115037696-Mar-15 3:10
Member 115037696-Mar-15 3:10 
AnswerRe: MAC theme used at java interface in Windows Pin
Richard MacCutchan6-Mar-15 6:35
mveRichard MacCutchan6-Mar-15 6:35 
QuestionSoftware Architekture With Design Pattern Pin
Member 114986694-Mar-15 7:03
Member 114986694-Mar-15 7:03 
AnswerRe: Software Architekture With Design Pattern Pin
jschell4-Mar-15 9:06
jschell4-Mar-15 9:06 
Questionabout java program for vfdt algorithm in data stream Pin
Member 114432123-Mar-15 22:28
Member 114432123-Mar-15 22:28 
AnswerRe: about java program for vfdt algorithm in data stream Pin
Richard MacCutchan3-Mar-15 22:58
mveRichard MacCutchan3-Mar-15 22:58 
Questionis there a better way to remove the last digit of a number and see if the remainder of the remaining digits is the same as the removed digit. [Solved] Pin
Khuthadzo Tshikotshi3-Mar-15 20:27
professionalKhuthadzo Tshikotshi3-Mar-15 20:27 
AnswerRe: is there a better way to remove the last digit of a number and see if the remainder of the remaining digits is the same as the removed digit. Pin
Richard MacCutchan3-Mar-15 23:04
mveRichard MacCutchan3-Mar-15 23:04 
GeneralRe: is there a better way to remove the last digit of a number and see if the remainder of the remaining digits is the same as the removed digit. Pin
Khuthadzo Tshikotshi4-Mar-15 19:40
professionalKhuthadzo Tshikotshi4-Mar-15 19:40 
QuestionGetting SQL Exception ORA-08103: object no longer exists in java Pin
Abhi_aec2-Mar-15 1:27
Abhi_aec2-Mar-15 1:27 
AnswerRe: Getting SQL Exception ORA-08103: object no longer exists in java Pin
Richard MacCutchan2-Mar-15 2:34
mveRichard MacCutchan2-Mar-15 2:34 
GeneralRe: Getting SQL Exception ORA-08103: object no longer exists in java Pin
Abhi_aec2-Mar-15 23:23
Abhi_aec2-Mar-15 23:23 
GeneralRe: Getting SQL Exception ORA-08103: object no longer exists in java Pin
Richard MacCutchan2-Mar-15 23:35
mveRichard MacCutchan2-Mar-15 23:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.