/* * @(#)Tilegen.java 1.0 08/08/18 * * * * * * * * */ import java.awt.*; import java.applet.*; import java.net.*; import java.awt.event.*; import java.io.FilePermission; import java.util.Calendar; import java.text.SimpleDateFormat; import java.security.AccessController; import java.lang.*; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.Formatter; import java.util.FormatterClosedException; import java.lang.String; public class tilegen12 extends Applet implements ActionListener { Image tile_gif,qug_gif; URL base; MediaTracker mt; Button okButton; Button confirmButton; Button frameButton; TextField north_inputs,east_inputs,south_inputs,west_inputs,frameip1,frameip2; TextArea compact3; int cflag,frflag; String newline; public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; public void init() { setLayout(null); okButton = new Button("Submit Inputs"); frameButton = new Button("Submit frame glues"); confirmButton = new Button("Click to confirm"); north_inputs = new TextField("Type north outputs here",40); east_inputs = new TextField("Type east inputs here",40); south_inputs = new TextField("Type south inputs here",40); west_inputs = new TextField("Type west outputs here",40); frameip1 = new TextField("",40); frameip2 = new TextField("",40); compact3 = new TextArea(10,10); compact3.setEditable(false); cflag=0; frflag=0; north_inputs.setBounds(130,40,200,30); add(north_inputs); east_inputs.setBounds(340,150,130,30); add(east_inputs); south_inputs.setBounds(130,250,200,30); add(south_inputs); west_inputs.setBounds(10,150,130,30); add(west_inputs); frameip1.setBounds(680,22,50,30); add(frameip1); frameip2.setBounds(680,62,50,30); add(frameip2); compact3.setBounds(500,150,400,300); add(compact3); okButton.setBounds(130,290,100,30); add(okButton); okButton.addActionListener(this); confirmButton.setBounds(10,420,120,30); add(confirmButton); confirmButton.addActionListener(this); frameButton.setBounds(500,110,200,30); add(frameButton); frameButton.addActionListener(this); newline = System.getProperty("line.separator"); mt = new MediaTracker(this); try { base = getDocumentBase(); } catch (Exception e) {} tile_gif = getImage(base,"tile_sample.gif"); qug_gif = getImage(base, "quick_user_guide.gif"); try { mt.waitForAll(); } catch (InterruptedException e) {} } public void paint(Graphics g) { g.drawString("Welcome to XTile ver 1.2 for 3-way Compact error Correction", 10, 20 ); g.drawString("\n Please enter inputs for the four sides of the computational tile design.", 10, 35 ); //g.drawString("\n enter input for frame.", 500, 35 ); g.drawString("\n enter input for vertical frame", 500, 50 ); g.drawString("\n enter input for horizontal frame", 500, 90 ); g.drawString("North inputs :"+north_inputs.getText(),10,340); g.drawString("East inputs :"+east_inputs.getText(),10,360); g.drawString("South inputs :"+south_inputs.getText(),10,380); g.drawString("West inputs :"+west_inputs.getText(),10,400); int[] xcd = new int[3]; int[] ycd = new int[3]; xcd[0]=150;xcd[1]=235;xcd[2]=150; ycd[0]=80;ycd[1]=160;ycd[2]=240; g.setColor( Color.red ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=150;xcd[1]=235;xcd[2]=320; ycd[0]=80;ycd[1]=160;ycd[2]=80; g.setColor( Color.blue ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=320;xcd[1]=235;xcd[2]=320; ycd[0]=80;ycd[1]=160;ycd[2]=240; g.setColor( Color.yellow ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=150;xcd[1]=235;xcd[2]=320; ycd[0]=240;ycd[1]=160;ycd[2]=240; g.setColor( Color.green ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); g.setColor( Color.black ); g.drawString("\n W", 192, 160 ); g.drawString("\n E", 276, 160 ); g.drawString("\n N", 235, 120 ); g.drawString("\n S", 234, 200 ); } public void actionPerformed(ActionEvent evt) { frflag=0; if(evt.getSource() == frameButton) { frflag=1; } if (evt.getSource() == okButton){ repaint();okButton.setLabel("Submitted");cflag=0;frflag=1;} else if ((evt.getSource() == confirmButton && cflag==0) || frflag==1) { String[] in = new String[100]; int i=0; for(i=0;i<100;i++) {in[i]="";} int xi=0; int l1,l2,l3,l4; l1=l2=l3=l4=0; char[] ni = north_inputs.getText().toCharArray(); int nil = north_inputs.getText().length(); if(north_inputs.getText()!="\n") { l1++; for(i=0;i= 0 ; i--) { d_1[i] = ""; for(j=0;j < size_east;j++,k++) { d_1[i] = d_1[i].concat(String.valueOf(ipv.charAt(k))); } } char d_vframe[][] = new char[nt][size_east]; int end = i; //System.out.println("\nbegiinning\n"); for(i=0; i=0; i--) { b_1[i] = ""; for(j=0;j < size_north;j++,k++) { // System.out.printf("\n %d %d %d\n",i,j,k); b_1[i] = b_1[i].concat(String.valueOf(iph.charAt(k))); } } char b_vframe[][] = new char[nt_2][size_north]; for(i=0;i < nt_2; i++) { b_vframe[i] = b_1[i].toCharArray(); } for(i=0;i=nt) { vsouth_glues[i] = vsouth_glues[i%nt]; // System.out.printf("\nin spcl. condn. v2[ipernt]= %s are and ipernt is %d and i is %d \n",vsouth_glues[i%nt],i%nt,i); flag = 1; // System.out.printf("\nin spcl. cond.v1= %s and v2= %s are",String.copyValueOf(s_vframe[i]),String.copyValueOf(s_vframe[i%nt])); } else { // System.out.printf("\nv1= %s and v2= %s are",String.copyValueOf(s_vframe[i]),String.copyValueOf(s_vframe[i%nt])); vsouth_glues[i] = String.valueOf(++high); } } int nt2; nt2 = i-1; for(i=0;i=nt_2) { heast_glues[i] = String.valueOf(++high); heast_glues[i+1] = heast_glues[(i%nt_2)+1]; // System.out.printf("\nin spcl. condn. v2[ipernt]= %s are and ipernt is %d and i is %d \n",heast_glues[i%nt_2],i%nt_2,i); flag = 1; // System.out.printf("\nin spcl. cond.v1= %s and v2= %s are",String.copyValueOf(ss_vframe[i]),String.copyValueOf(ss_vframe[i%nt_2])); } else { // System.out.printf("\nv1= %s and v2= %s are",String.copyValueOf(ss_vframe[i]),String.copyValueOf(ss_vframe[i%nt_2])); heast_glues[i] = String.valueOf(++high); } } //------------------end big loop int nt3; nt3 = i; for(i=0;i=0;i--) bout = bout.concat(String.valueOf(bin.charAt(i))); return bout; } public static char[] infixtopostfix(String exp) { StackArray stack = new StackArray(); int pri; int length; int j = 0; char x; char expression[] = new char[100]; //System.out.println("Please enter the input expression"); //exp = input.nextLine(); length = exp.length(); for(int i =0 ; i <= length ; i++) { if(i == length) { while(stack.peek() != '#') { if(stack.peek() == '(') x = stack.pop(); else expression[j++] = stack.pop(); } } else if(exp.charAt(i) == '(') { stack.push(exp.charAt(i)); } else if(exp.charAt(i) == '.'|| exp.charAt(i) == '+'|| exp.charAt(i) == '~'|| exp.charAt(i) == '^') { if(stack.peek() != '(' && stack.peek() != '#') expression[j++] = stack.pop(); else stack.push(exp.charAt(i)); } else if(exp.charAt(i) == ')') { while(stack.peek() != '(') expression[j++] = stack.pop(); } else { expression[j++] = exp.charAt(i); } } //for(int i =0; i < length; i++) //System.out.printf("%c",expression[i]); return expression; } public static char EvaluatePf(String exp) { String exp2=""; for(int a=0; Character.isLetterOrDigit(exp.charAt(a)) || exp.charAt(a) == '+'|| exp.charAt(a) == '^'|| exp.charAt(a) == '~'|| exp.charAt(a) == '.';a++) { exp2=exp2.concat(String.valueOf(exp.charAt(a))); } StackArray stack = new StackArray(); int length = exp2.length(); //System.out.printf("\n%s exp and length %d\n",exp2,length); char a , b; int answer = 0; String temp; char temp1; for(int i = 0; i < length; i++) { if(exp2.charAt(i) != '.' && exp2.charAt(i) != '+' && exp2.charAt(i) != '~' && exp2.charAt(i) != '^') { stack.push(exp2.charAt(i)); } else if(exp2.charAt(i) == '.') { a = stack.pop(); b = stack.pop(); answer = Integer.parseInt(String.valueOf(a)) * Integer.parseInt(String.valueOf(b)); temp = String.valueOf(answer); temp1 = temp.charAt(0); stack.push(temp1); } else if(exp2.charAt(i) == '^') { a = stack.pop(); b = stack.pop(); answer = Integer.parseInt(String.valueOf(a)) ^ Integer.parseInt(String.valueOf(b)); temp = String.valueOf(answer); temp1 = temp.charAt(0); stack.push(temp1); } else if(exp2.charAt(i) == '+') { a = stack.pop(); b = stack.pop(); answer = Integer.parseInt(String.valueOf(a)) + Integer.parseInt(String.valueOf(b)); if(answer > 0) answer = 1; temp = String.valueOf(answer); temp1 = temp.charAt(0); stack.push(temp1); } else if(exp2.charAt(i) == '~') { a = stack.pop(); if(a == '1') temp1 = '0'; else temp1 = '1'; stack.push(temp1); } } temp1 = stack.pop(); return temp1; } }