import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TabeliteRakendus extends JApplet implements MouseListener, ActionListener{ TabelitePaigutus paigutus=new TabelitePaigutus(); JTextField tfPealkiri=new JTextField(); JTextArea tfTulbad=new JTextArea(5, 50); JButton salvestusnupp=new JButton("Salvesta"); JPanel p1=new JPanel(new BorderLayout()); Andmetabel valitud=null; public TabeliteRakendus(){ add(paigutus); paigutus.addMouseListener(this); salvestusnupp.addActionListener(this); JPanel p2=new JPanel(new BorderLayout()); p2.add(tfPealkiri, BorderLayout.CENTER); p2.add(salvestusnupp, BorderLayout.EAST); p1.add(p2, BorderLayout.NORTH); p1.add(tfTulbad, BorderLayout.SOUTH); add(p1, BorderLayout.SOUTH); } //Hoolitsege, et tekstiväljades muudetud andmed //jõuaksid ka joonisele tagasi. public void actionPerformed(ActionEvent e){ if(valitud!=null){ valitud.muudaPealkiri(tfPealkiri.getText()); valitud.muudaTulbadTekstina(tfTulbad.getText()); paigutus.repaint(); } } public void mousePressed(MouseEvent e){ valitud=paigutus.leiaTabelKohal( e.getX(), e.getY()); if(valitud!=null){ tfPealkiri.setText(valitud.kysiPealkiri()); tfTulbad.setText(valitud.kysiTulbadTekstina()); } } 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("Tabelid"); f.getContentPane().add(new TabeliteRakendus()); f.setSize(400, 300); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }