import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Joonis3 extends JComponent implements ActionListener{ int laius=40; int korgus=20; JTextField tf=new JTextField(String.valueOf(laius)); JTextField tf2=new JTextField(String.valueOf(korgus)); JCheckBox cb=new JCheckBox(); JColorChooser varvivalik=new JColorChooser(); JPanel p=new JPanel(new GridLayout(3, 2)); public Joonis3(){ setLayout(new BorderLayout()); p.add(new JLabel("Laius:")); p.add(tf); p.add(new JLabel("Kõrgus:")); p.add(tf2); p.add(new JLabel("Täis:")); p.add(cb); add(p, BorderLayout.SOUTH); add(varvivalik, BorderLayout.NORTH); tf.addActionListener(this); tf2.addActionListener(this); cb.addActionListener(this); varvivalik.setPreviewPanel(new JPanel()); } public void actionPerformed(ActionEvent e){ laius=Integer.parseInt(tf.getText()); korgus=Integer.parseInt(tf2.getText()); repaint(); } public void paintComponent(Graphics g){ g.setColor(varvivalik.getColor()); if(cb.isSelected()){ g.fillOval(50, 320, laius, korgus); } else { g.drawOval(50, 320, laius, korgus); } } public static void main(String[] arg){ JFrame f=new JFrame("Esimene aken"); f.setSize(300, 500); f.getContentPane().add(new Joonis3()); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }