Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Beginner: Error with 'extends JApplet'

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Beginner: Error with 'extends JApplet'

    Hey,

    I have a bit of history with programming about 6 years ago with C++ when I dropped out of college. However, I am resuming my studies but the course has changed to a more Java based one so I am spending the next few months teaching myself Java. At the moment, I am waiting for a new book to arrive and am using an old version of Deitel and Deitel Java - How to Program, which references Netscape Communicator so enough said!

    Anyways, I'm just trudging towards the general tutorials and opening chapters and I've not got all the concepts straight in my head yet. The code is messy as I'm not doing anything with arrays yet.

    import javax.swing.JOptionPane;
    import java.awt.Graphics;
     
    public class PosNegZero extends JApplet
    {
     
    	String entry1, entry2, entry3, entry4, entry5; 
    	double ent1, ent2, ent3, ent4, ent5, noP, noN, no0;
     
     
    	public void init() {
     
    		no0 = 0 ; noP = 0; noN = 0;
    		entry1 = JOptionPane.showInputDialog("Enter 1st Number: ");
    		ent1 = Double.parseDouble (entry1);
    		entry2 = JOptionPane.showInputDialog("Enter 2nd Number: ");
    		ent2 = Double.parseDouble (entry2);
    		entry3 = JOptionPane.showInputDialog("Enter 3rd Number: ");
    		ent3 = Double.parseDouble (entry3);
    		entry4 = JOptionPane.showInputDialog("Enter 4th Number: ");
    		ent4 = Double.parseDouble (entry4);
    		entry5 = JOptionPane.showInputDialog("Enter 5th Number: ");
    		ent5 = Double.parseDouble (entry5);
     
    		if (ent1 == 0)
    			no0++;
    		else if (ent1 > 0)
    			noP++;
    		else if (ent1 < 0)
    			noN++;
     
    		if (ent2 == 0)
    			no0++;
    		else if (ent2 > 0)
    			noP++;
    		else if (ent2 < 0)
    			noN++;
     
    		if (ent3 == 0)
    			no0++;
    		else if (ent3 > 0)
    			noP++;
    		else if (ent3 < 0)
    			noN++;
     
    		if (ent4 == 0)
    			no0++;
    		else if (ent4 > 0)
    			noP++;
    		else if (ent4 < 0)
    			noN++;
     
    		if (ent5 == 0)
    			no0++;
    		else if (ent5 > 0)
    			noP++;
    		else if (ent5 < 0)
    			noN++;
     
    	}
     
     
     
    public void paint (Graphics g)
    {
    	g.drawString(no0 + " zero numbers\n" + noP + " positive numbers\n" + noN + " negative numbers\n", 25, 25);
    }
     
    }

    What I think I am doing is declaring an overall Class PosNegZero, and declaring global String and Double variables to be used in the classes init() and print(Graphics g)

    The error I am getting is JApplet cannot be resolved to a type

    The error could be down to me either not using the variables properly or not understanding Applets. I can output the same code to a command line or using showMessage but I want to use an applet for the purposes of this book question.

    Thanks!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,612
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Beginner: Error with 'extends JApplet'

    You forgot to import JApplet.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    chrisob (April 17th, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Beginner: Error with 'extends JApplet'

    Argh! I had done it in a previous example and just used import javax.swing.* rather than import JApplet and JOptionPane!

    Is it better to just use swing.* or awt.* unless you need to call a subdirectory?

    Oh, and thanks!

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,612
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Beginner: Error with 'extends JApplet'

    I like to use the full import statement without any wildcards, just because it lets you know exactly what you're using in that class. Wildcards don't add any overhead, they just make it less clear what the class is doing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Beginner: Error with 'extends JApplet'

    I'm sure it will make more sense to me (classes and importing etc) once I get a bit more practice. Expect to see a lot of me!!!

    Thanks again! This is why I miss doing this in college as it's good to have heads to throw things at!

Similar Threads

  1. NEED HELP! Beginner JApplet Problems
    By bam0792 in forum AWT / Java Swing
    Replies: 4
    Last Post: February 20th, 2012, 02:52 PM
  2. [SOLVED] Bad operand types for binary operator '<' error issue (beginner)
    By mju516 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 27th, 2012, 10:33 PM
  3. Beginner, Reading from file error
    By Lynce in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 27th, 2011, 07:31 AM
  4. error with a java game..(beginner)
    By Skat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 1st, 2010, 03:04 PM
  5. keyword Extends
    By chronoz13 in forum Object Oriented Programming
    Replies: 3
    Last Post: November 27th, 2009, 07:30 AM