2 次元の JPanel テーブルを作成しました。最初のセルに JButton があります。矢印キーを使用してボタンをテーブルの境界内に移動したいです。すべてのセルまたはボタンに KeyListener を配置する必要がありますか?私の質問はばかげていると思いますが、KeyListener.Thank について少し助けが必要です!!
これが私が書いたコードです!
public class MyFrame extends JFrame {
JPanel [][] innerCells;
public MyFrame() {
JFrame fr = new JFrame("Final Exams");
fr.setSize(800, 600);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setVisible(true);
fr.setLocationRelativeTo(null);
JPanel p = new JPanel(new GridLayout(10, 10));
JButton b = new JButton("G");
innerCells = new JPanel[10][10];
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
innerCells[i][j] = new JPanel();
innerCells[i][j].setBorder(BorderFactory.createLineBorder(Color.orange));
p.add(innerCells[i][j]);
}
}
innerCells[0][0].add(b);
fr.add(p);
}