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

56
LINES

< > BotCompany Repo | #1000966 // Dialog in a fancy font

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2476L/17K/58K).

!752

static JTextArea textArea;
static float fontSize = 24f;
static S fontSnippet =
  //"#1000967" // a TrueType font (works, but no punctuation)
  //"#1000969" // an OpenType font (works! but hard to read)
  //"#1000970"
  //"#1004887" // the great Akashi
  "#1004889";

static Font loadFont() ctex {
  return Font.createFont(Font.TRUETYPE_FONT, loadLibrary(fontSnippet)).deriveFont(fontSize);
}

p {
  textArea = new JTextArea();
  textArea.setFont(loadFont());
  textArea.setMargin(new Insets(10, 10, 10, 10));
  
  textArea.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == 0) {
        enterPressed();
      }
    }
  });
  
  makeFrame("Dialog", new JScrollPane(textArea));
  sleep(); // important for auto-logging as of now
}

static void enterPressed() {
  S text = textArea.getText();
  int idx = textArea.getCaretPosition();
  
  // move to end of line first
  while (idx < text.length() && text.charAt(idx) != '\n') ++idx;
  textArea.setCaretPosition(idx);
  
  //print(quote(text.substring(0, idx)));
  int lineStart = text.lastIndexOf("\n", idx-1);
  //print(lineStart + " " + idx);
  S line = text.substring(lineStart+1, idx);
  print("?? " + line);
  processLine(line);
}

static void processLine(S line) {
  type(line + "??");
}

static void type(S bla) {
  print("!! " + bla);
  textArea.insert("\n" + bla, textArea.getCaretPosition());
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000966
Snippet name: Dialog in a fancy font
Eternal ID of this version: #1000966/1
Text MD5: 2e402ee27f3a0955486af6f1d8f67c40
Transpilation MD5: 3c5812d0f68ddbcea9089dbdb8d59b41
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-13 06:20:06
Source code size: 1507 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 549 / 578
Referenced in: [show references]