| 25 | | new IRCConsole().test(); |
| | 39 | IRCConsole console = new IRCConsole(); |
| | 40 | console.createChatWindow(); |
| | 41 | // console.test(); |
| | 42 | } |
| | 43 | |
| | 44 | /** |
| | 45 | * チャットウインドウを作成します。 |
| | 46 | * |
| | 47 | * @return チャットウインドウのインスタンス |
| | 48 | */ |
| | 49 | public Window createChatWindow() |
| | 50 | { |
| | 51 | // 表示エリア |
| | 52 | final JTextPane textPane = new JTextPane(); |
| | 53 | textPane.setEditable(false); |
| | 54 | textPane.setPreferredSize(new Dimension(320, 240)); |
| | 55 | final StyledDocument doc = textPane.getStyledDocument(); |
| | 56 | final String LF = System.getProperty("line.separator"); |
| | 57 | |
| | 58 | // スクロールパネル |
| | 59 | JScrollPane scrollPane = new JScrollPane(textPane); |
| | 60 | scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
| | 61 | |
| | 62 | // 入力フィールド |
| | 63 | final JTextField textField = new JTextField(); |
| | 64 | textField.addActionListener(new ActionListener() |
| | 65 | { |
| | 66 | public void actionPerformed(ActionEvent evt) |
| | 67 | { |
| | 68 | try |
| | 69 | { |
| | 70 | // 入力テキストを取得 |
| | 71 | String str = evt.getActionCommand(); |
| | 72 | |
| | 73 | // 入力フィールドをクリア |
| | 74 | textField.setText(""); |
| | 75 | |
| | 76 | // 表示エリアに1行追加 |
| | 77 | AttributeSet style = null; |
| | 78 | doc.insertString(doc.getLength(), str + LF, style); |
| | 79 | // textPane.setCaretPosition(doc.getLength()); |
| | 80 | } |
| | 81 | catch (BadLocationException e) |
| | 82 | { |
| | 83 | e.printStackTrace(); |
| | 84 | } |
| | 85 | } |
| | 86 | }); |
| | 87 | |
| | 88 | // メインパネル |
| | 89 | JPanel mainPane = new JPanel(); |
| | 90 | mainPane.setLayout(new BorderLayout()); |
| | 91 | mainPane.add(scrollPane, BorderLayout.CENTER); |
| | 92 | mainPane.add(textField, BorderLayout.SOUTH); |
| | 93 | |
| | 94 | // ウインドウ |
| | 95 | JFrame frame = new JFrame(); |
| | 96 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| | 97 | frame.add(mainPane); |
| | 98 | frame.pack(); |
| | 99 | frame.setVisible(true); |
| | 100 | |
| | 101 | return frame; |