import javax.swing.*; import java.awt.*; import java.awt.event.*; public class HoidlaProov extends JPanel implements ActionListener{ JTextField tf=new JTextField(); Hoidla h=new LoendavHoidla(); JButton nuppLisa=new JButton("Lisa"); JButton nuppKysi=new JButton("Küsi"); JButton nuppEemalda=new JButton("Eemalda"); public HoidlaProov(){ 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); } 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 HoidlaProov()); f.setVisible(true); } }