From 8fa67d594cec56a4fe0e22b1659887ac2891c26d Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Fri, 9 Feb 2024 22:00:26 +0100 Subject: [PATCH] refactoring: EmojiPicker --- src/main/java/EmojiPicker.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/EmojiPicker.java b/src/main/java/EmojiPicker.java index 73bb1db..ad93e6a 100644 --- a/src/main/java/EmojiPicker.java +++ b/src/main/java/EmojiPicker.java @@ -3,16 +3,19 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - public class EmojiPicker extends JPanel { - - private static final String[] emojis = {"😀", "😃", "😄", "😁", "😆", "😅", "😂", "🤣", "😊", "😇", "🙂", "🙃"}; + private JTextField textField; + private static final String[] emojis = {"😀", "😃", "😄", "😁", "😆", "😅", + "😂", "🤣", "😊", "😇", "🙂", "🙃"}; + + + public EmojiPicker(JTextField textField) { - setLayout(new GridLayout(4, 3, 5, 5)); + for (String emoji : emojis) { JButton emojiButton = new JButton(emoji); emojiButton.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20)); @@ -21,7 +24,6 @@ public class EmojiPicker extends JPanel { } setPreferredSize(new Dimension(300, 200)); - } private class EmojiActionListener implements ActionListener { @@ -34,11 +36,11 @@ public class EmojiPicker extends JPanel { @Override public void actionPerformed(ActionEvent e) { - System.out.println("Selected emoji: " + emoji); textField.setText(textField.getText() + emoji); + } } - }} +}