Changeset 25708

Show
Ignore:
Timestamp:
12/02/08 21:57:42 (5 weeks ago)
Author:
tarchan
Message:

lang/java/IRCKit: チャットウインドウを追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/IRCKit/trunk/src/com/mac/tarchan/irc/client/IRCConsole.java

    r25703 r25708  
    88package com.mac.tarchan.irc.client; 
    99 
     10import java.awt.BorderLayout; 
     11import java.awt.Dimension; 
     12import java.awt.Window; 
     13import java.awt.event.ActionEvent; 
     14import java.awt.event.ActionListener; 
    1015import java.net.MalformedURLException; 
    1116import java.util.Properties; 
     17 
     18import javax.swing.JFrame; 
     19import javax.swing.JPanel; 
     20import javax.swing.JScrollPane; 
     21import javax.swing.JTextField; 
     22import javax.swing.JTextPane; 
     23import javax.swing.text.AttributeSet; 
     24import javax.swing.text.BadLocationException; 
     25import javax.swing.text.StyledDocument; 
    1226 
    1327/** 
     
    2337        public static void main(String[] args) 
    2438        { 
    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; 
    26102        } 
    27103