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