Bonjour,
J'essaye de faire une petite console, mais j'ai un problème avec l'actualisation du JTextArea mais pourtant j'ai tout essayer (setText, revalidate, append...) mais sa change rien.
J'avais essayer de le JTextPane mais toujours le même problème
Pourtant mon code est correct
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 package modules; import modules.Command; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; public class Console extends JFrame{ private JPanel container = new JPanel(); private JButton entrer = new JButton("Entrer"); private JTextField jtf = new JTextField(""); protected JTextArea ecran_info = new JTextArea(); public void fenetre() { this.setTitle("Console"); this.setSize(400, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); container.setBackground(Color.white); container.setLayout(new BorderLayout()); ecran_info.setEditable(false); ecran_info.setText("Bienvenue dans la console"); JPanel sud = new JPanel(); sud.setLayout(new BoxLayout(sud, BoxLayout.LINE_AXIS)); jtf.setForeground(Color.BLACK); jtf.setPreferredSize( new Dimension(300, 30 ) ); sud.add(jtf); entrer.addActionListener(new Bouton()); sud.add(entrer); container.add(ecran_info, BorderLayout.CENTER); container.add(sud, BorderLayout.SOUTH); this.setContentPane(container); this.setVisible(true); } public void ajouter_texte(String message) { System.out.println("La variable 'message' : "+message); ecran_info.append(message); } class Bouton implements ActionListener { public void actionPerformed(ActionEvent arg0){ new Command(jtf.getText()); } } }Merci d'avance
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 package modules; import modules.Console; public class Command { Console console = new Console(); private String command[] = { "message" }; public Command(String text) { if(text.equals(command[0])) { System.out.println("Teste de la commande 'message'"); console.ajouter_texte(text); } else { System.out.println("Cette command n'existe pas"); } } }
Partager