import java.applet.Applet; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Riiul extends Applet implements ActionListener{ int korgus; int raamatuid=0; TextField tf=new TextField("", 15); TextField tf2=new TextField("", 15); public Riiul(){ add(tf); add(tf2); tf.addActionListener(this); tf2.addActionListener(this); } public void paint(Graphics t){ t.drawImage(Toolkit.getDefaultToolkit().getImage("Kylie.jpg"), 0, 0, getSize().width, getSize().height, this); } public void actionPerformed(ActionEvent e){ korgus=Integer.parseInt(tf.getText().trim()); if(korgus<=70){JOptionPane.showMessageDialog(this, "Riiul ei saa olla madalam kui 70 cm"); return;} if(korgus>=474){JOptionPane.showMessageDialog(this, "Riiul ei saa olla kõrgem kui 473 cm"); tf.setText("473"); korgus=473;} repaint(); raamatuid=Integer.parseInt(tf2.getText().trim()); repaint(); } public void paint(Graphics g){ int i=0; int k=0; int z=0; int kabi=0; int r=0; int rabi=0; for (i=0;(i=0); r++){ rabi++; // rabi (loe r_abi) naäitab, kuhu raamat joonistada g.drawLine(50+(5*rabi), (550-kabi)-2, 50+(5*rabi), (550-kabi)-42); while(rabi==57){ kabi=kabi-50; if(kabi==0){JOptionPane.showMessageDialog(this, "Riiulisse ei mahu üle "+r+" raamatu!"); tf2.setText(""+r); return; } rabi=0; //järg läheb uue riiuli algusesse } } } public static void main(String argumendid[]){ Frame f=new Frame("Riiuli tellimine"); f.setSize(1024, 768); f.setBackground(new Color(249,249,220)); f.setLocation(300, 0); f.add(new Riiul()); f.setVisible(true); } }