import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Joonis4 extends JPanel implements ActionListener{ int vasakserv=10; int ylaserv=40; int ruudusuurus=30; int veergudearv=8; int ridadearv=8; JTextField tfRead=new JTextField(String.valueOf(ridadearv)); JTextField tfVeerud=new JTextField(String.valueOf(veergudearv)); public Joonis4(){ JPanel ylapaneel=new JPanel(new GridLayout(1, 4)); //1 rida, 2 veergu ylapaneel.add(new JLabel("Ridu:")); ylapaneel.add(tfRead); ylapaneel.add(new JLabel("Veerge:")); ylapaneel.add(tfVeerud); this.setLayout(new BorderLayout()); //Lubab servadesse paigutada this.add(ylapaneel, BorderLayout.NORTH); tfRead.addActionListener(this); tfVeerud.addActionListener(this); } public void actionPerformed(ActionEvent e){ ridadearv=Integer.parseInt(tfRead.getText()); veergudearv=Integer.parseInt(tfVeerud.getText()); repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); //Kutsu välja JPaneli sama käsklus int ruudulaius=(this.getWidth()-2*vasakserv)/veergudearv; int ruudukorgus=(this.getHeight()-ylaserv)/ridadearv; if(ruudulaius