gpt4 book ai didi

java - JPanel KeyListener 不工作

转载 作者:行者123 更新时间:2023-11-29 06:38:52 26 4
gpt4 key购买 nike

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class AnaPencere{
JFrame pen;
AnaPencere(){
pen = new JFrame("Ana Pencere");
pen.setSize(613, 253);
pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pen.setLocationRelativeTo(null);
pen.setResizable(false);
pen.add(new Cizim());
pen.setVisible(true);
}


private class Cizim extends JPanel{

private Cizim() {
this.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println(e.getKeyCode());
}
});
}
}
}

当我运行项目时,一切都按预期工作,但是当我按下某个键时,我在控制台中看不到预期的结果

最佳答案

关于java - JPanel KeyListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15599748/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com