🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: The static method readURL(String) from the type URLReader should

#599
From: scott
Date: Wed, 23 Mar 2005 18:51
177 lines
5106 bytes
Here is the code for the applet that calls the method in the initial post.  I've hightlighted the method that generates the warning with a comment.  

Apologies for the complete silliness of the app :).  I'm still trying to learn Java and this seemed vaguely more interesting than plain Hello, World.

Any other feedback would be appreciated...


package com.shp.kandis;

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.MalformedURLException;

public class HelloKandis extends Applet implements Runnable {
	static final long serialVersionUID = 1;
	Button btn = null;
	ColorLoop red = null;
	ColorLoop blue = null;
	ColorLoop green = null;
	Thread appletThread = null;
	TextArea msg = null;
	MessageParser msgGenerator = new MessageParser();
	static URLReader urlReader = new URLReader();
	RefreshHandler h = null;
	public void init() {
		// get the event handler
		h = new RefreshHandler(this);
		
		// prepare the labels
		msg = new TextArea("", 3, 50, TextArea.SCROLLBARS_NONE);
		msg.setEditable(false);

		
		// prepare the buttons
		btn = new Button ("Refresh");
		btn.addActionListener(h);
		
		// color loops
		red = new ColorLoop(125, true, 10);
		blue = new ColorLoop(125, false, 10);
		green = new ColorLoop(125, false, 25);
		
		// initialize applet panel
		setFont(new Font("Verdana",Font.BOLD, 24));
		setSize(1000,200);

		add(msg);
	}

	public void start(){
		if (appletThread == null){
			appletThread = new Thread(this);
			appletThread.start();
		}
	}
	
	public void stop(){
		appletThread = null;
	}
	
	public void run(){
		Thread thisThread = Thread.currentThread();
		while (thisThread == appletThread){
			repaint();
			try{
				Thread.sleep(500);
			}catch (InterruptedException e ){}
		}
	}
	
	
	public void destroy(){
		btn = null;
		red = null;
		blue = null;
		green = null;
		msgGenerator = null;
		urlReader = null;
		h = null;
	}


	public Color getColor(){
		return new Color(red.getNextValue(), green.getNextValue(), blue.getNextValue());
	}
	public void paint (Graphics g){
		Color c = getColor();
		msg.setForeground(c);
		msg.setText(getMessage());

		c = null;
	}

	public String getMessage(){
		String msg = "Hello, Kandis.\n  It's: \n" 
			+ " #now()#.";
		
		if (getParameter("url") != null){
			msg = readURL(getParameter("url"));
		}else if (getParameter("message") != null){
			msg = getParameter("message");
		}
		
		msgGenerator.setMessageStub(msg);
		return msgGenerator.getMessage();
	}
	
//line below generates warning
	public String readURL(String url){
		String rc = "";
		try {
			rc = urlReader.readURL(url);
		} catch (MalformedURLException e){
			System.err.println(e.getMessage());
		}
		return rc;
	}
	
	
	class RefreshHandler implements ActionListener{
		private Applet parent;
		public RefreshHandler(Applet parent){
			this.parent = parent;
		}
		
		public void actionPerformed(ActionEvent evt){
			parent.repaint();
		}
	}
}



"Lori M Olson [TeamB]" <javadragon@techie.com> wrote:
>Scott Powell wrote:
>
>> I get the cited warning message in a project I'm working on.
>> 
>> URLReader's signature is  public static String readURL(URL url)
>> 
>> And indeed the method that calls it is not static.
>> 
>> But I don't really understand why it would generate a warning or how one
>> could solve it.
>> 
>> The readURL method only uses local variables (and the parameter) so it
>> doesn't need to not be static (if I understand when static gets used).
>> 
>> Full method is below.
>> 
>> Thanks
>> Scott
>> 
>>  public static String readURL(URL url){
>
>To answer the question I *need* to see the code that calls it.
>
>-- 
>
>Regards,
>
>Lori Olson [TeamB]
>
>------------
>
>Save yourself, and everyone else, some time and search the
>newsgroups and the FAQ-O-Matic before posting your next
>question.
>
>Google Advanced Newsgroup Search
>     http://www.google.ca/advanced_group_search
>Other Newsgroup Searches:
>     http://www.borland.com/newsgroups/ngsearch.html
>Joi Ellis's FAQ-O-Matic:
>     http://www.visi.com/~gyles19/fom-serve/cache/1.html
Technical Details
Message-ID: <4241baaa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4240a17f$1@newsgroups.borland.com> <4240a90c@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,6574813dc04e4e07
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "scott" <spowell@rpsweb.com>
Sender: "scott" <spowell@rpsweb.com>
Reply-To: "scott" <spowell@rpsweb.com>
Subject: Re: The static method readURL(String) from the type URLReader should
Newsgroups: borland.public.jbuilder.java.language
X-User-Info: 64.80.153.236     
References: <4240a17f$1@newsgroups.borland.com> <4240a90c@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4241baaa$1@newsgroups.borland.com>
Date: 23 Mar 2005 10:51:22 -0800
X-Trace: newsgroups.borland.com 1111603882 207.105.83.66 (23 Mar 2005 10:51:22 -0800)
Lines: 178
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail