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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
| import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class amlpm extends Frame implements ActionListener, MouseListener {
int sost=1;
int m=0,n=0, pla=0, plb=0;
int [][][]s=null; int [][]a=null; int [][]b=null;
int prS=0, prA=0, prB=0, row=-1, column=-1;
ScrollPane pnA,pnB,pnS;
TextField rang;
Frame w; MenuBar mb;
Menu m0;
List t1,t3; List t2, t4; Label l10;
TextField tma,tmb, tms, psp, hm;
Button b1, bcn,bcp;
JTable mA, mB, mS=new JTable();
public static void main(String[] args) {
amlpm a = new amlpm();
}
public amlpm() throws HeadlessException {
super();
w=new Frame("АМЛПМ");
System.out.println("Hello!");
w.setSize(700,550);
w.setBackground(Color.orange);
w.setLayout(null);
rang=new TextField();
w.add(rang);
rang.setBounds(535,75,50,20);
w.add(new Label("Ранг начальной матрицы")).setBounds(485,50,150,20);
b1=new Button("Вычислить");
w.add(b1);
b1.setEnabled(false);
b1.setBounds(520,110,80,25);
b1.setBackground(Color.white);
b1.setFont(new Font(("Times New Roman"),1,12));
b1.setForeground(Color.black);
Label l1=new Label("Степень полинома А");
w.add(l1);
l1.setBounds(20,50,150,20);
t1=new List();
t1.add("2"); t1.add("3"); t1.add("4"); t1.add("5"); t1.add("6"); t1.add("7"); t1.add("8"); t1.add("9"); t1.add("10");
t1.add("11"); t1.add("12");t1.add("13");t1.add("14");t1.add("15");t1.add("16");
w.add(t1);
t1.setBounds(30,75,70,20);
Label l2=new Label("Коэффициенты полинома А");
w.add(l2);
l2.setBounds(10,110,160,20);
t2=new List();
w.add(t2);
t2.setBounds(25,135,70,20);
Label l3=new Label("Степень полинома В");
w.add(l3);
l3.setBounds(280,50,150,20);
t3=new List();
t3.add("2"); t3.add("3"); t3.add("4"); t3.add("5"); t3.add("6"); t3.add("7"); t3.add("8"); t3.add("9"); t3.add("10");
t3.add("11"); t3.add("12");t3.add("13");t3.add("14");t3.add("15");t3.add("16");
w.add(t3);
t3.setBounds(295,75,70,20);
Label l4=new Label("Коэффициенты полинома В");
w.add(l4);
l4.setBounds(250,110,160,20);
t4=new List();
w.add(t4);
t4.setBounds(290,135,70,20);
Label l5=new Label("Период матрицы А");
w.add(l5);
l5.setBounds(10,170,150,20);
tma=new TextField();
w.add(tma);
tma.setBounds(25,190,70,20);
Label l6=new Label("Период матрицы В");
w.add(l6);
l6.setBounds(255,170,150,20);
tmb=new TextField();
w.add(tmb);
tmb.setBounds(290,190,70,20);
Label l7=new Label("Период матрицы S");
w.add(l7);
l7.setBounds(490,170,150,20);
tms=new TextField();
w.add(tms);
tms.setBounds(530,190,70,20);
Label l8=new Label("матрица А");
w.add(l8);
l8.setBounds(60,240,90,20);
pnA=new ScrollPane();
w.add(pnA);
pnA.setBounds(20,265,150,150);
pnA.doLayout();
Label l9=new Label("матрица В");
w.add(l9);
l9.setBounds(300,240,90,20);
pnB=new ScrollPane();
w.add(pnB);
pnB.setBounds(250,265,150,150);
pnB.doLayout();
l10=new Label("матрица S[0]");
l10.setForeground(Color.red);
w.add(l10);
l10.setBounds(540,240,90,20);
pnS=new ScrollPane();
w.add(pnS);
pnS.setBounds(500,265,150,150);
pnS.doLayout();
Label ll=new Label("Состояния");
ll.setFont(new Font("Times New Roman",1,13));
w.add(ll);
ll.setBounds(540,420,120,20);
bcn=new Button(">>");
w.add(bcn);
bcn.setEnabled(false);
bcn.setBounds(580,440,25,25);
bcn.setBackground(Color.white);
bcn.setForeground(Color.black);
bcn.setFont(new Font("Times New Roman",0,13));
bcp=new Button("<<");
w.add(bcp);
bcp.setEnabled(false);
bcp.setBounds(540,440,25,25);
bcp.setBackground(Color.white);
bcp.setForeground(Color.black);
bcp.setFont(new Font("Times New Roman",0,13));
Label hem=new Label("Вес Хэмминга");
w.add(hem);
hem.setBounds(25,450,85,20);
hm=new TextField();
w.add(hm);
hm.setBounds(120,450,70,20);
Label psl=new Label("ПСП");
w.add(psl);
psl.setBounds(15,495,30,20);
psp=new TextField();
psp.setForeground(Color.blue);
w.add(psp);
psp.setFont(new Font("Times New Roman",0,13));
psp.setBounds(50,495,470,23);
w.setVisible(true);
w.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent g)
{
w.dispose();
System.exit(0);
}
} );
t1.addMouseListener(this);
t2.addMouseListener(this);
t4.addMouseListener(this);
t3.addMouseListener(this);
b1.addActionListener(this);
bcn.addActionListener(this);
bcp.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("Вычислить")){
sost=0;
if (n!=0) {
if (t2.getSelectedItem()!=null){
pla=Integer.parseInt(t2.getSelectedItem().substring(0,t2.getSelectedItem().length()-1));
a=matr.matrA(n,pla);
mA=new JTable(n,n);
mA.setGridColor(Color.blue);
mA.setIgnoreRepaint(true);
mA.doLayout();
mA.setEnabled(false);
mA.setIntercellSpacing(new Dimension(3,3));
mA.setRowHeight(20);
mA.sizeColumnsToFit(37);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++){
String str=Integer.toString(a[i][j]);
mA.setValueAt(str,i,j);}
pnA.removeAll();
pnA.add(mA);
pnA.doLayout();
prA=matr.period(a);
tma.setText(Integer.toString(prA));
}
else msg("Не выбраны коэффициенты полинома A");
}
if (m!=0)
if (t4.getSelectedItem()!=null){
plb=Integer.parseInt(t4.getSelectedItem().substring(0,t4.getSelectedItem().length()-1));
b=matr.matrB(m,plb);
mB=new JTable(m,m);
mB.setGridColor(Color.blue);
mB.setIntercellSpacing(new Dimension(3,3));
mB.setIgnoreRepaint(true);
mB.doLayout();
mB.setEnabled(false);
mB.setRowHeight(20);
mB.sizeColumnsToFit(7);
String str="";
for (int i=0;i<m;i++)
for (int j=0;j<m;j++){
str=Integer.toString(b[i][j]);
mB.setValueAt(str,i,j);
}
pnB.removeAll();
pnB.add(mB);
pnB.doLayout();
prB=matr.period(b);
tmb.setText(Integer.toString(prB));
}
else msg("Не выбраны коэффициенты полинома B");
int rg=0;
boolean rr=false;
if (!rang.getText().isEmpty()){
rg=Integer.parseInt(rang.getText());
if ((rg>n)&(rg>m))
msg("Ранг превышает размер матрицы");
else rr=true;
}
else msg("Введите ранг!");
if ((n!=0)&(m!=0)&(rr==true)){
l10.setText("матрица S[0]");
String str;
int kf=0;
if (m*n>100) kf=750;
if ((m*n>60)&(m*n<100)) kf=1400;
if (m*n<60) kf=1700;
s=new int[kf*m*n][n][m];
s[0]=matr.matrS0(n,m,rg);
mS=new JTable(n,m);
mS.setFont(new Font("Times New Roman",1,14));
mS.setSelectionBackground(Color.yellow);
mS.setCellSelectionEnabled(true);
mS.addMouseListener(this);
mB.setIgnoreRepaint(true);
mS.doLayout();
mS.setGridColor(Color.red);
mS.setIgnoreRepaint(true);
mS.setRowHeight(20);
mS.sizeColumnsToFit(307);
mS.setIntercellSpacing(new Dimension(5,5));
for (int i=0;i<n;i++)
for (int j=0;j<m;j++){
str=Integer.toString(s[0][i][j]);
mS.setValueAt(str,i,j); }
pnS.removeAll();
pnS.add(mS);
pnS.doLayout();
}
if ((a!=null)&(b!=null)&(s!=null)){
for (int k=1;;k++){
s[k]=matr.product(a,b,s[k-1]);
int pr=0;
for (int i=0;i<a.length;i++)
for (int j=0;j<b.length;j++)
if (s[k][i][j]==s[0][i][j]) pr++;
if (pr==a.length*b.length) {prS=k; break;}
}
bcn.setEnabled(true);
if (prS!=0) tms.setText(Integer.toString(prS));
}
}
if (e.getActionCommand().equals(">>")){
if ((s[0]!=null)&(a!=null)&(b!=null)&(sost<prS)){
sost++;
String str;
mS.removeAll();
mS.setForeground(new Color((17+sost*30)%256 ,(6+sost*20)%256,(3+sost*35)%256));
System.out.println("sost="+sost);
for (int i=0;i<n;i++)
for (int j=0;j<m;j++){
str=Integer.toString(s[sost][i][j]);
mS.setValueAt(str,i,j);
}
l10.setText("матрица S["+sost+"]");
l10.setForeground(Color.red);
}
}
if (e.getActionCommand().equals("<<")){
if ((s[1]!=null)&(sost>0)){
String str;
sost--;
mS.removeAll();
for (int i=0;i<n;i++)
for (int j=0;j<m;j++){
str=Integer.toString(s[sost][i][j]);
mS.setValueAt(str,i,j);
}
l10.setText("матрица S["+sost+"]");
}
}
if (sost>0) bcp.setEnabled(true);
else bcp.setEnabled(false);
if (sost>=prS-1) bcn.setEnabled(false);
else bcn.setEnabled(true);
}
public static void koeff (int n, List t){
if (n==2) t.add("7H");
if (n==3) t.add("13F");
if (n==4){
t.add("23F");
t.add("37D"); }
if (n==5){
t.add("45E");
t.add("75G");
t.add("67H");
}
if (n==6){
t.add("103F");
t.add("127B");
t.add("147H");
t.add("111A");
}
if (n==7){
t.add("211E");
t.add("217E");
t.add("235E");
}
if (n==8){
t.add("435E");
t.add("567B");
t.add("763D");
}
if (n==9){
t.add("1021E");
t.add("1131E");
t.add("1461G");
}
if (n==10){
t.add("2011E");
t.add("2017B");
t.add("2415E");
}
if (n==11){
t.add("4005E");
t.add("4445E");
t.add("4215E");
t.add("4757B");
}
if (n==12){
t.add("10123F");
t.add("12133B");
t.add("10115A");
}
}
public void mouseClicked (MouseEvent g){
psp.setText("");
hm.setText("");
if (g.getComponent()==t1){
if (mA!=null) pnA.removeAll();
if (mS!=null) pnS.removeAll();
t2.removeAll();
n=Integer.parseInt(t1.getSelectedItem());
koeff(n,t2); }
if (g.getComponent()==t3){
if (mB!=null) pnB.removeAll();
if (mS!=null) pnS.removeAll();
t4.removeAll();
m=Integer.parseInt(t3.getSelectedItem());
koeff(m,t4); }
if ((n!=0)&(m!=0)) b1.setEnabled(true);
if (g.getComponent()==mS){
psp.setText(""); hm.setText("");
int psl[]=null;
if (mS!=null){
row=mS.getSelectedRow();
column=mS.getSelectedColumn();
if ((row!=-1)&(column!=-1))
psl=posl.posled(s,prS,row,column);
String str="";
if (psl!=null){
for (int i=0;i<psl.length;i++)
str=str+psl[i];
psp.setText(str);
int hem=posl.hemming(psl);
hm.setText(Integer.toString(hem));}}
}
}
boolean ind;
public void msg(String text){
final Dialog d=new Dialog(w);
d.setBackground(Color.red);
d.setSize(260,80);
d.setLocation(100,100);
d.setLayout(null);
Label l=new Label(text);
d.add(l);
l.setBounds(10,28,240,20);
final Button b=new Button("OK");
d.add(b);
d.setBackground(Color.yellow);
b.setBounds(90,53,50,20);
b.setBackground(Color.white);
if (ind==false) d.setVisible(true);
ind=true;
b.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent r){
if (r.getSource()==b) {d.dispose(); ind=false;}}});
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
} } |