Bonjour à tous,
Je débute en Java graces aux tutos et historiques des forums
Mais là, je butte sur un petit problème :
Lorsque je compile le code ci-dessous, j'ai une fenetre applet qui s'ouvre en plus de ma fenetre principale.
Savez-vous comment je peux procéder pour que cette applet vierge et inutile n'apparaisse plus ?
Par avance, merci pour votre aide,
Djipe
PS : Désolé si mon code n'est pas beau : je suis habitué à développer en assembleur...
Voilà mon code. Il me sert à envoyer des infos à mon serveur TCP/IP :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.DataOutputStream; import java.net.Socket; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.JLabel; public class ClientTCP1 extends Applet implements ActionListener{ public ClientTCP1() { } TextField text1; Button button1; JButton bouton; int click = 0; JLabel L_Etat; JTextField textField; public void init(){ JFrame fenetre = new JFrame("Client TCP - Connection à Djipe"); fenetre.setVisible(true); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); fenetre.getContentPane().add(panel); bouton = new JButton("Nb click : "); panel.add(bouton); L_Etat = new JLabel("New label"); panel.add(L_Etat); textField = new JTextField(); textField.setAlignmentX(Component.LEFT_ALIGNMENT); textField.setLocation(new Point(19, 17)); textField.setHorizontalAlignment(SwingConstants.LEFT); panel.add(textField); textField.setColumns(10); bouton.addActionListener(this); fenetre.setSize(500,300); } // methods needed for actionlistener Interface public void actionPerformed(ActionEvent e){ // declare and initialise a string to be shown click++; String message = " You clicked the button. woo hoo" + click; // if the source of the action is the button // ie if the button is clicked if(e.getSource() == button1){ // set the text of the textfield to our message text1.setText(message); } if(e.getSource() == bouton){ try { Socket clientSocket = new Socket("192.168.1.2", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); outToServer.writeBytes("Click" + click + '\n'); L_Etat.setText("Connecté."); } catch(Exception ee) { L_Etat.setText("Problème de connection."); } // set the text of the textfield to our message textField.setText("coucou - " + click); } } }
Partager