| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 740 人关注过本帖
标题:java按钮问题
只看楼主 加入收藏
hamletfei
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-31
收藏
 问题点数:0 回复次数:1 
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]));
        }
     
  


   
      

}
}  










第二个按钮不能用怎么办啊
搜索更多相关主题的帖子: public import java 
2009-12-30 21:00
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
把问题描述清楚一些吧,还有,这代码也太乱了吧

可惜不是你,陪我到最后
2010-01-04 09:38
快速回复:java按钮问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050510 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved