Swing help

They have: 9 posts

Joined: Jun 2006

just stated learning Java. trying to create a java EmailFrame which will display a blank Submission Complete message.

but i keep getting error message when ever I try to compile the code.

error (Can not find symbol symbol method submit)

this is what my script looks like

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

public class EmailFrame extends JFrame
{
private InfoPanel infoPanel = new InfoPanel();

public EmailFrame()
{
super("Shared Listener Test");

setJMenuBar(createMenuBar());
getContentPane().add(infoPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(190,150);
setLocation(300,300);
}

private JMenuBar createMenuBar()
{
JMenuBar menuBar = new JMenuBar();
JMenu menu;
JMenuItem item;



item = new JMenuItem("Exit");
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
System.exit(0);
}
});




return menuBar;
}

public static void main(String[] args)
{
JFrame f = new EmailFrame();
f.setVisible(true);
}
}

class InfoPanel extends JPanel
{
private JTextField firstname = new JTextField(10);
private JTextField lastname = new JTextField(10);
private JTextField email = new JTextField(15);

private JButton button = new JButton("Submit");

public InfoPanel()
{
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
submit();
}
});

setLayout(new GridLayout(4,2));

add(new JLabel("Firstname"));
add(firstname);
add(new JLabel("Lastname"));
add(lastname);
add(new JLabel("Email"));
add(email);
add(button);
}

public void clear()
{
firstname.setText("");
lastname.setText("");
email.setText("");
}
}
'

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

You're making a call to submit() whereas you have not defined a method called submit().

        button.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent evt)
                {
                    <strong>submit();</strong>
                }
            });
'

They have: 9 posts

Joined: Jun 2006

thanks for your help

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.