Browse Source

refactoring: EmojiPicker

remotes/origin/client-handler
Valentin Spiroski 11 months ago
parent
commit
8fa67d594c
  1. 14
      src/main/java/EmojiPicker.java

14
src/main/java/EmojiPicker.java

@ -3,16 +3,19 @@ import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
public class EmojiPicker extends JPanel { public class EmojiPicker extends JPanel {
private static final String[] emojis = {"😀", "😃", "😄", "😁", "😆", "😅", "😂", "🤣", "😊", "😇", "🙂", "🙃"};
private JTextField textField; private JTextField textField;
public EmojiPicker(JTextField textField) {
private static final String[] emojis = {"😀", "😃", "😄", "😁", "😆", "😅",
"😂", "🤣", "😊", "😇", "🙂", "🙃"};
public EmojiPicker(JTextField textField) {
setLayout(new GridLayout(4, 3, 5, 5)); setLayout(new GridLayout(4, 3, 5, 5));
for (String emoji : emojis) { for (String emoji : emojis) {
JButton emojiButton = new JButton(emoji); JButton emojiButton = new JButton(emoji);
emojiButton.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20)); emojiButton.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 20));
@ -21,7 +24,6 @@ public class EmojiPicker extends JPanel {
} }
setPreferredSize(new Dimension(300, 200)); setPreferredSize(new Dimension(300, 200));
} }
private class EmojiActionListener implements ActionListener { private class EmojiActionListener implements ActionListener {
@ -34,11 +36,11 @@ public class EmojiPicker extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Selected emoji: " + emoji); System.out.println("Selected emoji: " + emoji);
textField.setText(textField.getText() + emoji); textField.setText(textField.getText() + emoji);
}
} }
}}
}

Loading…
Cancel
Save