aspose file tools
The moose likes Swing / AWT / SWT and the fly likes ActionListeners Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "ActionListeners" Watch "ActionListeners" New topic
Author

ActionListeners

Keith O'Gorman
Greenhorn

Joined: Mar 16, 2000
Posts: 4
When I compile this code, I get an error - 'undefined variable this ' at the submitBtn.addActionListener(this).
Can anyone see what the problem is ?
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class initial extends JInternalFrame implements ActionListener
{
// Declarations & Initialisations
private static JTabbedPane tabbedPane = new JTabbedPane();
private static JPanel topPanel = new JPanel();
private static JPanel panel1 = new JPanel();
private static JPanel panel2 = new JPanel();
private static JButton submitBtn = new JButton("Submit");
private static JLabel userNameL = new JLabel("Username :");
private static JLabel passwordL = new JLabel("Password :");
private static JTextField userNameTF = new JTextField();
private static JPasswordField passwordPF = new JPasswordField();
private static JDesktopPane desktop = new JDesktopPane();
public static String userName = new String();
public static String password = new String();
private static JScrollPane scrollPane1;

//System.out.println("in class initial");
public initial()
{
setClosable( true );
setMaximizable( true );
setIconifiable( true );
setResizable( true );
setTitle("Network Info Tool");
setSize(210, 250);

System.out.println("in method initial");

// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

//CreateTopPane( topPanel );

//desktop.add(initial);
moveToFront();
// Create the tab pages
createPage1();
createPage2();
// Create a tabbed pane
tabbedPane.addTab("Logon", panel1);
tabbedPane.addTab("About", panel2);
topPanel.add(tabbedPane, BorderLayout.CENTER);
}

private void CreateTopPane( JPanel topPanel )
{
// Create a text area
JTextArea area = new JTextArea();
// Load a file into the text area, catching any exceptions
try {
FileReader fileStream = new FileReader( "TestFrame.java" );
area.read( fileStream, "TestFrame.java" );
}
catch( FileNotFoundException e )
{
System.out.println( "File not found" );
}
catch( IOException e )
{
System.out.println( "IOException occurred" );
}
// Create the scrolling pane for the text area
scrollPane1 = new JScrollPane();
scrollPane1.getViewport().add( area );
topPanel.add( scrollPane1, BorderLayout.CENTER );
}

public static void createPage1()
{

panel1.setLayout(null);
userNameL.setBounds(10, 15, 150, 20);
panel1.add(userNameL);
userNameTF.setBounds(10, 35, 150, 20);
panel1.add(userNameTF);
passwordL.setBounds(10, 60, 150, 20);
panel1.add(passwordL);
passwordPF.setBounds(10, 80, 150, 20);
passwordPF.setEchoChar('*');
panel1.add(passwordPF);

submitBtn.setBounds(30, 120, 110, 30);
panel1.add(submitBtn);

submitBtn.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
String logonError = "Incorrect User Name or Password";

System.out.println("USERNAME = " + userName);

if(e.getSource() == submitBtn)
{
System.out.println("Action: submitButton pressed");
userName = userNameTF.getText();
password = passwordPF.getText();
System.out.println("USERNAME = " + userName);
System.out.println("PASSWORD = " + password);


if ((daveframe.dave(userName, password)) == true)
{
System.out.println("NO ERROR");
}
else
{
JOptionPane.showMessageDialog(null,logonError, " ", JOptionPane.WARNING_MESSAGE);
System.out.println("ERROR");
}
}
}
public static void createPage2()
{
panel2.setLayout(new BorderLayout());
}
}
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
That's because your method createPage1 is declared as static. Staic methods exist for all object instances, and have no "this".
It should work if you remove the "static".


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionListeners
 
Similar Threads
JTabbedPane problems - not loading correctly
JSplitterView treats panes differently
JTabbedPane display Problem
Look and feel with Custom UI delegate
How to change components(JTextField) size dynamic in JTabbedPane?