// Processed by NMI's Java Code Viewer 4.8.2 © 1997-2000 B. Lemaire // Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com // Copy registered to Evaluation Copy // Source File Name: ChatArea.java import java.awt.*; import symantec.itools.awt.SplitterPanel; class ChatArea extends Panel { private SplitterPanel splitterPanel1; TextField msgInput; static TextArea messages = new TextArea("Welcome to Scrabble\n", 1, 10); static List choice; private static int listIndex[]; String defaultFont; Color defaultFontColor; int defaultFontSize; Color defaultBackgroundColor; int defaultFontStyle; Color defaultChatAreaBackground; String font; Color fontColor; int fontSize; Color backgroundColor; int fontStyle; Color chatAreaBackground; Component target; public ChatArea(Component component) { msgInput = new TextField(); defaultFont = "Dialog"; defaultFontColor = Color.blue; defaultFontSize = 14; defaultBackgroundColor = Color.white; defaultChatAreaBackground = Color.lightGray; target = component; choice.addItem("All Players"); choice.select(0); splitterPanel1 = new SplitterPanel(1); splitterPanel1.setLayout(null); splitterPanel1.setBdrSizes(1, 1); splitterPanel1.use3dBdr = true; splitterPanel1.getLeftPanel().setMinimumSize(new Dimension(350, 0)); splitterPanel1.getLeftPanel().setPreferredSize(new Dimension(350, 0)); splitterPanel1.getRightPanel().setMinimumSize(new Dimension(0, 0)); splitterPanel1.getRightPanel().setPreferredSize(new Dimension(50, 0)); Panel panel = new Panel(); panel.setLayout(new GridLayout(1, 1)); panel.add(messages); Panel panel1 = new Panel(); panel1.setLayout(new GridLayout(1, 1)); panel1.setBackground(Color.lightGray); panel1.add(choice); splitterPanel1.getLeftPanel().add(panel); splitterPanel1.getRightPanel().add(panel1); setLayout(new GridBagLayout()); GridBagLayout gridbaglayout = (GridBagLayout)getLayout(); GridBagConstraints gridbagconstraints = new GridBagConstraints(); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = 0; gridbagconstraints.fill = 1; GridBagConstraints gridbagconstraints1 = new GridBagConstraints(); gridbagconstraints1.gridx = 0; gridbagconstraints1.gridy = 1; gridbagconstraints1.fill = 1; gridbagconstraints1.insets = new Insets(0, 3, 0, 3); GridBagConstraints gridbagconstraints2 = new GridBagConstraints(); gridbagconstraints2.gridx = 0; gridbagconstraints2.gridy = 2; gridbagconstraints2.fill = 1; GridBagConstraints gridbagconstraints3 = new GridBagConstraints(); gridbagconstraints3.gridx = 0; gridbagconstraints3.gridy = 3; gridbagconstraints3.fill = 1; gridbagconstraints3.weightx = 1.0D; gridbagconstraints3.weighty = 1.0D; gridbagconstraints3.insets = new Insets(0, 3, 3, 3); Label label = new Label("Send..."); Label label1 = new Label("Messages :"); messages.setEditable(false); gridbaglayout.setConstraints(label, gridbagconstraints); gridbaglayout.setConstraints(msgInput, gridbagconstraints1); gridbaglayout.setConstraints(label1, gridbagconstraints2); gridbaglayout.setConstraints(splitterPanel1, gridbagconstraints3); font = defaultFont; fontColor = defaultFontColor; fontSize = defaultFontSize; backgroundColor = defaultBackgroundColor; fontStyle = defaultFontStyle; chatAreaBackground = defaultChatAreaBackground; applyLook(); add(label); add(msgInput); add(label1); add(splitterPanel1); } public void applyLook() { Font font1 = new Font(font, fontStyle, fontSize); messages.setFont(font1); msgInput.setFont(font1); choice.setFont(font1); messages.setForeground(fontColor); msgInput.setForeground(fontColor); choice.setForeground(fontColor); messages.setBackground(backgroundColor); msgInput.setBackground(backgroundColor); choice.setBackground(backgroundColor); setBackground(chatAreaBackground); } public static void addText(String s, int i) { messages.appendText(s + "\n"); } public static int getSelected() { if(choice.getSelectedIndex() == 0) return -1; else return listIndex[choice.getSelectedIndex() - 1]; } public static void updateChoiceList() { int i; if(choice.getSelectedIndex() != 0) { if(ClientData.connected[listIndex[choice.getSelectedIndex() - 1]]) i = listIndex[choice.getSelectedIndex() - 1]; else i = -1; } else { i = -1; } choice.clear(); choice.addItem("All Players"); int j = 0; for(int k = 0; k < C.MAX_NUM_OF_PLAYERS; k++) { listIndex[k] = 0; if(ClientData.connected[k]) { listIndex[j] = k; choice.addItem(ClientData.nicks[k], j + 1); if(k == i) choice.select(j + 1); j++; } } if(i == -1) choice.select(0); } public synchronized void validate() { super.validate(); messages.appendText(""); } public boolean handleEvent(Event event) { if(event.id == 1001 && event.target == msgInput) { if(ClientData.amI_Connected) { if(choice.getSelectedIndex() != 0) target.handleEvent(new Event(this, 1001, new Mail(msgInput.getText(), listIndex[choice.getSelectedIndex() - 1]))); else target.handleEvent(new Event(this, 1001, new Mail(msgInput.getText(), 129))); msgInput.setText(""); } else { msgInput.setText(""); } return true; } else { return false; } } static { choice = new List(C.MAX_NUM_OF_PLAYERS, false); listIndex = new int[C.MAX_NUM_OF_PLAYERS]; } }