import java.applet.*; import java.awt.*; import java.net.URL; import java.awt.event.*; import java.lang.Math.*; import java.io.*; public class Graaf { public static java.awt.Point clickPoint = null; private static final int RADIUS = 5; public static double a = 0; public static Boolean[] tipud = new Boolean[151]; public static int[] osaHulk = new int[50]; public static int[] serv1 = new int[51]; public static int[] serv2 = new int[51]; static Boolean esimene = Boolean.TRUE; static Color rest,ees,taga; static Frame f = new Frame("Graafi genereerimine"); static CheckboxGroup cbg = new CheckboxGroup(); static Checkbox tipp = new Checkbox("Tipud", cbg, true); static Checkbox serv = new Checkbox("Servad", cbg, false); static Checkbox oHulk = new Checkbox("Osahulk", cbg, false); static Button nupp = new Button("Valmis"); public static int i,j,x,y,k,q,loendur,servArv,oArv; public static void paint(Graphics g) { g.setColor(taga); g.fillRect(0, 0, 300 - 1, 470 - 5); g.setColor(rest); j = Math.round((300-1)/10); k = Math.round((460-35)/15); for (i = 1; i<10; i++) { g.drawLine(i*j,1,i*j,473-35);} for (i = 1; i<15; i++) { g.drawLine(1,i*k+20,300 - 1,i*k+20);} g.setColor(ees); if (clickPoint != null){ x = Math.round((clickPoint.x-j/2)/j+1); y = Math.round((clickPoint.y-20-k/2)/k+1); if (x<10) { if (cbg.getSelectedCheckbox() == tipp) { if (tipud[y*10+x] == Boolean.TRUE) { tipud[y*10+x] = Boolean.FALSE; Eemalda.sweep(); } else { tipud[y*10+x] = Boolean.TRUE;} } else { if (cbg.getSelectedCheckbox() == serv) { if (tipud[y*10+x] == Boolean.TRUE) { if (esimene == Boolean.TRUE) { if (serv1[servArv] != y*10+x) { serv2[servArv] = y*10+x; esimene = Boolean.FALSE; for (i=0; i9) { y++; x = i-y*10+1;} if (tipud[y*10+x] == java.lang.Boolean.TRUE) { g.fillOval(x*j - RADIUS, y*k - RADIUS+20, RADIUS * 2, RADIUS * 2);}} if (esimene == Boolean.TRUE) { if (Math.round(serv1[servArv]/10)>serv1[servArv]/10) { y = Math.round(serv1[servArv]/10)-1; } else { y = Math.round(serv1[servArv]/10);} g.drawOval((serv1[servArv]-y*10)*j-2*RADIUS, y*k-2*RADIUS+20, RADIUS*4, RADIUS*4); } for (i=0; iserv1[i]/10) { y = Math.round(serv1[i]/10)-1; } else { y = Math.round(serv1[i]/10);} if (Math.round(serv2[i]/10)>serv2[i]/10) { x = Math.round(serv2[i]/10)-1; } else { x = Math.round(serv2[i]/10);} g.drawLine((serv1[i]-y*10)*j, y*k+20, (serv2[i]-x*10)*j, x*k+20);} for (i=0; iosaHulk[i]/10) { y = Math.round(osaHulk[i]/10)-1; } else { y = Math.round(osaHulk[i]/10);} g.drawRect((osaHulk[i]-y*10)*j-2*RADIUS, y*k-2*RADIUS+20, RADIUS*4, RADIUS*4);} } public static void main(String[] args) { System.out.println("Graaf GUI by Mikk Normak and Erik Iter RIF11. Version 2.1"); rest = Color.green; ees = Color.black; taga = Color.white; servArv = 0; oArv = 0; esimene = Boolean.FALSE; for (i=0; i9) { ay++; ax = f-ay*10+1;} if (Graaf.tipud[ay*10+ax] == java.lang.Boolean.TRUE) { tippArv++;}} out.println(tippArv); ay = 0; for (f=0; f<150; f++) { ax = f-ay*10+1; if (ax>9) { ay++; ax = f-ay*10+1;} if (Graaf.tipud[ay*10+ax] == java.lang.Boolean.TRUE) { out.println(ay);}} out.println(Graaf.servArv); for (g=0; g9) { ay++; ax = f-ay*10+1;} if (Graaf.tipud[ay*10+ax] == java.lang.Boolean.TRUE) { tippArv++; if (Graaf.serv1[g] == ay*10+ax){ out.println(tippArv); f = 150;}}} tippArv = 0; ay = 0; for (f=0; f<150; f++) { ax = f-ay*10+1; if (ax>9) { ay++; ax = f-ay*10+1;} if (Graaf.tipud[ay*10+ax] == java.lang.Boolean.TRUE) { tippArv++; if (Graaf.serv2[g] == ay*10+ax){ out.println(tippArv); f = 150;}}} } out.println(Graaf.oArv); if (Graaf.oArv == 0) { out.println("2"); } else { out.println("1"); for (g = 0; g9) { ay++; ax = f-ay*10+1;} if (Graaf.tipud[ay*10+ax] == java.lang.Boolean.TRUE) { tippArv++; if (Graaf.osaHulk[g] == ay*10+ax){ out.println(tippArv); f = 150;}}}}} } catch (IOException m) { System.err.println("Caught IOException: " + m.getMessage()); } finally { if (out != null) { out.close(); } else { System.out.println("Väljundfaili ei suudetud kirjutada"); }} System.exit(0); } }