boujour a tous.
J ai ecris un petit prog en java et je me demandais si vous auriez des conseils pour le rendre plus propre.
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//definition de la classe de fenetre
 class CSuperSwing extends JFrame {
 
JButton m_OK,m_QUITTER;
JTextField m_text1,m_text2,m_text3;
JLabel m_info1,m_info2,m_info3,m_info4;
JTextArea m_info5;
 
 
 
 
//Gestion des evenements pour les elements de controle
class CMonEcouteurAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
//int i;
LongCorp sc = new LongCorp(m_text3.getText());
 
int LongueurDecimal;
LongueurDecimal=(sc.m_VraiLong);
System.out.println(LongueurDecimal);
if (((LongueurDecimal%2) ==0) && (m_text1.getText().length() == 4) && (LongueurDecimal >= 30))
 {  
       m_info5.setBackground(Color.green);
       m_info5.setText("C1 40 "+m_text1.getText() + " " + sc.ReturnValueHex()+" " + m_text2.getText()+" " +m_text3.getText());	
  }
      else if (((LongueurDecimal%2) ==0) && (m_text1.getText().length() == 4))
  {
       m_info5.setBackground(Color.green);
       m_info5.setText("C1 40 "+m_text1.getText() + " 0" + sc.ReturnValueHex()+" " +m_text2.getText()+" " +m_text3.getText());	
  }
      else 
  {
         m_info5.setBackground(Color.red);
         m_info5.setText("Erreur: parametre incorrect!!!!");
   }
 
 
}
}
 
 //constructeur
 CSuperSwing(String titre) {
 super(titre);
 
 //creations des boutons
 m_OK = new JButton("OK");
 m_QUITTER = new JButton("QUITTER");
 m_info1 = new JLabel("Adresse: ");
 m_text1 = new JTextField(4);
 m_info2 = new JLabel("Zone: ");
 m_text2 = new JTextField("05",2);
 m_info3 = new JLabel("Octets à modifier: ");
 m_text3 = new JTextField(50);
 m_info4 =new JLabel("trame à envoyer: ");
 m_info5 =new JTextArea(3,44);
 m_info5.setSize(40,40);
 m_info5.setEditable(false);
 
 m_info5.setBackground(Color.yellow);
m_info5.setLineWrap(true) ;
 
 
 
 
 
 
 
 //Gestionnaire de positionnement
 
 setLayout(new FlowLayout());
 
 //integrations des bouttons
 
 add(m_info1);
 add(m_text1);
 add(m_info2);
 add(m_text2);
 add(m_info3);
 add(m_text3);
 //setLayout(new FlowLayout());
 add(m_OK);
 add(m_info4);
 
 add(m_info5);
 //add(m_QUITTER);
 
 
 
 //fermeture de l application a la fermeture de la fenetre
 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 
 //enregistrements des bouttons aupres de leur ActionListener
 
 m_OK.addActionListener(new CMonEcouteurAction());
 //m_QUITTER.addActionListener(new CMonEcouteurAction());
 }
 }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 class LongCorp {  //calculer la longueur de la trame 
int m_LongDec;
String m_Corp;
int m_VraiLong;
 
 LongCorp (String Corp) {
m_Corp = Corp;
m_LongDec =( (Corp.length()/2)+1) ;
m_VraiLong = Corp.length();
}
//retourne la bonne valeur en decimal avec la methode ReturnValueDec
int ReturnValueDec ()
{
return m_LongDec;
}
 
//retourne la bonne valeur en hexadecimal avec la methode ReturnValueHex
String ReturnValueHex() 
{
String Value1=Integer.toHexString(m_LongDec);
return Value1;
}
}
class LireTrame {
}
 
 
 
 
public class CProgPrincipal {
 
public static void main(String[] args) {
 
 
CSuperSwing app = new CSuperSwing("Superspike Trame Loader Constructeur");
 app.pack();
 app.setBackground(Color.green);
 app.setSize(640,480);
 app.setVisible(true);
 
 
 
}
}