From edd14a58242d36fb567b12fb23dd1f028cdcf1d1 Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Fri, 9 Feb 2024 22:04:25 +0100 Subject: [PATCH] refactoring: EmojiPicker3 --- src/main/java/EmojiPicker.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/EmojiPicker.java b/src/main/java/EmojiPicker.java index 8d9f330..85c1f21 100644 --- a/src/main/java/EmojiPicker.java +++ b/src/main/java/EmojiPicker.java @@ -20,19 +20,20 @@ public class EmojiPicker extends JPanel { * @param textField The JTextField to append selected emojis. */ public EmojiPicker(JTextField textField) { - setLayout(new GridLayout(4, 3, 5, 5)); - + setLayout(new GridLayout(4, 3, 5, 5)); // Set grid layout for the emoji buttons + // Create and add buttons for each emoji for (String emoji : emojis) { JButton emojiButton = new JButton(emoji); - emojiButton.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20)); - emojiButton.addActionListener(new EmojiActionListener(emoji)); - add(emojiButton); + emojiButton.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20)); // Set font for emoji buttons + emojiButton.addActionListener(new EmojiActionListener(emoji)); // Add action listener to each button + add(emojiButton); // Add emoji button to the panel } - setPreferredSize(new Dimension(300, 200)); + setPreferredSize(new Dimension(300, 200)); // Set preferred size for the EmojiPicker panel } + private class EmojiActionListener implements ActionListener { private String emoji;