import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Haldusleht extends JApplet implements MouseListener, ActionListener{ Tahvel tahvel=new Tahvel(); JTextField tfLaius=new JTextField(); JTextField tfK6rgus=new JTextField(); Ristkylik valitud=null; public Haldusleht(){ JPanel alapaneel=new JPanel(new java.awt.GridLayout(2, 2)); alapaneel.add(new JLabel("Laius:")); alapaneel.add(tfLaius); alapaneel.add(new JLabel("Kõrgus:")); alapaneel.add(tfK6rgus); add(alapaneel, java.awt.BorderLayout.SOUTH); add(tahvel, java.awt.BorderLayout.CENTER); tahvel.addMouseListener(this); tfLaius.addActionListener(this); tfK6rgus.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(valitud!=null){ if(e.getSource()==tfLaius){ valitud.muudaLaius(Integer.parseInt(tfLaius.getText())); } if(e.getSource()==tfK6rgus){ valitud.muudaK6rgus(Integer.parseInt(tfK6rgus.getText())); } repaint(); } } public void mousePressed(MouseEvent e){ valitud=tahvel.leiaKujundKohal(e.getX(), e.getY()); if(valitud!=null){ tfLaius.setText(String.valueOf(valitud.kysiLaius())); tfK6rgus.setText(String.valueOf(valitud.kysiK6rgus())); } else { if(tfLaius.getText().trim().length()>0){ tahvel.kujundid.add(new Ristkylik( e.getX(), e.getY(), Integer.parseInt(tfLaius.getText()), Integer.parseInt(tfK6rgus.getText()) )); tfLaius.setText(""); tfK6rgus.setText(""); } } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ JFrame f=new JFrame(); f.getContentPane().add(new Haldusleht()); f.setSize(400, 300); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }