如何使用 keyTyped() 方法删除我的图块 class?

How to use keyTyped() method to remove my tile class?

这是我的瓷砖class:

public class Tile extends JLabel {

    public static Font font = new Font("Serif", Font.BOLD, 39);

    private static char _c;

    public Tile(char c, Color background) {
        setBackground(background);
        setOpaque(true);
        _c = c;
        setText(convert());
        setFont(font);
    }

    public static char randomLetter() {
        Random r = new Random();
        char randomChar = (char) (97 + r.nextInt(26));
        return randomChar;
    }

    public static Color randomColor() {
        Random rand = new Random();
        float r = rand.nextFloat();
        float g = rand.nextFloat();
        float b = rand.nextFloat();

        Color randomColor = new Color(r, g, b);
        return randomColor;
    }

    public static char getChar() {
        return _c;
    }

    public String convert() {
        return String.valueOf(getChar());
    }
}

我的 GUI class

public class Game implements KeyListener {

    public static Game game;

    private Model model;

    public Game() {
        model = new Model();

        for (int i = 0; i < 4; i++) {
            model.add(new Tile(Tile.randomLetter(), Tile.randomColor()));
        }

        JFrame frame = new JFrame();
        frame.getContentPane().setLayout(new GridLayout(4, 1));
        frame.setSize(500, 800);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        for (Tile tile : model.getTiles()) {
            frame.add(tile);
        }

        frame.getContentPane().addKeyListener(this);
        frame.getContentPane().setFocusable(true);
        frame.getContentPane().requestFocusInWindow();

    }

    @Override
    public void keyPressed(KeyEvent arg0) {
    }

    @Override
    public void keyReleased(KeyEvent e) {
    }

    @Override
    public void keyTyped(KeyEvent e) {
        if (model.getTiles(0).Tile.getChar == e.getKeyChar()) {
            System.out.println("YOU REMOVED A TILE!!!");
        }
        // model.removeByChar(e.getKeyChar());
    }

    public static void main(String[] args) {

        new Game();

    }
}

和我的模特class

public class Model {

    private ArrayList<Tile> list = new ArrayList<Tile>();

    public Model() {
    }

    public void add(Tile tile) {
        list.add(tile);
    }

    public ArrayList<Tile> getTiles() {
        return list;
    }
}

我试图在按下与图块字母相关的键时移除图块,但我不知道如何实现。

@Override
public void keyTyped(KeyEvent e) {
    for (Tile t : model.getTiles()) {
        if (t.getChar() == e.getKeyChar()) {
            System.out.println("YOU REMOVED A TILE!!!");
            frame.remove(t);
            frame.repaint();
        }
    }
    // model.removeByChar(e.getKeyChar());
}