View Single Post
  #4 (permalink)  
Old 07-09-2009, 02:32 PM
RamyaSivakanth's Avatar
RamyaSivakanth RamyaSivakanth is offline
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 583
Rep Power: 1
RamyaSivakanth is on a distinguished road
Default
Hi,
Something u want to experiment with Java Compiler and make everyone to get ..Just kidding.

1.My question is when actionPerformed is called again u are instantiating and attaching the actionlistener with this object and totally u are doing the same thing make it stack overflow.

2.Why u need separate handler class for this?

I have corrected ur code.please check it.

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame {   
    public static void main(String[] args) {      
        JFrame frame = new Test();
        frame.setSize(500, 500);
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setTitle("Tijds Registratie");
        frame.setContentPane(new RegistratiePanel());
        frame.setVisible(true);
    }
}

class RegistratiePanel extends JPanel implements ActionListener {
    private JToolBar bar;
    private JButton Ok, Cancel, Start, Stop;
    public JTextField tijdStart, tijdEind, Voor, Van;
    
    public RegistratiePanel() {
        
        setLayout(null);
        
        Ok = new JButton("Ok");
        Cancel = new JButton("Cancel");
        Start = new JButton("Start");
        Stop = new JButton("Stop");
        
        Ok.addActionListener(this);
        
        bar = new JToolBar();
        
        bar.add(Ok);
        bar.add(Cancel);
        bar.add(Start);
        bar.add(Stop);
        
        add(bar);        
        bar.setFloatable(false);
        bar.setRollover(true);
        bar.setBounds(0, 0, 500, 30);
        
        tijdStart = new JTextField(10);
        tijdEind = new JTextField(10);
        Voor = new JTextField(10);
        Van = new JTextField(10);
        
        tijdStart.setBounds(100, 50, 300, 20);
        tijdEind.setBounds(100, 150, 300, 20);
        Voor.setBounds(100, 250, 300, 20);
        Van.setBounds(100, 350, 300, 20);
        
        add(tijdStart);
        add(tijdEind);
        add(Voor);
        add(Van);
                    
    }

	public void actionPerformed(ActionEvent e) {
        tijdStart.setText("Er is op Ok gedrukt");
    }
}
__________________
Ramya
Reply With Quote