34. 小雪の降る中
2011/01/20
コメントを残す
33. Clojure: Big EndianとLittle Endianのデータファイルを作成
2010/12/27
コメントを残す
clojureでファイル解析を行う練習をしてみたいので、簡単にテストデータを作っておく。pythonで。
#!/usr/bin/env python from __future__ import with_statement from struct import pack #Little Endian with file("little-endian.dat", "w") as f: f.write(pack('<H', 0x1234)) f.write(pack('<I', 0x12345678)) # Big Endian with file("big-endian.dat", "w") as f: f.write(pack('>H', 0x1234)) f.write(pack('>I', 0x12345678))
32. Clojure: javax.swing.JList を使う
2010/12/25
コメントを残す
Swingの部品を使う練習 その1
;; javax.swing.JList sample (import '(javax.swing JFrame JPanel JOptionPane JScrollPane JList)) (import '(javax.swing.event ListSelectionListener)) (import '(java.awt Dimension BorderLayout)) (defn msgbox [frame msg] (JOptionPane/showMessageDialog frame msg "Info" JOptionPane/INFORMATION_MESSAGE)) (let [data ["Blue" "Green" "Red" "White" "Black"] list (JList. (into-array data)) frame (JFrame.) scrollpane (JScrollPane.) panel (JPanel.)] (.addListSelectionListener list (proxy [ListSelectionListener] [] (valueChanged [e] (let [idx (.getSelectedIndex list)] (msgbox frame idx))))) (.setView (.getViewport scrollpane) list) (.setPreferredSize scrollpane (Dimension. 200 80)) (.add panel scrollpane) (.add (.getContentPane frame) panel BorderLayout/CENTER) (.setDefaultCloseOperation frame JFrame/DISPOSE_ON_CLOSE) ; for running on SLIME ;; (.setDefaultCloseOperation frame JFrame/EXIT_ON_CLOSE) (.setTitle frame "javax.swing.JList sample") (.setBounds frame 10 10 250 130) (.setVisible frame true))