View Single Post
  #3 (permalink)  
Old 07-09-2009, 02:04 PM
YouGina YouGina is offline
Member
 
Join Date: Jul 2009
Posts: 5
Rep Power: 0
YouGina is on a distinguished road
Default
class okHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
RegistratiePanel reg = new RegistratiePanel();
reg.tijdStart.setText("Dit is een test");
}
}
Is this what you mean?

When I try this, nothing happens, the text "Dit is een test" is not sended to the JTextField, but there's also no error, although I would expect a stackoverflow?

The source with a couple of comments:
PHP Code:
import java.awt.*;
import java.awt.event.*;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import java.awt.LayoutManager;

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

class 
RegistratiePanel extends JPanel {
    private 
JToolBar bar;
    private 
JButton OkCancelStartStop;
    public 
JTextField tijdStarttijdEindVoorVan;
    
    public 
RegistratiePanel() {
        
        
setLayout(null);
        
        
Ok = new JButton("Ok"); // This button is going to be used
        
Cancel = new JButton("Cancel");
        
Start = new JButton("Start");
        
Stop = new JButton("Stop");
        
        
Ok.addActionListener(new okHandler()); // The actionhandler is called
        
        
bar = new JToolBar();
        
        
bar.add(Ok);  // Button added to the JToolBar
        
bar.add(Cancel);
        
bar.add(Start);
        
bar.add(Stop);
        
        
add(bar);        
        
bar.setFloatable(false);
        
bar.setRollover(true);
        
bar.setBounds(0050030);
        
        
tijdStart = new JTextField(10); // when Ok button is pushed, text should appear in here.
        
tijdEind = new JTextField(10);
        
Voor = new JTextField(10);
        
Van = new JTextField(10);
        
        
tijdStart.setBounds(1005030020);
        
tijdEind.setBounds(10015030020);
        
Voor.setBounds(10025030020);
        
Van.setBounds(10035030020);
        
        
add(tijdStart);
        
add(tijdEind);
        
add(Voor);
        
add(Van);
                    
    }
}
class 
okHandler implements ActionListener {
    public 
void actionPerformed(ActionEvent e) {
        
RegistratiePanel reg = new RegistratiePanel(); // I guess this is instantiating the RegistratiePanel?
        
reg.tijdStart.setText("Dit is een test"); // This is the text which should appear in the JTextField tijdStart
    
}

Reply With Quote