Jframe problems

Hi i am working on a project and i am having a problem with a section of code:

new ActionListener()

{

publicvoid actionPerformed(ActionEvent event)//Display new internal window.

{

JFrame frame =new JFrame("Enter Criteria");

JTextField textField =new JTextField("");

frame.getContentPane().add(textField, BorderLayout.CENTER);

JButton button =new JButton("Submit");

frame.add(button, BorderLayout.LINE_END);

button.setActionCommand("submit");

button.addActionListener(this);

frame.setVisible(true);

frame.setSize(300, 50);

if(event.getActionCommand()=="submit")

{

generateReport GenerateReport =new generateReport(textField.getText());

frame.dispose();

}

}

}

);

when i click on submit i get another jframe appear pass the data through and then disappear i have taken out the dispose function as a test and i get another jframe that appears and passes no data through to the jframe if i keep clicking on submit i keep getting new jframes appearing and passing no data through?

Any ideas will be most welcome :)

[1801 byte] By [nnuttaa] at [2007-11-27 4:08:53]
# 1
Do this tutorial before writing anything else: http://java.sun.com/docs/books/tutorial/uiswing/Your current terrible code is an infinite circularity of same GUI set instantiation.Are you going to do a stress test on your computer?
hiwaa at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 2
Can you explain what are you doing in generateReport constructor?
EagerJavaa at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 3

generateReport is a query to a mysql database all im trying to do is get a jframe initialised when a certain menu button is pressed,

within the jframe have a textfield and a button,

when the button is clicked get the text inside the textfield,

then put it into the generateReport file to impliment into the query

nnuttaa at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 4

new ActionListener()

{

public void actionPerformed(ActionEvent event)//Display new internal window.

{

JFrame frame = new JFrame("Enter Criteria");

JTextField textField = new JTextField("");

frame.getContentPane().add(textField, BorderLayout.CENTER);

JButton button = new JButton("Submit");

frame.add(button, BorderLayout.LINE_END);

button.setActionCommand("submit");

button.addActionListener(this); // <=============== **** here ****

..................

..................

As mentioned above, this code is within an ActionListener interface object and then at the indicated spot, has a circular reference to the same ActionListener

interface object, and this doesn't make sense. You must think through your logic step by step and correct it before going on.

petes1234a at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 5

This is an inelegent attempt that may do what you want your app to do, but since I'm just learning Swing, it's not pretty. Let me know if it at least works though.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Foo extends JFrame

{

private JFrame entryCriteriaFrame;

private JTextField entryCriteriaText;

public Foo()

{

JPanel pane = new JPanel();

JButton button1 = new JButton("button1");

button1.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

button1Action();

}

});

pane.add(button1);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

getContentPane().add(pane);

pack();

setVisible(true);

}

private void button1Action()

{

entryCriteriaFrame = new JFrame("Enter Criteria");

entryCriteriaText = new JTextField("");

entryCriteriaFrame.getContentPane().add(entryCriteriaText, BorderLayout.CENTER);

JButton button2 = new JButton("Submit");

button2.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

button2Action();

}

});

entryCriteriaFrame.add(button2, BorderLayout.LINE_END);

entryCriteriaFrame.setVisible(true);

entryCriteriaFrame.setSize(new Dimension(300,60));

}

public void button2Action()

{

GenerateReport GenerateReport = new generateReport(entryCriteriaText.getText());

entryCriteriaFrame.dispose();

}

public static void main(String[] args)

{

Foo myFoo = new Foo();

}

}

petes1234a at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 6
Create the JTextField object outside the ActionListener Anonymous inner Class and try the same..
Josephrajaa at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...
# 7
> Create the JTextField object outside the> ActionListener Anonymous inner Class and try the> same..is that to me or to the original poster? And if to the original poster, how will this get rid of his circular reference?
petes1234a at 2007-7-12 9:14:16 > top of Java-index,Java Essentials,New To Java...