import javax.swing.*; import java.awt.*; import java.awt.event.*; public class HoidlaProov2 extends JPanel implements ActionListener{ JTextField tf=new JTextField(); // Hoidla h=new LoendavHoidla(); // Hoidla h=new SalvestavHoidla(); Hoidla h=new SalvestavNaitavHoidla(); // Hoidla h=new NaitavHoidla(); JButton nuppLisa=new JButton("Lisa"); JButton nuppKysi=new JButton("Küsi"); JButton nuppEemalda=new JButton("Eemalda"); public HoidlaProov2(){ setLayout(new BorderLayout()); Panel p=new Panel(new GridLayout(1, 4)); p.add(tf); p.add(nuppLisa); p.add(nuppKysi); p.add(nuppEemalda); add(p, BorderLayout.NORTH); nuppLisa.addActionListener(this); nuppKysi.addActionListener(this); nuppEemalda.addActionListener(this); if(h instanceof JComponent){ add((JComponent)h, BorderLayout.SOUTH); } } public void actionPerformed(ActionEvent e){ if(e.getSource()==nuppLisa){h.lisa(Integer.parseInt(tf.getText()));} if(e.getSource()==nuppKysi){tf.setText(String.valueOf(h.kysiKogus()));} if(e.getSource()==nuppEemalda){h.eemalda(Integer.parseInt(tf.getText()));} } public static void main(String[] arg){ JFrame f=new JFrame(); f.setSize(400, 200); f.getContentPane().add(new HoidlaProov2()); f.setVisible(true); } }