Hi i have a teensy problem that i need help with, as i mentioned earlier in some previous thread (can't remember when!) i'm creatin an applet based tutorial. It's nearly finshed thank god except for the last applet i seem to be getting an error that i can't fix. heres the code below;

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

public class textArea extends JApplet
implements ActionListener
{

public static final int LINES = 10;
public static final int CHAR_PER_LINE = 40;

private JTextArea theText;
private String memo1 = ("No Memo 1");

public void init()
{
Container getcontentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setBackground(Color.BLUE);

JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.LIGHT_GRAY);
buttonPanel.setLayout(new FlowLayout());
JButton memo1Button = new JButton("save a memo");
memo1Button.addActionListener(this);
buttonPanel.add(memo1Button);
JButton clearButton = new JButton("clear name");
clearButton.addActionListener(this);
buttonPanel.add(clearButton);
JButton memo1Button2 = new JButton("get the memo");
memo1Button2.addActionListener(this);
buttonPanel.add(memo1Button2);
contentPane.add(buttonPanel, BorderLayout.NORTH);

JPanel textPanel = new JPanel();
textPanel.setBackground(Color.BLUE);

theText = new JTextArea(LINES, CHAR_PER_LINE);
theText.setBackground(Color.WHITE);
textPanel.add(theText);
contentPane.add(textPanel, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e)
{
Container contentPane = getContentPane();
String actionCommand = e.getActionCommand();
if (actionCommand.equals("save a memo"))
memo1Button = theText.getText();
else if (actionCommand.equals("get the memo"))
memo1Button2 = theText.setText(memo1Button2);
else if (actionCommand.equals("clear name"))
clearButton = theText.setText("");
else theText.setText("error in interface");
}
}

the error i get is cannot find symbol variable contentPane, i dn't get it because evry applet i have dne so far uses the exact same coding and i've had no such problem, plese could anyone with the foggiest give me any tips, it will be much much appreciated, thanks!

Please use code tags ..... it keeps the code readable, Anyways what line are you getting that error . . . knowing would have helped a lot ???

Now heres a shot from what I see ....
The first line in your init() function is Container getcontentPane = getContentPane(); , But I do not see the getcontentPane variable used anywhere, So I am assuming you should correct that to Container contentPane = getContentPane(); When the Java compiler says it cant find the symbol, its not playing jokes, it really means it ;) !!!

sory bout not using code tags i'm new never actually used the forum, are these code tags []
thanks for the help by the way

sory bout not using code tags i'm new never actually used the forum, are these code tags []
thanks for the help by the way

Code tags...

[code]

// paste code here

[/code]

or

[code=JAVA] // paste code here

[/code]


Here's your code, formatted with code tags:

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

public class textArea extends JApplet
        implements ActionListener 
{    
    public static final int LINES = 10;
    public static final int CHAR_PER_LINE = 40;
    
    private JTextArea theText;
    private String memo1 = ("No Memo 1");
    
    public void init() 
    {
        Container getcontentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.setBackground(Color.BLUE);
        
        JPanel buttonPanel = new JPanel();
        buttonPanel.setBackground(Color.LIGHT_GRAY);
        buttonPanel.setLayout(new FlowLayout());
        JButton memo1Button = new JButton("save a memo");
        memo1Button.addActionListener(this);
        buttonPanel.add(memo1Button);
        JButton clearButton = new JButton("clear name");
        clearButton.addActionListener(this);
        buttonPanel.add(clearButton);
        JButton memo1Button2 = new JButton("get the memo");
        memo1Button2.addActionListener(this);
        buttonPanel.add(memo1Button2);
        contentPane.add(buttonPanel, BorderLayout.NORTH);
        
        JPanel textPanel = new JPanel();
        textPanel.setBackground(Color.BLUE);
        
        theText = new JTextArea(LINES, CHAR_PER_LINE);
        theText.setBackground(Color.WHITE);
        textPanel.add(theText);
        contentPane.add(textPanel, BorderLayout.CENTER);
    }
    
    public void actionPerformed(ActionEvent e) 
    {
        Container contentPane = getContentPane();
        String actionCommand = e.getActionCommand();
        if (actionCommand.equals("save a memo"))
            memo1Button = theText.getText();
        else if (actionCommand.equals("get the memo"))
            memo1Button2 = theText.setText(memo1Button2);
        else if (actionCommand.equals("clear name"))
            clearButton = theText.setText("");
        else theText.setText("error in interface");
    }
}

You have the problem that stephen84s pointed out above with getcontentPane and a problem with memo1Button, memo1Button2, and clearButton. Are these JButtons? I see they are declared in init, but you probably want to declare them globally, I'm guessing, since they are going out of scope. You are also using setText and getText incorrectly. Here's a link.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextComponent.html

commented: Patient and helpful +9

Hi i have a teensy problem that i need help with, as i mentioned earlier in some previous thread (can't remember when!) i'm creatin an applet based tutorial. It's nearly finshed thank god except for the last applet i seem to be getting an error that i can't fix. heres the code below;

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

public class textArea extends JApplet
implements ActionListener
{

public static final int LINES = 10;
public static final int CHAR_PER_LINE = 40;

private JTextArea theText;
private String memo1 = ("No Memo 1");

public void init()
{
Container getcontentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setBackground(Color.BLUE);

JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.LIGHT_GRAY);
buttonPanel.setLayout(new FlowLayout());
JButton memo1Button = new JButton("save a memo");
memo1Button.addActionListener(this);
buttonPanel.add(memo1Button);
JButton clearButton = new JButton("clear name");
clearButton.addActionListener(this);
buttonPanel.add(clearButton);
JButton memo1Button2 = new JButton("get the memo");
memo1Button2.addActionListener(this);
buttonPanel.add(memo1Button2);
contentPane.add(buttonPanel, BorderLayout.NORTH);

JPanel textPanel = new JPanel();
textPanel.setBackground(Color.BLUE);

theText = new JTextArea(LINES, CHAR_PER_LINE);
theText.setBackground(Color.WHITE);
textPanel.add(theText);
contentPane.add(textPanel, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e)
{
Container contentPane = getContentPane();
String actionCommand = e.getActionCommand();
if (actionCommand.equals("save a memo"))
memo1Button = theText.getText();
else if (actionCommand.equals("get the memo"))
memo1Button2 = theText.setText(memo1Button2);
else if (actionCommand.equals("clear name"))
clearButton = theText.setText("");
else theText.setText("error in interface");
}
}

the error i get is cannot find symbol variable contentPane, i dn't get it because evry applet i have dne so far uses the exact same coding and i've had no such problem, plese could anyone with the foggiest give me any tips, it will be much much appreciated, thanks!

why r u calling getContentpane method inside actionPerformed??

thanks to all who replied have made the changes and now my applet works, thanks for the code tag help VD much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.