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(500, 500); 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 Ok, Cancel, Start, Stop; public JTextField tijdStart, tijdEind, Voor, Van; 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(0, 0, 500, 30); 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(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); } } 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 } }
|