gens546 | Bonsoir,
Je suis actuellement sur un projet de Chat IRC, j'ai créé l'interface et à coté on m'a donné un code de base pour les gérer les sockets, thread qui renvoi tout en mode console. Du coup, je dois remplacer les entrées/sorties vers mon interface. Sauf que c'est là qu'apparaît le problème.
Voici le code de l'interface
Code :
- public class AppChatClient2 extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- private JFrame frame;
- private ChatServer leServeur;
- private ChatClient leClient;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- AppChatClient2 frame = new AppChatClient2();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public AppChatClient2() {
- leServeur = new ChatServer(4444);
- leClient = new ChatClient("localhost", 4444);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- GridBagLayout gbl_contentPane = new GridBagLayout();
- gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_contentPane.columnWeights = new double[]{1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- contentPane.setLayout(gbl_contentPane);
- JSplitPane splitPane = new JSplitPane();
- GridBagConstraints gbc_splitPane = new GridBagConstraints();
- gbc_splitPane.insets = new Insets(0, 0, 5, 0);
- gbc_splitPane.gridheight = 6;
- gbc_splitPane.gridwidth = 9;
- gbc_splitPane.fill = GridBagConstraints.BOTH;
- gbc_splitPane.gridx = 0;
- gbc_splitPane.gridy = 1;
- contentPane.add(splitPane, gbc_splitPane);
- JList list_1 = new JList();
- list_1.setModel(new AbstractListModel() {
- String[] values = new String[] {"Connect\u00E9(s)"};
- public int getSize() {
- return values.length;
- }
- public Object getElementAt(int index) {
- return values[index];
- }
- });
- list_1.setToolTipText("" );
- splitPane.setLeftComponent(list_1);
- final JTextArea textArea = new JTextArea();
- splitPane.setRightComponent(textArea);
- textField = new JTextField();
- GridBagConstraints gbc_textField = new GridBagConstraints();
- gbc_textField.gridwidth = 7;
- gbc_textField.insets = new Insets(0, 0, 0, 5);
- gbc_textField.fill = GridBagConstraints.HORIZONTAL;
- gbc_textField.gridx = 0;
- gbc_textField.gridy = 8;
- contentPane.add(textField, gbc_textField);
- textField.setColumns(10);
- JButton btnNewButton = new JButton("Send" );
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- textArea.setText(textArea.getText()+textField.getText()+'\n');
- }
- });
- GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
- gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
- gbc_btnNewButton.anchor = GridBagConstraints.EAST;
- gbc_btnNewButton.gridx = 7;
- gbc_btnNewButton.gridy = 8;
- contentPane.add(btnNewButton, gbc_btnNewButton);
- JButton btnNewButton_1 = new JButton("Leave" );
- btnNewButton_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- leClient.handle(".bye" );
- }
- });
- GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
- gbc_btnNewButton_1.gridx = 8;
- gbc_btnNewButton_1.gridy = 8;
- contentPane.add(btnNewButton_1, gbc_btnNewButton_1);
- }
- }
|
J'ai linké en ce qui concerne les sockets et threads sur ftp pour avoir un code complet : http://romaincointet.fr/java/
Merci d'avance |