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

58
LINES

< > BotCompany Repo | #1000792 // Snippet search (Swing)

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

Libraryless. Click here for Pure Java version (319L/4K/12K).

!636
!modern // includes string ==
!actionListener {
!x619 // standard classes (LetterLayout, CenteredLine)
!multi-line strings

import java.awt.*;
import java.awt.event.*;
import java.util.List;

main {
  static JList list;
  static JTextField tfCmd;
  static new L<S> history;
  static int historyIdx;
  
  psvm {
    JFrame frame = new JFrame("Snippet Search");
    
    JPanel panel = new JPanel(new BorderLayout());
    
    list = new JList();
    panel.add(BorderLayout.CENTER, new JScrollPane(list));
    
    tfCmd = new JTextField();
    panel.add(BorderLayout.NORTH, tfCmd);
    
    tfCmd.addActionListener(actionListener {
      tfCmd.selectAll();
      String cmd = tfCmd.getText();
      runCmd(cmd);
    });
    
    frame.addWindowListener(new WindowAdapter() {
      public void windowOpened(WindowEvent e) {
        tfCmd.requestFocus();
      }
    }); 
    
    frame.add(panel);
    frame.setBounds(100, 100, 500, 400);
    frame.setVisible(true);
    exitOnFrameClose(frame);
    
    //runCmd(""); // find latest
  }
  
  static void runCmd(String cmd) ctex {
    if (cmd == "") cmd = "%";
    S page = loadPage("http://tinybrain.de:8080/tb/search.php?q=" + urlencode(cmd));
    Matcher m = Pattern.compile(">(#\\d+)</a> - (.*?)<br>").matcher(page);
    
    new DefaultListModel<S> model;
    while (m.find())
      model.addElement(htmldecode(m.group(1) + " - " + m.group(2)));
    list.setModel(model);
  }
}

Author comment

Began life as a copy of #1000690

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000792
Snippet name: Snippet search (Swing)
Eternal ID of this version: #1000792/1
Text MD5: 0478c6241e406ae24f2c94e6e08f49d0
Transpilation MD5: ae33065e6ee53e7dee55285b5598df2e
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-28 12:12:51
Source code size: 1492 bytes / 58 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 691 / 678
Referenced in: [show references]