0
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class string4 extends Applet implements TextListener{
Label lblMessage;
TextField txtText1;
String strString1="";
Font fntFont=new Font("Georgia",Font.Bold,20);
public void init(){
lblMessage=new Label("enter some words");
add(lblMessage);
txtText1=new TextField(20);
add(txtText1);
txtText1.addTextListener(this);
}
public void paint(Graphics objG){
objG.setFont(fntFont);
objG.drawString="strString 1,202,62";
}
public void textValueChanged(TextEvent objE){
strString1=txtText1.getText();
}
}

this the edited one,,I tried it but still have an error this is what the cmd says C:\sample java>javac string4.java string4.java:8: cannot find symbol symbol : variable Bold location: class java.awt.Font Font fntFont=new Font("Georgia",Font.Bold,20);

string4.java:18: cannot find symbol symbol : variable drawString location: class java.awt.Graphics objG.drawString="strString 1,202,62";

2 errors

Junel
  • 17
  • 1
  • 4

3 Answers3

3

Try to write

Font fntFont=new Font("Georgia",Font.Bold,20);

you are writing

fntFont=new Font("Georgia",Font.Bold,20);

where there is no type definition.

And you need to import that on top too.

If I'm not wrong you are not using IDE. If so,I'm suggesting you to use a IDE,which will help you to get rid doff of all these type of compile time errors,I'm sure that saves you lot of time.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • I'd tried it and the command prompt tellsC:\sample java>javac string4.java string4.java:8: cannot find symbol symbol : variable Bold location: class java.awt.Font Font fntFont=new Font("Georgia",Font.Bold,20); ^ string4.java:18: cannot find symbol symbol : variable drawString location: class java.awt.Graphics objG.drawString="strString 1,202,62"; ^ 2 errors – Junel Aug 18 '13 at 09:59
2

You are missing to define the type for

fntFont

Java is a strongly typed language and hence you need to define the type of all the variables.

Replace this :

fntFont=new Font("Georgia",Font.Bold,20);

with

Font fntFont=new Font("Georgia",Font.Bold,20);
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0
fntFont=new Font("Georgia",Font.Bold,20);// You have to define the type 

In java When we are creating a object we have to do as follows

Type(Class Name) name_for_object=new Type(input argument here if accept by constructor);

Use

Font fntFont=new Font("Georgia",Font.Bold,20);
Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115