Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1001309 // Desktop: Leo's emoticons (include)

JavaX fragment (include)

  !636
  !actionListener {

  static boolean showPicture = true; // global switch. if false, you get the normal text display instead of the smiley
  
  static L<S> emotions = litlist(
    "#1001283", "happy",
    "#1001284", "unhappy",
    "#1001285", "oh",
    "#1001286", "bored",
    "#1001287", "wide mouth");
    
  static int borderColor = 0xFFFFFFFF;
  static S lastEmotion;
  static JFrame emo_frame;
  static ImageSurface img;
  static JTextField textField;
    
  static void emo(S emotion) {
    if (!showPicture) return;
    if (emo_frame == null) {
      emo_frame = new JFrame("Leo vx");
      
      img = new ImageSurface();
      img.setImage(loadImage(emotions.get(0)));
      textField = new JTextField();
      textField.addActionListener(actionListener {
        textField.selectAll();
        handleText(textField.getText());
      });
      
      emo_frame.getContentPane().setLayout(new BorderLayout);
      emo_frame.getContentPane().add(BorderLayout.CENTER, img);
      emo_frame.getContentPane().add(BorderLayout.SOUTH, textField);
      
      emo_frame.pack();
      centerFrame(emo_frame);
      emo_frame.setVisible(true);
    }
    int i;
    for (i = 0; i < emotions.size(); i += 2)
      if (emotions.get(i+1).equalsIgnoreCase(emotion))
        break;
    if (i >= emotions.size()) {
      print("Emotion not found: " + emotion);
      // use the last one from the list as default
      i -= 2;
    }
    lastEmotion = emotions.get(i+1);
    img.setImage(loadImage(emotions.get(i)));
  }
  
  static void setBorderColor(int color) {
  }
      
  static void happy() { emo("happy"); }
  static void unhappy() { emo("unhappy"); }
  static void oh() { emo("oh"); }
  static void bored() { emo("bored"); }
  static void wideMouth() { emo("wide mouth"); }
  
  static void disappear() {
    happy();
    if (emo_frame != null) {
      emo_frame.dispose();
      emo_frame = null;
    }
    swingLater(1000, runnable {
      img.setImage((RGBImage) null);
      swingLater(1000, runnable {
        System.exit(0);
      });
    });
  }
  

Author comment

Began life as a copy of #1001293

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001309
Snippet name: Desktop: Leo's emoticons (include)
Eternal ID of this version: #1001309/1
Text MD5: db43665b995a23e133537bcf49163400
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-09 17:24:19
Source code size: 2143 bytes / 74 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 547 / 737
Referenced in: [show references]