This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

having trouble running logo program

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, John

I saved my source code to D:\.....\logo.java but i still get the following error:-
Unable to load class logo/.

N.B: I compiled it before running it, below are the source codes:

importjava.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.Graphics;
import java.util.Vector;
public class logo extends Applet{

pulic void init(){

}

pulic void stop(){


}
public void paint (Graphics pg)
{
setBackground (Color.black);
pg.setColor(Color.blue);
pg.fillOval (5, 0, 200, 200);
pg.setColor(Color.white);
pg.fillOval(25,20,160,160);
pg.setColor(Color.blue);
pg.fillRect(0,200,240,25);
pg.setColor(Color.yellow);
pg.drawString("QUALITY EDUCATION FOR ALL",0,215);
pg.setColor(Color.lightGray);
pg.fillRect(220,20,250,135);
pg.setColor (Color.black);
pg.drawString ("Eric", 300, 80);
pg.setColor(Color.yellow);
pg.drawString ("OOP With Java Programmer", 300, 100);
pg.drawString ("THE OPEN UNIVERSTY OF TANZANIA",240 , 36);
}
}
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the command you used to compile and run?
 
Eric Mato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran it on Eclipse so, I hit debug and then it brought the error, unable to load class logo
 
Master Rancher
Posts: 3845
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class is an applet.  It does  not use the main method so it would not be run in a command window with the java command. It runs in a browser and needs an html page with an applet tag to execute.
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. I've added this to our Applets and Eclipse forums in hopes someone there knows.
 
Eric Mato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Norm Radder so, what should I add to the code in order for it to run?
 
Norm Radder
Master Rancher
Posts: 3845
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most current browsers do not support applets.  The one way to execute simple applets is to use the AppletViewer that is included in the JDK's bin folder.
Create a small html page with an applet tag that references your code and pass that as a command line argument to the appletviewer command.

It is also possible to add the applet tag code in a comment to the source program and pass the source program to the appletviewer program.  For example:
C:\Program Files\Java\jdk1.8.0_60\bin\appletviewer.exe D:\JavaDevelopment\Testing\ForumQuestions12\MyLogo.java

In the source:
 
Eric Mato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I will try and keep you posted.
 
Marshal
Posts: 69753
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use copy'n'paste in future; you have “importjava.awt.event.*;” in the first line of code, which has a compiler error in, so I think you have copied it wrongly.
And as people have already told you, nobody uses applets any more. I hope you aren't being taught about applets.
 
Marshal
Posts: 3144
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:... in the first line of code, which has a compiler error in, so I think you have copied it wrongly.


Also typos with:
pulic void init()
pulic void stop()


And import java.Graphics; should probably be import java.awt.Graphics;
 
Ron McLeod
Marshal
Posts: 3144
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run the Applet in the IDE - Eclipse has a built-in Applet Viewer:

 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic