codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Trying to access method A`s variables or resources from method B  Elomis at 04:32 on Monday, September 05, 2005
 

In order to avoid making every piece of code I write public, I am trying to figure out the correct way of accessing resources from other methods. I have the following style code;

import java.net.*;
import java.io.*;


public class Jeeves extends Thread {
private Socket socket = null;

public Jeeves(Socket socket) {
super("Jeeves");
this.socket = socket;
}

public void run() {

try {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));

String inputLine, outputLine;



while ((inputLine = in.readLine()) != null) {


ProcessLogin();

out.println("Hi.");

}
out.close();
in.close();
socket.close();

} catch (IOException e) {
e.printStackTrace();
}
}

public void ProcessLogin() {

out.println("This worked");

}






Now in the method ProcessLogin, out.println("whatever") doesn't work because it belongs to run(), not ProcessLogin(). What is the correct way of getting to stuff that is in the scope of elsewhere?

  Re: Trying to access method A`s variables or resources from method B  javabits at 11:02 on Tuesday, September 06, 2005
 

You should pass the PrintWriter out to ProcessLogin.

semper fi...








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Why Use Method?
•  Re: Help with filesystem object & displaying in a table
•  Re: Genetic Algorithm Help
•  Re: How to make an investment calculator
•  Re: line breaks in GUI
•  Re: Graph in Gui...
•  Graph in Gui...
•  Re: Counting zero values in a string
•  Re: Help!


Recent Articles
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net
Creating CSS Buttons


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005