/** Rooma numbrid (4p) * Etteantud arv vahemikus 1-2000 v2ljastatakse rooma numbrina */ import java.applet.Applet; import java.awt.*; import java.awt.font.*; import java.awt.event.*; public class HillarpEksam2 extends Applet implements ActionListener{ int nr1=1, nr2=0, nr3=0, nr4=0, i; //- int num1, num2, num3, num4; String number; String[] RoomaYhelised={" ", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; String[] RoomaKymnelised={" ", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String[] RoomaSajalised={" ", "CC"}; static int raamX=100, raamY=100; TextField tf1=new TextField("1", 4); public HillarpEksam2(){ add(tf1); tf1.addActionListener(this); } //- end of HillarpEksam2() public void actionPerformed(ActionEvent e){ number=tf1.getText(); System.out.println(""+number); i=number.length(); System.out.println(""+i); num1=(int)number.charAt(i-1); // if((num1<48) && (num1>57)) num1=48; num2=(int)number.charAt(i-2); if((num2<48) && (num2>57)){ num2=num2;}else{num2=48;} // num3=(int)number.charAt(i-3); // if((num3<48) || (num3>57)) num3=48; // num4=(int)number.charAt(i-4); // if((num4<48) || (num4>57)) num4=48; // nr1=Integer.parseInt(num1); // nr2=Integer.parseInt((number.length()-1)); // nr=Integer.parseInt(tf1.getText().trim()); // if(nr<10) nr1=nr; System.out.println("Yhel "+num1+" kymnel "+num2+" Sajal "+num3+" Tuhandel "+num4); repaint(); } //- end of actionPerformed public void paint(Graphics g){ g.setColor(Color.black); //texti v2rv mustaks if ((nr1<1) || (nr1>100)){ g.drawString("Pole vőimalik", 10, 50); }else{ g.drawString(RoomaKymnelised[nr2-48]+""+RoomaYhelised[num1-48]+"", 10, 50); } //- end if } //-end of paint public static void main(String argumendid[]){ Frame f=new Frame("Tulpdiagrammi joonistamine"); f.setSize(raamX, raamY); f.add(new HillarpEksam2()); f.setVisible(true); } //- end of main } //- end of class