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

55
LINES

< > BotCompany Repo | #1035473 // JOnScreenKeyboard

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8132L/46K).

sclass JOnScreenKeyboard extends JPanel {
  JPanel[] panel;
  JButton[][] button;
  
  event keyPressed(S key);
  
  static final S[][] key = {
    {"Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9",
        "F10", "F11", "F12", "PrtSc", "Insert", "Delete", "Home",
        "End", "PgUp", "PgDn"}, {"3\n2", "&", "é", "\"", "'", "(",
        "§", "è", "!", "ç", "à", ")", "-", "BkSpc", "NumLock", "/",
        "*", "-"}, {"Tab", "A", "Z", "E", "R", "T", "Y", "U", "I",
        "O", "P", "^", "$", "Enter", "7", "8", "9", "+"},
    {"ShiftLock",
        "Q", "S", "D", "F", "G", "H", "J", "K", "L", "M", "ù", "µ",
        "4", "5", "6"}, {"Shift", "<", "W", "X", "C", "V", "B",
        "N", ",", ";", ":", "=", "Shift", "Up", "1", "2", "3", "Enter"},
    {"Ctrl", "Fn", "Win", "Alt", "Space", "AltGr", "Context",
        "Ctrl", "Left", "Down", "Right", "0", "."}
  };

  *() {
    init();
  }
  
  void init {
    setLayout(new GridLayout(0, 1));
    
    panel = new JPanel[6];
    for (int row = 0; row < key.length; row++) {
        panel[row] = new JPanel();
        button = new JButton[20][20];
        for (int column = 0; column < key[row].length; column++) {
            button[row][column] = new JButton(key[row][column]);
            //button[row][column].putClientProperty("column", column);
            //button[row][column].putClientProperty("row", row);
            button[row][column].putClientProperty("key", key[row][column]);
            button[row][column].addActionListener(e -> {
              JButton btn = cast e.getSource();
              S key = cast btn.getClientProperty("key");
              _print("JOnScreenKeyboard key pressed: " + key);
              keyPressed(key);
            });
            panel[row].add(button[row][column]);
        }
        add(panel[row]);
    }
  }
  
  JScrollPane withScrollPane() {
    var sp = jscroll_borderless_center(this);
    onFirstResize(sp, -> scrollToCenter(sp));
    ret sp;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035473
Snippet name: JOnScreenKeyboard
Eternal ID of this version: #1035473/7
Text MD5: 37ddcabd9601eeff4f1fb92db6f10aab
Transpilation MD5: 4cb277c39e62d3fc0cd4003b1ef80ac9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-22 22:09:17
Source code size: 2026 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 262
Version history: 6 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)