Ejemplo n.º 1
0
  public static void createAndShowGUI() throws IOException {
    JFrame frame = new JFrame("Emoticon");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String emote = getEmote(-1);
    Emoticon e = new Emoticon(emote);

    ByteArrayInputStream input = new ByteArrayInputStream(e.getPNG());
    BufferedImage bimg = ImageIO.read(input);

    final BufferedImage image = bimg;
    Canvas canvas;
    frame.add(
        canvas =
            new Canvas() {
              @Override
              public void paint(Graphics g) {
                super.paint(g);
                g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
              }
            });
    canvas.setSize(e.bimg.getWidth(), e.bimg.getHeight());

    frame.pack();
    frame.setVisible(true);
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    if (args.length > 0) {
      String[] vars = args[0].split("\\?");
      String s = vars[0];

      if (s.equalsIgnoreCase("jp")) {
        FONT = FONT2;
      }

      if (s.equalsIgnoreCase("test")) {
        System.out.println("Test");
      } else if (s.equalsIgnoreCase("print")) {
        try {
          System.out.write("Text Print Test".getBytes());
          System.out.flush();
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else {
        try {
          String emote = URLDecoder.decode(vars[vars.length - 1], "UTF-8");
          Emoticon e = new Emoticon(emote);
          // write the bytes to the output stream
          System.out.write(e.getPNG());
          System.out.flush();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
      }
    } else { // no args
      try {
        if (GraphicsEnvironment.isHeadless()) {
          Emoticon e = new Emoticon(getEmote(-1)); // random emote
          // write the bytes to the output stream
          System.out.write(e.getPNG());
          System.out.flush();
        } else {
          // not in headless mode, show gui
          createAndShowGUI();
          System.out.println("Showing gui");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }