where is this error Noobie question first time using Java

C:\Program Files\Apache Group\Apache\htdocs\school>javac rootapplet.java
rootapplet.java:17: cannot resolve symbol
symbol  : variable screen
location: class rootapplet
        screen.drawString("Testing");
        ^
1 error
LVL 1
aot2002Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Nick_72Connect With a Mentor Commented:
You probably haven't declared the variable screen.

/Nick
0
 
TrekkyLeaperCommented:
The variable "screen" is either not defined or out of scope.
0
 
aot2002Author Commented:
well would this be a path issue as the main path is
c:\jdk\

if not then how can i clear the variable screen




import java.awt.*;

public class rootapplet extends javax.swing.JApplet {
      String parameter1;
      String parameter2;
      String parameter3;

      public void init() {
            parameter1 = getParameter("adjective1");
            parameter2 = getParameter("adjective2");
            parameter3 = getParameter("adjective3");
            
            }
            
      public void paint(Graphics Screen) {
      
      screen.drawString("Testing");
      
      }
      
      
   }
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sudhakar_koundinyaCommented:
>>public void paint(Graphics Screen) {  should be
public void paint(Graphics screen) {
0
 
sudhakar_koundinyaCommented:
java  is case sensitive language
0
 
aot2002Author Commented:
ok same error



C:\Program Files\Apache Group\Apache\htdocs\school>javac rootapplet.java
rootapplet.java:17: cannot resolve symbol
symbol  : method drawString (java.lang.String)
location: class java.awt.Graphics
        screen.drawString("Testing");
              ^
1 error





import java.awt.*;

public class rootapplet extends javax.swing.JApplet {
      String parameter1;
      String parameter2;
      String parameter3;

      public void init() {
            parameter1 = getParameter("adjective1");
            parameter2 = getParameter("adjective2");
            parameter3 = getParameter("adjective3");
            
            }
            
      public void paint(Graphics screen) {
      
      screen.drawString("Testing");
      
      }
      
      
   }            
   

   
0
 
WebstormCommented:
screen.drawString("Testing",10,10);
0
 
WebstormCommented:
you need to specify the position :

    screen.drawString("Testing",x,y);
0
 
sudhakar_koundinyaCommented:
screendrawString("Testing",100,100) ;
0
 
sudhakar_koundinyaCommented:
screen.drawString("Testing",100,100) ;
0
 
WebstormCommented:
>> screen.drawString("Testing",100,100) ;
as i said.
0
 
sudhakar_koundinyaCommented:
yep at same time we both gave the answer. the first one has type-o error  :-)
0
 
aot2002Author Commented:
ok no error but shouldnt i see somtheing in the page?

 Directory of C:\Program Files\Apache Group\Apache\htdocs\school

08/10/2004  12:20 PM    <DIR>          .
08/10/2004  12:20 PM    <DIR>          ..
08/10/2004  12:20 PM                63 index.html
08/10/2004  12:19 PM                63 index.html.bak
08/10/2004  12:19 PM               684 rootapplet.class
08/10/2004  12:19 PM               424 rootapplet.java
08/10/2004  12:18 PM               422 rootapplet.java.bak
08/10/2004  11:48 AM               156 var.java
08/10/2004  11:48 AM               284 Variable.class



<applet code="rootapplet.class" height=100 width=300>
<applet>




==========================================



import java.awt.*;

public class rootapplet extends javax.swing.JApplet {
      String parameter1;
      String parameter2;
      String parameter3;

      public void init() {
            parameter1 = getParameter("adjective1");
            parameter2 = getParameter("adjective2");
            parameter3 = getParameter("adjective3");
            
            }
            
      public void paint(Graphics screen) {
      
      screen.drawString("Testing", 100,100);
      
      }
      
      
   }            
   

   
0
 
aot2002Author Commented:
i do have all plugins and all i see is a grey screen
0
 
sudhakar_koundinyaCommented:
>> ok no error but shouldnt i see somtheing in the page?

Did not get you
0
 
aot2002Author Commented:
in the webpage i should see "testing"
0
 
JK2429Commented:
drawString requires 3 parameters:
abstract  void drawString(AttributedCharacterIterator iterator, int x, int y)
Draws the text given by the specified iterator, using this graphics context's current color.
abstract  void drawString(String str, int x, int y)
Draws the text given by the specified string, using this graphics context's current font and color.

public void paint (Graphics screen)
{
screen.drawString("abc", 5,5);
}

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html
0
 
sudhakar_koundinyaCommented:
appletviewer rootapplet.java

is this working??
0
 
koushik_msCommented:
Hi aot2002,
  Try increasing the value of height parameter in the html code.
Change ...

>>   <applet code="rootapplet.class" height=100 width=300>
>>  <applet>

to
  <html><body>
  <applet code="rootapplet.class" height=300 width=300>
 </applet></body></html>

Otherwise, use smaller values for co-ordinates in drawString method call:
Change
> screen.drawString("Testing", 100,100);
to
screen.drawString("Testing", 10,10);

like Webstorm said.

Cheers!
K
0
 
sudhakar_koundinyaCommented:
there is no difference between screen.drawString("Testing", 100,100);
and screen.drawString("Testing", 10,10);

it is afterall a matter of position. only thing he/she need to do is increase the size of applet
0
 
sudhakar_koundinyaCommented:
>>   <applet code="rootapplet.class" height=100 width=300>
>>  <applet>

to
  <html><body>
  <applet code="rootapplet.class" height=300 width=300>
 </applet></body></html>

coming to above statements both are valid

the second one need to declare in html page where as user can declare in source file itself for first option

if he choose first optioon then
appletviewer rootapplet.java works
appletviewer rootapplet.html works

if user wants to see the output in browser itself

iexplore  rootapplet.html works

Best Regards
Sudhakar





0
 
aot2002Author Commented:
root applet not found error on status bar
0
 
aot2002Author Commented:
class rootapplet not found

but yet it is in the directory
 Directory of C:\Program Files\Apache Group\Apache\htdocs\school

08/10/2004  07:24 PM    <DIR>          .
08/10/2004  07:24 PM    <DIR>          ..
08/10/2004  07:23 PM                64 index.html
08/10/2004  06:50 PM                63 index.html.bak
08/10/2004  07:24 PM               498 rootapplet.class
08/10/2004  07:24 PM               430 rootapplet.java
08/10/2004  12:19 PM               424 rootapplet.java.bak
08/10/2004  11:48 AM               156 var.java
08/10/2004  11:48 AM               284 Variable.class
0
 
aot2002Author Commented:
<applet code="rootapplet.class" height=300 width=300>
</applet>





import java.awt.*;

public class rootapplet extends javax.swing.JApplet {
      String parameter1;
      String parameter2;
      String parameter3;

      public void init() {
            //parameter1 = getParameter("adjective1");
            //parameter2 = getParameter("adjective2");
            //parameter3 = getParameter("adjective3");
            
            }
            
      public void paint(Graphics screen) {
      
      screen.drawString("abc", 5,5);
      
      }
      
      
   }            
   

   
0
 
WebstormCommented:
Try:

<applet code="rootapplet.class" codebase="./" height=300 width=300>
</applet>
0
 
aot2002Author Commented:
0
 
sudhakar_koundinyaCommented:
i am able to see ur applet. place string in some other position say 25,25
0
 
aot2002Author Commented:
ok did it and recompiled it
0
 
aot2002Author Commented:
Java(TM) 2 SDK, Standard Edition
                               Version 1.4.2

to compile this on windows XP pro
0
 
aot2002Author Commented:
i am able to see ur applet.

what seems to be the issue ?
please help !
0
All Courses

From novice to tech pro — start learning today.