Results 1 to 4 of 4
  1. #1
    calco is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Applet not appearing as I believe it should

    The age textfield and done button dont appear, my HTML height and width are both 800.
    Can anybody see any errors I have put in the code to make it appear like this?

    The code:
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    
    public class agegreeting extends Applet implements ActionListener {
    	
    	String greeting;
    	
    	TextField nameField;
    	TextField ageField;
    	
    	public void init () {
    		setLayout (new BorderLayout());
    		Panel bottomPanel = new Panel();
    		
    		Label nameLabel = new Label ("Name: ");
    		nameField = new TextField (15);
    		
    		Label ageLabel = new Label ("Age: ");
    		ageField = new TextField (2);
    		
    		Button doneButton = new Button ("Press when done");
    		
    		bottomPanel.add (nameLabel);
    		bottomPanel.add (nameField);
    		bottomPanel.add (ageLabel);
    		bottomPanel.add (ageField);
    		bottomPanel.add (doneButton);
    		
    		doneButton.addActionListener (this);
    		
    		add (bottomPanel, BorderLayout.SOUTH);
    		
    		greeting = "";
    		}
    	
    	public void actionPerformed (ActionEvent click) {
    		
    		String name = nameField.getText ();
    		int age = new Integer (ageField.getText().trim()).intValue();
    		
    		if (age < 2) {
    			greeting = "Hello little baby!";
    			}
    		else if (age < 10) {
    			greeting = "Hey " + name +", whats up?";
    			}
    		else if (age < 16) {
    			greeting = "Hello " + name + " hows school going?";
    			}
    		else {
    			greeting = "Nice to see you again " + name;
    		}
    		}
    		
    	public void paint (Graphics g) {
    		g.drawOval (40,40, 120,150);         // Head
    		g.drawOval (57,75, 30,20);           // Left eye
    		g.drawOval (110,75, 30,20);          // Right eye
    		g.fillOval (68,81, 10,10);           // pupil (left)
    		g.fillOval (121,81, 10,10);          // pupil (right)
    		g.drawOval (85,100, 30,30);          // Nose
    		g.fillArc (60,125,80,40, 180,180);   // Mouth
    		g.drawOval (25,92, 15,30);           // Left ear
    		g.drawOval (160,92, 15,30);          // Right ear
    		
    		g.drawString (greeting, 190,150);
    	}
    }
    How I see it:
    Applet not appearing as I believe it should-nkajz.jpg

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Applet not appearing as I believe it should

    Moved from New to Java

    db
    Last edited by DarrylBurke; 08-08-2012 at 05:33 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Applet not appearing as I believe it should

    1. Why, in this day and age, are you using java.awt.Applet which has been superseded by javax.swing.JApplet more than 10 years ago?

    2. Every painting method override should invoke the super implementation. Go through this Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    3. After changing the value of greeting you need to repaint()

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    calco is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: Applet not appearing as I believe it should

    I'm completely new to java and I just followed what the guide that I found told me to do.
    I'll go through that lesson tonight.
    Thanks, may have been 10 years behind if it weren't for the help!

Similar Threads

  1. Java Applet button not appearing
    By Barbados in forum New To Java
    Replies: 12
    Last Post: 01-21-2012, 09:42 PM
  2. Panel not appearing in JFrame
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 03-29-2011, 07:53 PM
  3. jfilechooser not appearing
    By letter5 in forum New To Java
    Replies: 5
    Last Post: 02-15-2009, 04:45 PM
  4. why isn't my combobox appearing on my frame?
    By matpj in forum AWT / Swing
    Replies: 9
    Last Post: 01-29-2009, 03:46 PM
  5. Log messages are not appearing in my log file
    By indu_raj in forum Java Servlet
    Replies: 1
    Last Post: 08-08-2007, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •