5 Replies - 8587 Views - Last Post: 03 March 2009 - 10:34 PM Rate Topic: -----

#1 MacJava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 17-February 09

Telephone Keypad Applet

Post icon  Posted 03 March 2009 - 04:13 PM

These are the requirements of the program: The Continental Company wants you to create an applet that produces a telephone keypad. Create an applet that displays a text area across the top, similar to a LCD panel of most cell phones. Include buttons for the 10 digits, a star key (*), and a pound key (#). When clicked, the appropriate digit or symbol should display in the text area. No additional functionality is required until Continental approves your prototype.

This is what I have so far. I get an error on line 37
* illegal start of expression *

Also, I'm not 100% sure if I'm doing this the proper way...I'm really new to Java :blink: , I will really appreciate your help. Thanks for reading my post. :D

import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;

public class telephoneKeypad extends JApplet 
{

	public static void main (String [] args) 
	{
 		new telephoneKeypad().setVisible(true);
 	}

	public telephoneKeypad () 
	{
		Panel pnlKeyPad = new Panel();
		  GridLayout gridLayout1 = new GridLayout();
		  Button btnZero = new Button();
		  Button btnOne = new Button();
		  Button btnTwo = new Button();
		  Button btnThree = new Button();
 		Button btnFour = new Button();
		  Button btnFive = new Button();
		  Button btnSix = new Button();
		  Button btnSeven = new Button();
		  Button btnEight = new Button();
		  Button btnNine = new Button();
		  Button btnStar = new Button();
		  Button btnHash = new Button();
  
   		TextField tfNumber = new TextField();
		  Button btnDial = new Button();
		  BorderLayout borderLayout1 = new BorderLayout();
		  Panel pnlNumberEntry = new Panel();
		  FlowLayout flowLayout1 = new FlowLayout();
 
 		
		  public void init() // line 37
		  {
			this.setSize(new Dimension(175, 231));
			gridLayout1.setRows(4);
			gridLayout1.setColumns(3);
	
			btnOne.setLabel("1");
			btnTwo.setLabel("2");
			btnThree.setLabel("3");
			btnFour.setLabel("4");
			btnFive.setLabel("5");
			btnSix.setLabel("6");
			btnSeven.setLabel("7");
			btnEight.setLabel("8");
			btnNine.setLabel("9");
			btnStar.setLabel("*");
			btnZero.setLabel("0");
			btnHash.setLabel("#");
			btnDial.setLabel("Dial");
	
			pnlNumberEntry.setLayout(flowLayout1);
			pnlKeyPad.setLayout(gridLayout1);
			this.setLayout(borderLayout1);
			this.add(pnlNumberEntry, BorderLayout.NORTH);
			pnlNumberEntry.add(tfNumber, null);
			pnlNumberEntry.add(btnDial, null);
			this.add(pnlKeyPad, BorderLayout.CENTER);
			pnlKeyPad.add(btnOne, null);
			pnlKeyPad.add(btnTwo, null);
			pnlKeyPad.add(btnThree, null);
			pnlKeyPad.add(btnFour, null);
			pnlKeyPad.add(btnFive, null);
			pnlKeyPad.add(btnSix, null);
			pnlKeyPad.add(btnSeven, null);
			pnlKeyPad.add(btnEight, null);
			pnlKeyPad.add(btnNine, null);
			pnlKeyPad.add(btnStar, null);
			pnlKeyPad.add(btnZero, null);
			pnlKeyPad.add(btnHash, null);
	
 		}
; 		
 	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Telephone Keypad Applet

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Telephone Keypad Applet

Posted 03 March 2009 - 04:47 PM

You have an extra ; at ened of your code
	
		}
;			  // <------
	}
}



Better to use a GridLayout(4, 3)

There is no main() method in an Applet but an init() method.... you are writting an Application even if you extend JApplet
Was This Post Helpful? 0
  • +
  • -

#3 MacJava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 17-February 09

Re: Telephone Keypad Applet

Posted 03 March 2009 - 09:20 PM

View Postpbl, on 3 Mar, 2009 - 03:47 PM, said:

You have an extra ; at ened of your code
	
		}
;			  // <------
	}
}



Better to use a GridLayout(4, 3)

There is no main() method in an Applet but an init() method.... you are writting an Application even if you extend JApplet


Quote

I'm really confused on how to initiate an applet and where exactly I have to initiate them....

Now it's telling me that I have 2 errors.
'illegal start of expression'
';' expected...

Thanks for taking your time to read and help me out.

import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;

public class telephoneKeypad extends JApplet 
{
	public void init()
		  {
			this.setSize(new Dimension(175, 231));
			gridLayout(4, 3);
	
 			new telephoneKeypad().setVisible(true);
 

	public void telephoneKeypad () 
	{
		Panel pnlKeyPad = new Panel();
		  GridLayout gridLayout1 = new GridLayout();
		  Button btnZero = new Button();
		  Button btnOne = new Button();
		  Button btnTwo = new Button();
		  Button btnThree = new Button();
 		Button btnFour = new Button();
		  Button btnFive = new Button();
		  Button btnSix = new Button();
		  Button btnSeven = new Button();
		  Button btnEight = new Button();
		  Button btnNine = new Button();
		  Button btnStar = new Button();
		  Button btnHash = new Button();
  
   		TextField tfNumber = new TextField();
		  Button btnDial = new Button();
		  BorderLayout borderLayout1 = new BorderLayout();
		  Panel pnlNumberEntry = new Panel();
		  FlowLayout flowLayout1 = new FlowLayout();
 
 		
	  
		
	
			btnOne.setLabel("1");
			btnTwo.setLabel("2");
			btnThree.setLabel("3");
			btnFour.setLabel("4");
			btnFive.setLabel("5");
			btnSix.setLabel("6");
			btnSeven.setLabel("7");
			btnEight.setLabel("8");
			btnNine.setLabel("9");
			btnStar.setLabel("*");
			btnZero.setLabel("0");
			btnHash.setLabel("#");
			btnDial.setLabel("Dial");
	
			pnlNumberEntry.setLayout(flowLayout1);
			pnlKeyPad.setLayout(gridLayout1);
			this.setLayout(borderLayout1);
			this.add(pnlNumberEntry, BorderLayout.NORTH);
			pnlNumberEntry.add(tfNumber, null);
			pnlNumberEntry.add(btnDial, null);
			this.add(pnlKeyPad, BorderLayout.CENTER);
			pnlKeyPad.add(btnOne, null);
			pnlKeyPad.add(btnTwo, null);
			pnlKeyPad.add(btnThree, null); 
			pnlKeyPad.add(btnFour, null);
			pnlKeyPad.add(btnFive, null);
			pnlKeyPad.add(btnSix, null);
			pnlKeyPad.add(btnSeven, null);
			pnlKeyPad.add(btnEight, null);
			pnlKeyPad.add(btnNine, null);
			pnlKeyPad.add(btnStar, null);
			pnlKeyPad.add(btnZero, null);
			pnlKeyPad.add(btnHash, null);
	
 		}
		
 	}
}


Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Telephone Keypad Applet

Posted 03 March 2009 - 09:23 PM

First, you need a } to finish off the init() method...and second...

This is how you set a layout...

this.setLayout(new GridLayout(4,3));


You don't just call some gridLayout method.

This post has been edited by Locke: 03 March 2009 - 09:23 PM

Was This Post Helpful? 2
  • +
  • -

#5 MacJava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 17-February 09

Re: Telephone Keypad Applet

Posted 03 March 2009 - 10:02 PM

I just have a question...Now it's telling me that it cannot find symbol class GridLayout, Button, Panel, Dimension and so on....I have 42 errors :angry:
Am I forgetting to import something else???
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;
import java.awt.event.*;

public class telephoneKeypad extends JApplet 
{
	public void init()
		  {
			  this.setLayout(new GridLayout(4,3));
			this.setSize(new Dimension(175, 231));
		
	
 			new telephoneKeypad().setVisible(true);
 			
 		}
 

	public void telephoneKeypad () 
	{
		Panel pnlKeyPad = new Panel();
		  GridLayout gridLayout1 = new GridLayout();
		  Button btnZero = new Button();
		  Button btnOne = new Button();
		  Button btnTwo = new Button();
		  Button btnThree = new Button();
 		Button btnFour = new Button();
		  Button btnFive = new Button();
		  Button btnSix = new Button();
		  Button btnSeven = new Button();
		  Button btnEight = new Button();
		  Button btnNine = new Button();
		  Button btnStar = new Button();
		  Button btnHash = new Button();
  
   		TextField tfNumber = new TextField();
		  Button btnDial = new Button();
		  BorderLayout borderLayout1 = new BorderLayout();
		  Panel pnlNumberEntry = new Panel();
		  FlowLayout flowLayout1 = new FlowLayout();
 
 		
	  
		
	
			btnOne.setLabel("1");
			btnTwo.setLabel("2");
			btnThree.setLabel("3");
			btnFour.setLabel("4");
			btnFive.setLabel("5");
			btnSix.setLabel("6");
			btnSeven.setLabel("7");
			btnEight.setLabel("8");
			btnNine.setLabel("9");
			btnStar.setLabel("*");
			btnZero.setLabel("0");
			btnHash.setLabel("#");
			btnDial.setLabel("Dial");
	
			pnlNumberEntry.setLayout(flowLayout1);
			pnlKeyPad.setLayout(gridLayout1);
			this.setLayout(borderLayout1);
			this.add(pnlNumberEntry, BorderLayout.NORTH);
			pnlNumberEntry.add(tfNumber, null);
			pnlNumberEntry.add(btnDial, null);
			this.add(pnlKeyPad, BorderLayout.CENTER);
			pnlKeyPad.add(btnOne, null);
			pnlKeyPad.add(btnTwo, null);
			pnlKeyPad.add(btnThree, null); 
			pnlKeyPad.add(btnFour, null);
			pnlKeyPad.add(btnFive, null);
			pnlKeyPad.add(btnSix, null);
			pnlKeyPad.add(btnSeven, null);
			pnlKeyPad.add(btnEight, null);
			pnlKeyPad.add(btnNine, null);
			pnlKeyPad.add(btnStar, null);
			pnlKeyPad.add(btnZero, null);
			pnlKeyPad.add(btnHash, null);
	
 	}
 }


Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Telephone Keypad Applet

Posted 03 March 2009 - 10:34 PM

just

import java.awt.*;
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1