Hi, please help me! this is the code i wrote, with the error given below:
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tabslisten extends JApplet
{
JPanel RecPanel;
GridBagLayout gbl;
GridBagConstraints gbc;
public void init ()
{
FlowLayout flow;
flow = new FlowLayout();
Container content = getContentPane();
content.setLayout(new GridLayout());
JTabbedPane tabpane = new JTabbedPane();
content.add(tabpane, flow);
RecPanel = new JPanel();
recipientDetails();
tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details"
;
}
public void recipientDetails()
{
JLabel lblRecFName;
JLabel lblRecLName;
JTextField txtRecFName;
JTextField txtRecLName;
JButton btnValidate;
gbl = new GridBagLayout();
gbc = new GridBagConstraints();
RecPanel.setLayout(gbl);
lblRecFName = new JLabel("First Name"
;
lblRecLName = new JLabel("Last Name"
;
txtRecFName = new JTextField(8);
txtRecLName = new JTextField(5);
btnValidate= new JButton("Validate"
;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbl.setConstraints(lblRecFName, gbc);
RecPanel.add(lblRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbl.setConstraints(txtRecFName, gbc);
RecPanel.add(txtRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbl.setConstraints(lblRecLName, gbc);
RecPanel.add(lblRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbl.setConstraints(txtRecLName, gbc);
RecPanel.add(txtRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 32;
gbl.setConstraints(btnValidate, gbc);
RecPanel.add(btnValidate);
validateAction validateButton = new validateAction();
btnValidate.addActionListener(validateButton);
}
class validateAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
if (obj == btnValidate)
{
String fName = txtRecFName.getText();
String lName = txtRecLName.getText();
if (fName.length()==0)
{
getAppletContext().showStatus("First Name not entered."
;
return;
}
else if (lName.length()==0)
{
getAppletContext().showStatus("Last Name not entered."
;
return;
}
else
{
getAppletContext().showStatus("Successful."
;
}
}
}
}
}
ERROR:
tabslisten.java:90: Undefined variable: btnValidate
if (obj == btnValidate)
^
tabslisten.java:92: Undefined variable or class name: txtRecFName
String fName = txtRecFName.getText();
^
tabslisten.java:93: Undefined variable or class name: txtRecLName
String lName = txtRecLName.getText();
^
3 errors
Press any key to continue...
I'm sure I'm doing something really stupid, but I don't know what! ANY and ALL help will be appreciated! I've simplified the code as much as possible, but i HAVE to be able to validate, and i HAVE to use the panels in the tabbed pane! Thanks!
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tabslisten extends JApplet
{
JPanel RecPanel;
GridBagLayout gbl;
GridBagConstraints gbc;
public void init ()
{
FlowLayout flow;
flow = new FlowLayout();
Container content = getContentPane();
content.setLayout(new GridLayout());
JTabbedPane tabpane = new JTabbedPane();
content.add(tabpane, flow);
RecPanel = new JPanel();
recipientDetails();
tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details"
}
public void recipientDetails()
{
JLabel lblRecFName;
JLabel lblRecLName;
JTextField txtRecFName;
JTextField txtRecLName;
JButton btnValidate;
gbl = new GridBagLayout();
gbc = new GridBagConstraints();
RecPanel.setLayout(gbl);
lblRecFName = new JLabel("First Name"
lblRecLName = new JLabel("Last Name"
txtRecFName = new JTextField(8);
txtRecLName = new JTextField(5);
btnValidate= new JButton("Validate"
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbl.setConstraints(lblRecFName, gbc);
RecPanel.add(lblRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbl.setConstraints(txtRecFName, gbc);
RecPanel.add(txtRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbl.setConstraints(lblRecLName, gbc);
RecPanel.add(lblRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbl.setConstraints(txtRecLName, gbc);
RecPanel.add(txtRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 32;
gbl.setConstraints(btnValidate, gbc);
RecPanel.add(btnValidate);
validateAction validateButton = new validateAction();
btnValidate.addActionListener(validateButton);
}
class validateAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
if (obj == btnValidate)
{
String fName = txtRecFName.getText();
String lName = txtRecLName.getText();
if (fName.length()==0)
{
getAppletContext().showStatus("First Name not entered."
return;
}
else if (lName.length()==0)
{
getAppletContext().showStatus("Last Name not entered."
return;
}
else
{
getAppletContext().showStatus("Successful."
}
}
}
}
}
ERROR:
tabslisten.java:90: Undefined variable: btnValidate
if (obj == btnValidate)
^
tabslisten.java:92: Undefined variable or class name: txtRecFName
String fName = txtRecFName.getText();
^
tabslisten.java:93: Undefined variable or class name: txtRecLName
String lName = txtRecLName.getText();
^
3 errors
Press any key to continue...
I'm sure I'm doing something really stupid, but I don't know what! ANY and ALL help will be appreciated! I've simplified the code as much as possible, but i HAVE to be able to validate, and i HAVE to use the panels in the tabbed pane! Thanks!