🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19091

Re: Problem with member visibility/packages

#19091
From: Conrad Hoesle-Kienzlen
Date: Fri, 13 Mar 1998 00:00
161 lines
4705 bytes
Paul,
there's more than one thing wrong with that code:
1. the import of Mysource is unnecessary since both classes belong to the
same package. Whether this causes any harm I can't say.
2. in BusLogicDataClass method getTxtFields you need a type declaration in
front of your variables:
      String name = txtfldName.getText();
3. I am not sure what you are trying to achieve with the class
BusLogicDataClass. Since you declared all those variables private, they can
only be seen within that class. And since getTxtFields() does not return
anything, you can't get at them from outside by calling getTxtFields
either. If you are trying to deliver those variables to UIDataClass, then
you will have to write a setter/getter method for each value, or return
them all concatenated in one string (or as a string array) via return and
parse that string in UIDataClass.
...Conrad

Paul Richards wrote:

> I'm struggling with visibility and access and would welcome some help.
> I have a directory \Mysource containing UIDataClass.java and
> BusLogicDataClass.java, and have added 'package Mysource' to each file,
> and import statements for each class.
>
> When I try to compile BusLogicDataClass.java I get a list of errors
> like so:
>
> "Undefined variable or classname: txtfldName?"
>
> for each of the textfields in UIDataClass.java.
>
> When I try to compile UIDataClass.java I get the following:
>
> ".\Mysource\BusLogicDataClass.java: Undefined variable or classname:
> txtfldName?
>        name = txtfldName.getText()?;
>                ^?"
>   for each textfield.
>
> It's probably something very basic which I'm missing - can anyone spot
> the wood for the trees? (summary code below)
>
> TIA
>
> ++ *Paul*
>  ++ from Cheltenham, England
>  ++ Fri, 13 Mar 1998 18:44 GMT
>  ++ WinNT build 1381 + SP3
>  ++ http://freespace.virgin.net/paul.richards/
> ......
>
> /*
>  * UIDataClass.java
>  */
>
> package Mysource;
>
> import java.awt.*;
>
> import Mysource.*;
>
> public class UIDataClass extends Frame {
>   public UIDataClass() {
>     super();
>     setLayout(null);
>     addNotify();
>     Insets insets = insets();
>     // .....
>     // set up UI buttons, labels, textfields ...
>     // ....
>     show();
>   }
>
>   public boolean handleEvent(Event evt) {
>     // <snip>
>   }
>
> // Event handlers
>        <snip>
>
>
> // End of event handlers
>
>   public static void main(String args[]) {
>     new UIDataClass();
>     BusLogicDataClass BLDC = new BusLogicDataClass();
>   }
>
>   Label label1;
>   Label label2;
>   TextField txtfldName;
>   Label label3;
>   TextField txtfldAddr1;
>   Label label4;
>   TextField txtfldAddr2;
>   Label label5;
>   TextField txtfldAddr3;
>   Label label6;
>   TextField txtfldAge;
>   Label label7;
>   TextField txtfldMortgage;
>   Button btnAdd;
>   Button btnView;
>   Button btnExit;
>
> // Other methods/variables:
>
> }
>
> /**
> * BusLogicDataClass.java
> */
>
> package Mysource;
>
> import Mysource.*;
> import java.io.*;
> import java.util.*;
>
> public class BusLogicDataClass     // class to store data
> {
>   private String name;
>   private String address1;
>   private String address2;
>   private String address3;
>   private String age;
>   private String mortgage;
>
>  <snip>
>   {
>     BusLogicDataClass nameaddress = new BusLogicDataClass();
>   }
>
>   public BusLogicDataClass() // constructor
>   {
>    getTxtFields();
>    setTxtFields();
>   } // end constructor
>
>   void getTxtFields()
>   {
>       name     = txtfldName.getText();
>       address2 = txtfldAddr1.getText();
>       address2 = txtfldAddr2.getText();
>       address3 = txtfldAddr3.getText();
>       age      = txtfldAge.getText();
>       mortgage = txtfldMortgage.getText();
>   }
>
>    void setTxtFields()
>   {
>       txtfldName.setText("");
>       txtfldAddr1.setText("");
>       txtfldAddr2.setText("");
>       txtfldAddr3.setText("");
>       txtfldAge.setText("");
>       txtfldMortgage.setText("");
>   }
>
> } // end class BusLogicDataClass
Technical Details
Message-ID: <3509A106.7D465D69@csi.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <VA.0000002a.0c5a12e6@p5>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,ea213ab83e1f43a0
X-Google-Attributes: gidf74b3,public
From: Conrad Hoesle-Kienzlen <Conrad_Hoesle@csi.com>
Subject: Re: Problem with member visibility/packages
Date: 1998/03/13
Message-ID: <3509A106.7D465D69@csi.com>
X-Deja-AN: 333795858
Content-Transfer-Encoding: 7bit
References: <VA.0000002a.0c5a12e6@p5>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: CHK IT-Consulting
Newsgroups: borland.public.jbuilder.java.language