import java.awt.*; import java.awt.image.*; import java.lang.Math; import java.util.*; import java.io.*; public class Arendaja extends Frame { int punkte=0 ,smin ,ssec ,lmin ,lsec, aegmin, aegsec; String nimi,rida,ridak; public Arendaja() { setTitle("Mõtte arendaja"); MenuBar mbar = new MenuBar(); Menu m = new Menu("Algus"); m.add(new MenuItem("Start")); m.addSeparator(); m.add(new MenuItem("Välju")); mbar.add(m); m = new Menu("Aita"); m.add(new MenuItem("Juhend")); m.add(new MenuItem("Autorilt")); mbar.add(m); setMenuBar(mbar); } public boolean action(Event evt, Object arg) { if (evt.target instanceof MenuItem) if(arg.equals("Start")) { Calendar kalender=new GregorianCalendar(); smin=kalender.get(Calendar.MINUTE); ssec=kalender.get(Calendar.SECOND); Sisse1 ab2 = new Sisse1(this); ab2.show(); Calendar kal=new GregorianCalendar(); lmin=kal.get(Calendar.MINUTE); lsec=kal.get(Calendar.SECOND); if (ssec>lsec) { aegsec=60+lsec-ssec; if (smin>lmin) {aegmin=60+lmin-1-smin; } else aegmin=lmin-1-smin; } else { aegsec=lsec-ssec; if (smin>lmin) {aegmin=60+lmin-smin; } else aegmin=lmin-smin; } System.out.println(aegmin); System.out.println(aegsec); Sisse2 ab3 = new Sisse2(this); ab3.show(); Suleb ab4 = new Suleb(); Avab ab5 = new Avab(); repaint(); } else if(arg.equals("Juhend")) { Juhis ab6 = new Juhis(this); ab6.show(); } else if(arg.equals("Autorilt")) { Autorilt ab7 = new Autorilt(this); ab7.show(); } else if(arg.equals("Välju")) { System.exit(0); } else return super.action(evt, arg); return true; } public void paint(Graphics g) { g.setColor(Color.black); g.drawString(ridak,4,454); } public static void main(String arg[]) { Frame f = new Arendaja(); f.setLocation(100, 100); f.resize(410, 445); f.show(); } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) System.exit(0); return super.handleEvent(evt); } //Koordinaatide sisestamine class Sisse1 extends Dialog { TextField fromx = new TextField("5", 3); Label lb,plb; String fx; int i=1,nx; int a=(int)(Math.random()*1000); int b=(int)(Math.random()*1000); String label="Kui palju on "+a+"+"+b+"?"; String plabel="Punkte "+punkte; public Sisse1(Frame parent) { super(parent, "Hakka vastama" ,true); Panel p1 = new Panel(); plb = new Label(plabel); lb = new Label(label); p1.setLayout(new GridLayout(2,1)); p1.add(plb); p1.add(lb); add("North", p1); Panel p2 = new Panel(); p2.setLayout(new FlowLayout()); p2.add(new Label("Vastus :")); p2.add(fromx); add("Center", p2); Panel p3 = new Panel(); p3.add(new Button(" Ok ")); add("South", p3); resize(300, 130); setLocation(200, 300); } public boolean action(Event evt, Object arg) { if(arg.equals(" Ok ")) { fx = (fromx.getText()); nx = Integer.parseInt(fx); if (nx == (a+b)) punkte = punkte+10; else punkte = punkte - 5; if (i>=10) { dispose(); return true; } i++; a = (int)(Math.random()*1000); b = (int)(Math.random()*1000); label="Kui palju on"+a+"+"+b+"?"; plabel="Punkte"+punkte; lb.setText(label); plb.setText(plabel); } return false; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) dispose(); return super.handleEvent(evt); } } //Nime küsimine class Sisse2 extends Dialog { TextField fromnimi = new TextField("Nimi", 3); public Sisse2(Frame parent) { super(parent, "Sisesta oma nimi", true); Panel p1=new Panel(); p1.setLayout(new GridLayout(2, 1)); p1.add(new Label(" Palun Sisestage oma nimi: ")); p1.add(fromnimi); add("North", p1); Panel p2=new Panel(); p2.add(new Button(" Ok ")); add("South",p2); resize(300, 200); setLocation(200, 300); } public boolean action(Event evt, Object arg) { if(arg.equals(" Ok ")) { nimi=fromnimi.getText(); dispose(); return true; } return false; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) dispose(); return super.handleEvent(evt); } } class Avab { Avab() { Avaveel(); } void Avaveel() { try { BufferedReader sisse=new BufferedReader(new FileReader("Punktid.txt")); rida = sisse.readLine(); while(rida!=null) { ridak = ridak + rida+" "; rida = sisse.readLine(); } sisse.close(); } catch(IOException e) { } } } class Suleb { String ridak = ""; Suleb() { Suleveel(); } void Suleveel() { try { PrintWriter valja=new PrintWriter(new FileWriter("Punktid.txt")); valja.println(nimi); valja.println(aegmin); valja.println(aegsec); valja.close(); } catch(IOException e) { } } } /*juurde public static void main(String argumendid[]) throws IOException{ PrintWriter valja=new PrintWriter( new FileWriter("inimesed.txt", true) ); valja.println("Mari"); valja.close(); } välja public static void main(String argumendid[]) throws IOException{ BufferedReader sisse=new BufferedReader( new FileReader("inimesed.txt") ); String rida=sisse.readLine(); while(rida!=null){ System.out.println(rida); rida=sisse.readLine(); } sisse.close(); } */ //Kasutus juhend class Juhis extends Dialog { public Juhis(Frame parent) { super(parent, "Juhis", true); Panel p1=new Panel(); p1.setLayout(new GridLayout(6, 1)); p1.add(new Label(" Kuidas kasutada programmi ? ")); p1.add(new Label("1. Vali menüü ribalt Algus")); p1.add(new Label("2. Seejärel sisesta andmed AINULT täis arvuliselt")); p1.add(new Label("3. Nüüd joonistab programm sinu andmete järgi jooned")); p1.add(new Label(" ning kontrollib kas need on paralleelsed või kas ")); p1.add(new Label(" nad lõikuvad, ning märgib ära lõikepunkti. ")); add("North", p1); Panel p2=new Panel(); p2.add(new Button(" Ok ")); add("South",p2); resize(300, 200); setLocation(200, 300); } public boolean action(Event evt, Object arg) { if(arg.equals(" Ok ")) { dispose(); return true; } return false; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) dispose(); return super.handleEvent(evt); } } //Autori sõna class Autorilt extends Dialog { public Autorilt(Frame parent) { super(parent, " Autorilt ", true); Panel p1 = new Panel(); p1.setLayout(new GridLayout(3,1)); p1.add(new Label("Joonte Joonistaja")); p1.add(new Label("Versioon 1.0")); p1.add(new Label("Koostanud Janno Rütter")); add("Center", p1); Panel p2 = new Panel(); p2.add(new Button(" Ok ")); add("South", p2); resize(220, 150); setLocation(200, 300); } public boolean action(Event evt, Object arg) { if(arg.equals(" Ok ")) { dispose(); return true; } return false; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) dispose(); return super.handleEvent(evt); } } }