我改了几处,标示出来了,经测试确实能运行和画图。不过或许你需要再改一下
import java.util.*;
import java.applet.*;
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
public class Bianma extends Applet
{ //*********************将数组C做为全局变量
char c[]=new char[200];
//************输入任意字符串,它负责将其生成200位二进制序列C
public void getC()
{
System.out.println("输入编码内容:");
Scanner reader=new Scanner(System.in);
String inpt;
String sz=new String();
String erjinzhi=new String();
inpt=reader.next();
String binaryString=new String();
String season =new String();
String szh=new String();
String szz=new String();
int inptLength = inpt.length();
int strLength;
int n3;
int n4;
int n5;
boolean b = true;
if(inptLength%3 == 0)
{
strLength = inptLength/3;
}
else
{
b = false;
strLength = (int)inptLength/3 + 1;
}
String[] str = new String[strLength];
for(int i=0; i
if(b||(i!=str.length-1))
str[i] = inpt.substring(3*i,3*i+3);
else
str[i] = inpt.substring(3*i);
}
int x;
for(int i=0; i
String s=str[i];
x=Integer.parseInt(s);
binaryString=Long.toBinaryString(x);
n3=binaryString.length();
switch(n3)
{
case 1:
erjinzhi="000000000";
break;
case 2:
erjinzhi="00000000";
break;
case 3:
erjinzhi="0000000";
break;
case 4:
erjinzhi="000000";
break;
case 5:
erjinzhi="00000";
break;
case 6:
erjinzhi="0000";
break;
case 7:
erjinzhi="000";
break;
case 8:
erjinzhi="00";
break;
case 9:
erjinzhi="0";
break;
case 10:
erjinzhi="";
break;
}
sz=sz+erjinzhi+binaryString;
}
szh=sz+"0001";
switch(inptLength%3)
{
case 0:
season="1111111111";
break;
case 1:
season="1111111110";
break;
case 2:
season="1111111101";
break;
}
szz=season+szh;
n4=szz.length();
char [] a=szz.toCharArray();
char c[]=new char[200];
c[199]= '0';
int j=199;
int i;
for(i=n4-1;i>=0;i--)
{
c[j]=a[i];
j--;
}
System.out.print(c);//这是用做测试程序的,实际上不用输出
}
//*****************画图程序
public void paint(Graphics g)
{
getC();
g.drawRect(0 ,0, 28,28);
//下列程序中的c[n]就是程序1中的数组c
{
int j=3;
int i=12;
{
for (int n=0;n<=4;n++)
switch (c[n])
{
case(1):
g.drawLine(n+i,j,n+i,j);
}
}
}
//后面重复画点程序省略
}
}