Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Beginner: Error with 'extends JApplet'

  • 17-04-2012 06:59PM
    #1
    Registered Users, Registered Users 2 Posts: 8,324 ✭✭✭


    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 // error does not appear when I remove 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!


Comments

  • Registered Users, Registered Users 2 Posts: 8,324 ✭✭✭chrislad


    Never mind!

    I used import javax.swing.* last time and didn't use the .* this time and import the JApplet, just the JOptionPane

    *red face*


Advertisement