473,785 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error on drawString

2 New Member
I'm just learning how to program in java. I wrote my first java program, but got an error. Here is my program.


import java.awt.*;
import java.applet.*;
public class me extends Applet
{
public void init ()
{
String AuthorName;
AuthorName = "Steven Spielberg";
}
public void paint (Graphics x)
{
x.drawString (AuthorName,50, 50);
}
}


------------------- END OF PROGRAM ------------------------------

When I compiled it with command "javac <file_name.java >" (ie: javac me.java), it got an error. Error showed:

% javac me.java
me.java:12: cannot find symbol
symbol : variable AuthorName
location: class me
x.drawString (AuthorName,50, 50);
^
1 error

----------------------------------------------------------------------------------
Any help is appreciated. Thank you in advance.

-simon
Jan 24 '08 #1
5 2004
BigDaddyLH
1,216 Recognized Expert Top Contributor
If this is your first program, I would say, slow down! Learn the basics before trying to write GUI programs, and avoid applets as long as possible, perhaps forever. Start here: http://java.sun.com/docs/books/tutor...ted/index.html
Jan 24 '08 #2
simon28317
2 New Member
If this is your first program, I would say, slow down! Learn the basics before trying to write GUI programs, and avoid applets as long as possible, perhaps forever. Start here: http://java.sun.com/docs/books/tutor...ted/index.html

Thank you. It's good advice. I had checked out the link, and it a good link.

-simon
Jan 25 '08 #3
r035198x
13,262 MVP
Thank you. It's good advice. I had checked out the link, and it a good link.

-simon
Basically the scoping did you in there. You create something in one method and try to access it from another method. Better declare that String outside that init method.
NB. SmallDaddy's advice still holds though.
Jan 25 '08 #4
tulika004
1 New Member
Hey

Do not declare the variable locally in the function. It is not being recognised datswhy
Jan 25 '08 #5
Kid Programmer
176 New Member
The problem is you are telling it to draw the String AuthorName but it doesn't know what AuthorName is. You need to declare the variable AuthorName of the string type so that it will know what to print out.
Jun 19 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2863
by: nu b | last post by:
Hello all. I am new and I am having a tough time spotting my error here. The idea is to produce an applet that will have a JButton which I can push to display the string myName. Later I will make it so that it will chage the font size and style, but for now I can't even get it to display the String. It compiles fine but when I launch it in the browser or with the appletviewer, it shows the button and nothing happens when I click it. Can...
1
4364
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot: http://www.lowrad.net/files/alignment_screenshot.jpg As you can see I am printing four different text in each of the the parts of this image. ( The three parts are three images)
2
22312
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown below. I am running IIS5 on WinXP Pro. Server Error in '/Chapter04' Application. ---------------------------------------------------------------------------- ---- A generic error occurred in GDI+. Description: An unhandled exception occurred...
18
28758
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
0
1247
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
14
4110
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
2
2541
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So what I'm trying to do is print out a label so what I basically did is use Graphics.DrawString passing in the text of the label, the font of the label and the rectangle which represents the label (because it's set to autosize this should be the right...
1
2126
by: Anila | last post by:
Hi........ My problem is i wrote a program for drawing a line in Csharp. My code is using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
9
2973
by: kynos | last post by:
I would like to paint a box using DrawString, standard Unicode characters (box drawings characters) and monospaced font. Unfortunately for some fonts painted lines contain a break. Example code, in whom one can see the error: private void Form1_Paint (object sender, PaintEventArgs e) ( Font font = new Font ( "Courier New", 9);
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.