这是我写的一个能运行的方法呀
public class FrameHWnd extends JFrame implements KeyListener{
static FrameHWnd frame;
JPanel pp1;
JButton jb3;
boolean pressedQ=true;
private FrameHWnd frm;
private static JPanel pl;
private SongChoicePanel gp;
static
{
System.loadLibrary( "swinggethwnd2 ");
}
public int getComponentHWnd(Component c)
{
int ret = getHWnd(c);
return ret;
}
public native int getHWnd(Component c);
JPanel jp;
JButton jb1;
JButton jb2;
public FrameHWnd(){
this.addKeyListener(new EventReceiter());
jb1=new JButton( "jbutton1 ");
jb2=new JButton( "jbutton2 ");
jb3=new JButton( "jbutton3 ");
jp=new JPanel();
add(jp);
jp.setBackground(Color.red);
//
jp.add(jb1);
jb1.addKeyListener(this);
jp.add(jb2);
jb1.setBounds(100, 200, 50, 50);
jb2.setBounds(100, 300, 50, 50);
//可以实现
this.removeAll();
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
frame=new FrameHWnd();
int windowID=frame.getComponentHWnd(frame);
new Quake3MapAndMd2Engine(windowID,1,1,1,1).playGame();
}
public void keyPressed(KeyEvent e) {
switch (e.getKeyChar() & 223) {
case KeyEvent.VK_Q :
pp1=new JPanel();
this.remove(jp);
this.add(pp1);
pp1.add(jb3);
jb3.setBounds(300, 300, 100, 50);
break;
default:
break;
}
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
这是一个JNI的调用,把我的主程序运行在这个Frame上并实现了键盘操作,但是下面我要进行界面的跳转,我写了一个小测试类,结果键盘就不听使唤了。,如下
public class FrameHWnd extends JFrame implements KeyListener{
static FrameHWnd frame;
JPanel pp1;
JButton jb3;
boolean pressedQ=true;