Re: java:143: cannot find symbol -----Please help me
From: Andrew Thompson (SeeMySites_at_www.invalid)
Date: 05/26/04
- Next message: Marcel Urbanek: "Anyone experience with jetspeed2?Installation Problem/P6SpyDriver"
- Previous message: Danny: "java:143: cannot find symbol -----Please help me"
- In reply to: Danny: "java:143: cannot find symbol -----Please help me"
- Next in thread: Aki Laukkanen: "Re: java:143: cannot find symbol -----Please help me"
- Reply: Aki Laukkanen: "Re: java:143: cannot find symbol -----Please help me"
- Reply: Danny: "Re: java:143: cannot find symbol -----Please help me"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 May 2004 08:41:14 GMT
On Wed, 26 May 2004 16:04:20 +0800, Danny wrote:
I have an answer for you, but first, some comments..
You need to have a close look over this
<http://www.physci.org/codes/sscce.jsp>
It explains how you might have represented this
problem in 91 lines, rather than 391
> import java.lang.*;
..no need to import this
> class MyFrame extends JFrame
Terrible name, it sounds like the 'I, me, mine..'
phase of toddlers a class name should tell basically
what it is, so, for instance..
'RetailServerFrame'
> {
> JFrame frame;
> JButton buttonStart;
> JButton buttonExit;
> String userInput;
> String serverName;
> String userName;
> String password;
These are 'class level' attributes, anything
in the class has access to them.
> public static void main(String args[])
> {
> MyFrame f = new MyFrame();
> }
>
> public MyFrame()
> {
> super("Window Title");
>
> JLabel labelSpace;
> JLabel labelTitle;
> JLabel labelServername;
Whereas this is a local variable declared within
the constructor, nothing outside the constructor
can access it.
> ....
> class ButtonListener implements ActionListener
> {
>
> public void actionPerformed(ActionEvent evt)
> {
> JButton source = (JButton)evt.getSource();
> serverName = textServername.getText();
> System.out.println(serverName);
> }
>
> }
> }
So by this stage, the textServerName label is
'out of scope', or 'not visible'.
Solution, declare it as a class level
attribute, and the code will compile.
-- Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
- Next message: Marcel Urbanek: "Anyone experience with jetspeed2?Installation Problem/P6SpyDriver"
- Previous message: Danny: "java:143: cannot find symbol -----Please help me"
- In reply to: Danny: "java:143: cannot find symbol -----Please help me"
- Next in thread: Aki Laukkanen: "Re: java:143: cannot find symbol -----Please help me"
- Reply: Aki Laukkanen: "Re: java:143: cannot find symbol -----Please help me"
- Reply: Danny: "Re: java:143: cannot find symbol -----Please help me"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|