java按钮问题
import java.applet.*;import java.awt.*;
import java.awt.event.*;
public class Hamming extends Applet implements TextListener,ActionListener
{
Label L=new Label("数据:");
Button B=new Button("海明码");
Button A=new Button("纠错");
int tem=0;
int error[]=new int[4];
int Bit[]=new int[11];
int ham[]=new int[15];
int err[]=new int[15];
int mon[][]={{1,1,1,1,1,1,1,0,0,0,0,1,0,0,0},
{1,1,1,1,0,0,0,1,1,1,0,0,1,0,0},
{1,1,0,0,1,1,0,1,1,0,1,0,0,1,0},
{1,0,1,0,1,0,1,1,0,1,1,0,0,0,1}};
int [][]shch={{1,0,0,0,0,0,0,0,0,0,0,1,1,1,1}, /*生成矩阵*/
{0,1,0,0,0,0,0,0,0,0,0,1,1,1,0},
{0,0,1,0,0,0,0,0,0,0,0,1,1,0,1},
{0,0,0,1,0,0,0,0,0,0,0,1,1,0,0},
{0,0,0,0,1,0,0,0,0,0,0,1,0,1,1},
{0,0,0,0,0,1,0,0,0,0,0,1,0,1,0},
{0,0,0,0,0,0,1,0,0,0,0,1,0,0,1},
{0,0,0,0,0,0,0,1,0,0,0,0,1,1,1},
{0,0,0,0,0,0,0,0,1,0,0,0,1,1,0},
{0,0,0,0,0,0,0,0,0,1,0,0,1,0,1},
{0,0,0,0,0,0,0,0,0,0,1,0,0,1,1}};
/*数据*/
TextField t1=new TextField("",1);
TextField t2=new TextField("",1);
TextField t3=new TextField("",1);
TextField t4=new TextField("",1);
TextField t5=new TextField("",1);
TextField t6=new TextField("",1);
TextField t7=new TextField("",1);
TextField t8=new TextField("",1);
TextField t9=new TextField("",1);
TextField t10=new TextField("",1);
TextField t11=new TextField("",1);
/*汉明码*/
TextField T1=new TextField(1);
TextField T2=new TextField(1);
TextField T3=new TextField(1);
TextField T4=new TextField(1);
TextField T5=new TextField(1);
TextField T6=new TextField(1);
TextField T7=new TextField(1);
TextField T8=new TextField(1);
TextField T9=new TextField(1);
TextField T10=new TextField(1);
TextField T11=new TextField(1);
TextField T12=new TextField(1);
TextField T13=new TextField(1);
TextField T14=new TextField(1);
TextField T15=new TextField(1);
/*纠错码*/
TextField TT1=new TextField(1);
TextField TT2=new TextField(1);
TextField TT3=new TextField(1);
TextField TT4=new TextField(1);
TextField TT5=new TextField(1);
TextField TT6=new TextField(1);
TextField TT7=new TextField(1);
TextField TT8=new TextField(1);
TextField TT9=new TextField(1);
TextField TT10=new TextField(1);
TextField TT11=new TextField(1);
TextField TT12=new TextField(1);
TextField TT13=new TextField(1);
TextField TT14=new TextField(1);
TextField TT15=new TextField(1);
TextField ERR=new TextField(20);
public void init()
{
setLayout(new GridLayout(3,15));
add(L);add(t1);add(t2);add(t3);add(t4);add(t5);add(t6);add(t7);add(t8);add(t9);add(t10);add(t11);
add(new Label());add(new Label());add(new Label());add(new Label());
add(B);add(T1);add(T2);add(T3);add(T4);add(T5);add(T6);add(T7);add(T8);add(T9);add(T10);add(T11);add(T12);add(T13);
add(T14);add(T15);
add(A);add(TT1);add(TT2);add(TT3);add(TT4);add(TT5);add(TT6);add(TT7);add(TT8);add(TT9);add(TT10);add(TT11);add(TT12);add(TT13);
add(TT14);add(TT15);
B.addActionListener(this);
t1.addTextListener(this);
t2.addTextListener(this);
t3.addTextListener(this);
t4.addTextListener(this);
t5.addTextListener(this);
t6.addTextListener(this);
t7.addTextListener(this);
t8.addTextListener(this);
t9.addTextListener(this);
t10.addTextListener(this);
t11.addTextListener(this);
A.addActionListener(this);
T1.addTextListener(this);
T2.addTextListener(this);
T3.addTextListener(this);
T4.addTextListener(this);
T5.addTextListener(this);
T6.addTextListener(this);
T7.addTextListener(this);
T8.addTextListener(this);
T9.addTextListener(this);
T10.addTextListener(this);
T11.addTextListener(this);
T12.addTextListener(this);
T13.addTextListener(this);
T14.addTextListener(this);
T15.addTextListener(this);
}
public void textValueChanged(TextEvent e)
{
if(e.getSource()==t1) Bit[0]=Integer.parseInt(t1.getText());
if(e.getSource()==t2) Bit[1]=Integer.parseInt(t2.getText());
if(e.getSource()==t3) Bit[2]=Integer.parseInt(t3.getText());
if(e.getSource()==t4) Bit[3]=Integer.parseInt(t4.getText());
if(e.getSource()==t5) Bit[4]=Integer.parseInt(t5.getText());
if(e.getSource()==t6) Bit[5]=Integer.parseInt(t6.getText());
if(e.getSource()==t7) Bit[6]=Integer.parseInt(t7.getText());
if(e.getSource()==t8) Bit[7]=Integer.parseInt(t8.getText());
if(e.getSource()==t9) Bit[8]=Integer.parseInt(t9.getText());
if(e.getSource()==t10)Bit[9]=Integer.parseInt(t10.getText());
if(e.getSource()==t11)Bit[10]=Integer.parseInt(t11.getText());
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==B)
{
T1.setForeground(Color.red);T2.setForeground(Color.red);
T3.setForeground(Color.red);T4.setForeground(Color.red);
T5.setForeground(Color.red);T6.setForeground(Color.red);
T7.setForeground(Color.red);T8.setForeground(Color.red);
T9.setForeground(Color.red);T10.setForeground(Color.red);
T11.setForeground(Color.red);T12.setForeground(Color.red);
T13.setForeground(Color.red);T14.setForeground(Color.red);
T15.setForeground(Color.red);
for (int i=0;i<15 ;i++ )
{
int m=0;
for (int j=0;j<11 ;j++ )
{
m+=Bit[j]*shch[j][i];
}
ham[i]=m%2;
}
T1.setText(Integer.toString(ham[0]));
T2.setText(Integer.toString(ham[1]));
T3.setText(Integer.toString(ham[2]));
T4.setText(Integer.toString(ham[3]));
T5.setText(Integer.toString(ham[4]));
T6.setText(Integer.toString(ham[5]));
T7.setText(Integer.toString(ham[6]));
T8.setText(Integer.toString(ham[7]));
T9.setText(Integer.toString(ham[8]));
T10.setText(Integer.toString(ham[9]));
T11.setText(Integer.toString(ham[10]));
T12.setText(Integer.toString(ham[11]));
T13.setText(Integer.toString(ham[12]));
T14.setText(Integer.toString(ham[13]));
T15.setText(Integer.toString(ham[14]));
}
else if(e.getSource()==A)
{
int a=0;
err[0]=Integer.parseInt(T1.getText());
err[1]=Integer.parseInt(T2.getText());
err[2]=Integer.parseInt(T3.getText());
err[3]=Integer.parseInt(T4.getText());
err[4]=Integer.parseInt(T5.getText());
err[5]=Integer.parseInt(T6.getText());
err[6]=Integer.parseInt(T7.getText());
err[7]=Integer.parseInt(T8.getText());
err[8]=Integer.parseInt(T9.getText());
err[9]=Integer.parseInt(T10.getText());
err[10]=Integer.parseInt(T11.getText());
err[11]=Integer.parseInt(T12.getText());
err[12]=Integer.parseInt(T13.getText());
err[13]=Integer.parseInt(T14.getText());
err[14]=Integer.parseInt(T15.getText());
for (int i=0;i<4 ;i++ )
{
int n=0;
for (int j=0;j<15 ;j++ )
{
n+= err[j]*mon[j][i];
}
error[i]=n%2;
}
tem=8*error[3]+4*error[2]+2*error[1]+1*error[0];
switch (tem)
{
case :
}
TT1.setText(Integer.toString(err[0]));
TT2.setText(Integer.toString(err[1]));
TT3.setText(Integer.toString(err[2]));
TT4.setText(Integer.toString(err[3]));
TT5.setText(Integer.toString(err[4]));
TT6.setText(Integer.toString(err[5]));
TT7.setText(Integer.toString(err[6]));
TT8.setText(Integer.toString(err[7]));
TT9.setText(Integer.toString(err[8]));
TT10.setText(Integer.toString(err[9]));
TT11.setText(Integer.toString(err[10]));
TT12.setText(Integer.toString(err[11]));
TT13.setText(Integer.toString(err[12]));
TT14.setText(Integer.toString(err[13]));
TT15.setText(Integer.toString(err[14]));
}
}
}
第二个按钮不能用怎么办啊