Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Beginner: Error with 'extends JApplet'

Options
  • 17-04-2012 6:59pm
    #1
    Registered Users 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 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