action listener problem
I have created the following code and i want the "btnCreate" to open the frame eqstring, i have tried to implement the action listener and it compiles but when i run it the button does nothing
pnlCreate.add(btnCreate);
pnlSimpleExample.add(btnSimpleExample);
pnlHardExample.add(btnHardExample);
pnlTitle.add(new Label("MAIN MENU"));
pnlTitle.setFont(new Font("Arial", Font.BOLD, 36));
// Setup Main Frame
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(pnlCreate, BorderLayout.SOUTH);
f.getContentPane().add(pnlSimpleExample, BorderLayout.WEST);
f.getContentPane().add(pnlHardExample, BorderLayout.EAST);
f.getContentPane().add(pnlTitle, BorderLayout.NORTH);
this.setSize(300, 300);
btnCreate.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
eqstring mainFrame = new eqstring();
}
});
}
> eqstring mainFrame = new eqstring();
How are we supposed to know what this line of code does (other than invoke the constructor of the "eqstring" class)?
Are you saying you don't believe it is executing the above code? Or just that it "doesn't do anything" that you can see anyway?
Debug it! Put some tracing code above or below that line, so you can "watch" in a sense that it actually did execute it.
ok, warnerja i posted the question before i left for work, i have now only just got in and come back to the computer. . . . so im sorry that my saying thankyou/awarding the dukes didnt come soon enough. But i do appreciate the help people are offering here.
Im pretty new to java . . . basically i have created the interface and on the first page i have a button that i want open another page. The code i have pasted to show you is what i have taken from a text book . . . for the action listener.
> I think warnerja is stressed and really thinks you
> should check out this
> [url=http://forum.java.sun.com/rewards.jspa?&threadID=
> 5150158&messageID=9562382&dukes=10&doActions=rewardtru
> e&actionButton=Reward+Duke+Stars]very helpful Java
> tool[/url] that you can put your code into and it
> will tell you what you did wrong.
:-)