java问题:为什么我的这个程序不能实现面板上的那张图片,当按下键盘上的s键时,图标不移动??
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassBuJu15extendsJ...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BuJu15 extends JFrame {
Mypanel mp;
public static void main(String[] args) {
// TODO Auto-generated method stub
BuJu15 shi=new BuJu15();
}
public BuJu15(){
mp=new Mypanel();
this.addKeyListener(mp);
this.add(mp);
this.setSize(200,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage((new ImageIcon("src/Image/QQ.jpg")).getImage());
}
}
class Mypanel extends JPanel implements KeyListener{
public void paint(Graphics g){
super.paint(g);
g.fillOval(10,10,30,30);
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
int x=10,y=10;
if(e.getKeyChar()==115);
y=y+3;
repaint();
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
} 展开
import javax.swing.*;
import java.awt.event.*;
public class BuJu15 extends JFrame {
Mypanel mp;
public static void main(String[] args) {
// TODO Auto-generated method stub
BuJu15 shi=new BuJu15();
}
public BuJu15(){
mp=new Mypanel();
this.addKeyListener(mp);
this.add(mp);
this.setSize(200,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage((new ImageIcon("src/Image/QQ.jpg")).getImage());
}
}
class Mypanel extends JPanel implements KeyListener{
public void paint(Graphics g){
super.paint(g);
g.fillOval(10,10,30,30);
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
int x=10,y=10;
if(e.getKeyChar()==115);
y=y+3;
repaint();
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
} 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询