Вот кусочки кода , если есть вопросы , пожалуйста  Не даю весь код потому как ето 900 строк , чат всего лишь маленькое добавление к программе
| Код | result = new JTextArea(3, 50);
result.setCaretPosition(result.getDocument().getLength()); result.setEditable(false); result.setAlignmentX(Component.LEFT_ALIGNMENT); result.setBackground(Color.lightGray); result.setForeground(new Color(0, 0, 204)); result.setBorder(new TitledBorder(new EtchedBorder(), "Dialog"));
JScrollPane scrollPane = new JScrollPane(result, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // 0,6 AreaView = new JViewport(); AreaView.setView(result); scrollPane.setViewport(AreaView); //... //--------------------------- connect = new JButton("Send"); connect.setMnemonic('S'); connect.addActionListener(this); //... //------------------------------------ inputArea = new JTextArea(3, 50); inputArea.setAlignmentX(Component.LEFT_ALIGNMENT); inputArea.setBackground(Color.lightGray); inputArea.setForeground(new Color(204,0,0)); inputArea.setBorder(new TitledBorder(new EtchedBorder(), "Enter your message"));
scrollPane = new JScrollPane(inputArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // 0,7 //... //--------------------------------- public class BroadcastHandler extends Thread { BufferedReader broadcastReader;
public BroadcastHandler() { try { broadcastReader = new BufferedReader( new InputStreamReader(server.getInputStream())); } catch (IOException e){;}//scrollPanel(); } public void run() { String line; try{ while ((line=broadcastReader.readLine())!= null) { result.append(line+"\n"); } } catch (IOException e) {;}//scrollPanel(); } } //---------------------------- public void ChatFrame(String host) { try { server = new Socket(host,5454); pw = new PrintWriter(server.getOutputStream(), true); } catch(IOException e) { System.out.println("problem connecting to server"); } } //---------------------------- public void actionPerformed(ActionEvent evt) { pw.println(inputArea.getText()); inputArea.setText(""); scrollPanel(); }
| |