程序编译没错就是运行后没有反应.实在是不知道该怎么做了.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class test extends JFrame{
JPanel pl;
public test()
{
pl=new JPanel();
this.setLayout(null);
pl.setBounds(50,50,60,60);
pl.setBackground(Color.red);
this.getContentPane().add(pl);
this.setTitle("练习");
this.addKeyListener(new KeyAdapter()
{
public void pl_keyPressed(KeyEvent e){
if(e.getKeyCode()==39){
System.out.println("213");
pl.setLocation(pl.getLocation().x,pl.getLocation().y+10);
}
}
});
}
public static void main(String arg[]){
test ts=new test();
ts.setBounds(200,100,300,300);
ts.show();
}
}
[此贴子已经被作者于2007-7-19 22:00:13编辑过]
----------------解决方案--------------------------------------------------------
去掉pl_
----------------解决方案--------------------------------------------------------
我试了你的程序,为什么会有提示说:
test.java 中使用或覆盖了已过时的 API
要了解详细信息,请使用 -Xlint:deprecation 重新编译
----------------解决方案--------------------------------------------------------
因为show()过时了 应该用setVisible(true);
----------------解决方案--------------------------------------------------------
ts.show();
改成ts.setVisible(true);
[此贴子已经被作者于2007-7-20 12:17:53编辑过]
----------------解决方案--------------------------------------------------------
2楼的女侠说对了,把pl_去掉就可以了.
----------------解决方案--------------------------------------------------------
改过了以后,还是会出现错误!我也是一位Java的初学者,请高手指教!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class test extends JFrame{
JPanel pl;
public test()
{
pl=new JPanel();
this.setLayout(null);
pl.setBounds(50,50,60,60);
pl.setBackground(Color.red);
this.getContentPane().add(pl);
this.setTitle("ϰ");
this.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e){
if(e.getKeyCode()==39){
System.out.println("213");
pl.setLocation(pl.getLocation().x,pl.getLocation().y+10);
}
}
});
}
public static void main(String arg[]){
test ts=new test();
ts.setBounds(200,100,300,300);
ts.setVisible(true);
}
}
会出现以下错误:错误在附件中!
[此贴子已经被作者于2007-7-24 20:00:16编辑过]
----------------解决方案--------------------------------------------------------
楼上的把("ϰ") 改一下
----------------解决方案--------------------------------------------------------
this.setTitle("test");
改了也没用,同样的错误!!
难道是我的编译器有问题,不过我以前用都是好的啊!!
----------------解决方案--------------------------------------------------------