////////////Eksamiülesanne: Kaido Heinsalu, IF-21 import java.awt.*; import java.io.*; import java.applet.Applet; import java.awt.event.*; public class Lahutamine extends Panel implements ActionListener, TextListener{ TextField esimVali=new TextField(""); TextField teinVali=new TextField(""); Label mark = new Label("-"); Label infoLab = new Label(""); Label tyhiLab = new Label(""); Label ylemLab = new Label(""); Label alumLab = new Label(""); Label vastLab = new Label(""); Button arvuta=new Button("arvuta"); public Lahutamine(){ setLayout(new BorderLayout()); Panel ylaPaneel=new Panel(new GridLayout(1,4)); ylaPaneel.add(esimVali); ylaPaneel.add(mark); ylaPaneel.add(teinVali); ylaPaneel.add(arvuta); add(ylaPaneel, BorderLayout.WEST); Panel keskPaneel=new Panel(new GridLayout(1,1)); keskPaneel.add(infoLab); add(keskPaneel, BorderLayout.EAST); Panel tyhiPaneel=new Panel(new GridLayout(1,1)); tyhiPaneel.add(tyhiLab); add(tyhiPaneel, BorderLayout.SOUTH); esimVali.addTextListener(this); arvuta.addActionListener(this); Panel alaPaneel=new Panel(new GridLayout(3,1)); alaPaneel.add(ylemLab); alaPaneel.add(alumLab); alaPaneel.add(vastLab); add(alaPaneel, BorderLayout.NORTH); Panel paremPaneel=new Panel(new GridLayout(1,2)); paremPaneel.add(ylaPaneel); paremPaneel.add(keskPaneel); add(paremPaneel, BorderLayout.NORTH); Panel vasakPaneel=new Panel(new GridLayout(2,1)); vasakPaneel.add(alaPaneel); //tyhiPaneel.add(alaPaneel); add(vasakPaneel, BorderLayout.SOUTH); } public void textValueChanged(TextEvent e){ if(esimVali.getText().length()==4){ } } public void actionPerformed(ActionEvent syndmus){ int a,b,c; try{ if (syndmus.getSource()==arvuta){ System.out.println("Nupp töötab!"); a=Integer.parseInt(esimVali.getText()); b=Integer.parseInt(teinVali.getText()); c=a-b; if(b > a){ System.out.println("Tehe korras!"); ylemLab.setText(teinVali.getText()); alumLab.setText(esimVali.getText()); vastLab.setText(""+c); System.out.println(c); } else if(b < a){infoLab.setText("Esimene liige peab olema väiksem!");} //else{infoLab.setText("Sisesta arvud!");} } else{} } catch(Exception erind){System.out.println("Viga!");} } public static void main(String args[]){ Frame f=new Frame("Arvusüsteem"); f.add(new Lahutamine()); f.setSize(500,300); f.addWindowListener(new AknaKuulaja()); f.setVisible(true); } } class AknaKuulaja extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println("Out of game!"); System.exit(0); } }