M
mukesh
I want to develope standalone application by using java AWT in which an
image would move when down key pressed.
the code is as follows.
................................................
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
class event extends Frame implements KeyListener
{
Toolkit tk;
public Image ig;
Graphics g,g1;
event()
{
setLayout(null);
setSize(300,300);
// b=new Button();
//b.setBounds(20,20,30,30);
//add(b);
tk =Toolkit.getDefaultToolkit();
ig=tk.getImage("C:/pro/New Folder/Mukesh/sky.jpg");
ig.addKeyListener(this);
//addKeyListener(this);
setVisible(true);
}
public void keyPressed(KeyEvent ke) {
if(ke.getKeyCode()==KeyEvent.VK_DOWN)
{
paint(g1);
}
}
public void keyReleased(KeyEvent ke)
{
}
public void keyTyped(KeyEvent ke) {
}
public void paint(Graphics g)
{
g.drawImage(ig,100,100,40,40,this);
}
public static void main(String[] args)
{
event as=new event();
}
}
................................................
Afther compilation following error genrated :----
C:\pro\New Folder\Mukesh>javac event.java
event.java:22: cannot find symbol
symbol : method addKeyListener(event)
location: class java.awt.Image
ig.addKeyListener(this);
^
1 error
So, plz help me.
image would move when down key pressed.
the code is as follows.
................................................
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
class event extends Frame implements KeyListener
{
Toolkit tk;
public Image ig;
Graphics g,g1;
event()
{
setLayout(null);
setSize(300,300);
// b=new Button();
//b.setBounds(20,20,30,30);
//add(b);
tk =Toolkit.getDefaultToolkit();
ig=tk.getImage("C:/pro/New Folder/Mukesh/sky.jpg");
ig.addKeyListener(this);
//addKeyListener(this);
setVisible(true);
}
public void keyPressed(KeyEvent ke) {
if(ke.getKeyCode()==KeyEvent.VK_DOWN)
{
paint(g1);
}
}
public void keyReleased(KeyEvent ke)
{
}
public void keyTyped(KeyEvent ke) {
}
public void paint(Graphics g)
{
g.drawImage(ig,100,100,40,40,this);
}
public static void main(String[] args)
{
event as=new event();
}
}
................................................
Afther compilation following error genrated :----
C:\pro\New Folder\Mukesh>javac event.java
event.java:22: cannot find symbol
symbol : method addKeyListener(event)
location: class java.awt.Image
ig.addKeyListener(this);
^
1 error
So, plz help me.