This is what i have for my cellphone program could you please make any corrections because it is not working???I will post what i should have in a minute
CODE:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CellPhone extends Applet implements ActionListener
{
TextArea textarea;
Contacts[]contacts;
Contacts[]temp;
int numberValue = 0;
int nameArrayIndex = 0;
String stringValue = "";
String [] nameArray = { "285-322-1543 Jonathan Hunter",
"404-505-7898 Sandra Hamilton",
"876-360-5754 Jermaine Ellis",
"718-997-0990 Dad at work",
"301-675-9867 Pizza Hut",
};
JLabel phoneNumberLabel,dialLabel,ViewNumberLabel,StoreNu mberLabel,phoneLabel;
Font italic =new Font("Helvetica", Font.ITALIC,15);
JButton numNine,numEight,numSeven,numSix,numFive,numFour,n umThree,numTwo,numOne,numZero,numStar,numPound,dia lButton,clearButton,StoreNumberButton,ViewNumberBu tton;
public void init()
{
//size=5;
//contacts=new Contacts[size];
//current = 0;
Container container = new Container();
container.setLayout( new FlowLayout() );
container.setBackground(Color.black);
container.setLayout(new GridLayout(4,4,4,4));
int rows = 10;
int cols = 30;
textarea = new TextArea("", rows, cols);
phoneLabel = new JLabel( "Sprint" );
phoneLabel.setFont(italic);
container.add( phoneLabel);
ViewNumberButton = new JButton( "Contacts" );
ViewNumberButton.addActionListener( this );
container.add(ViewNumberButton);
clearButton = new JButton( "Clear" );
clearButton.addActionListener( this );
container.add(clearButton);
dialButton = new JButton( "Dial" );
dialButton.addActionListener( this );
container.add(dialButton);
StoreNumberButton = new JButton( "Store" );
StoreNumberButton.addActionListener( this );
container.add(StoreNumberButton);
numNine = new JButton( "9" );
numNine.addActionListener( this );
container.add(numNine);
numEight = new JButton( "8" );
numEight.addActionListener( this );
container.add(numEight);
numSeven = new JButton( "7" );
numSeven.addActionListener( this );
container.add(numSeven);
numSix = new JButton( "6" );
numSix.addActionListener( this );
container.add(numSix);
numFive = new JButton( "5" );
numFive.addActionListener( this );
container.add(numFive);
numFour = new JButton( "4" );
numFour.addActionListener( this );
container.add(numFour);
numThree= new JButton( "3" );
numThree.addActionListener( this );
container.add(numThree);
numTwo = new JButton( "2" );
numTwo.addActionListener( this );
container.add(numTwo);
numOne = new JButton( "1" );
numOne.addActionListener( this );
container.add(numOne);
numStar = new JButton( "*" );
numStar.addActionListener( this );
container.add(numStar);
numZero = new JButton( "0" );
numZero.addActionListener( this );
container.add(numZero);
numPound = new JButton( "#" );
numPound.addActionListener( this );
container.add(numPound);
Panel displayPanel= new Panel();
displayPanel.setLayout (new BorderLayout ());
displayPanel.add("Center",phoneLabel);
add(textarea,BorderLayout.SOUTH);
add("Center",phoneLabel);
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new GridLayout(1, 1, 4, 4));
buttonPanel.add("West",ViewNumberButton);
buttonPanel.add("Center",dialButton);
buttonPanel.add("East",StoreNumberButton);
buttonPanel.add("North",clearButton);
add("West", buttonPanel);
Panel numberPanel= new Panel();
numberPanel.setLayout(new GridLayout(1, 1, 6, 6));
numberPanel.add("West", numOne);
numberPanel.add("Center", numTwo);
numberPanel.add("East", numThree);
add("South",numberPanel);
Panel number2Panel= new Panel();
number2Panel.setLayout(new GridLayout(1, 1, 6, 4));
number2Panel.add("West", numFour);
number2Panel.add("Center", numFive);
number2Panel.add("East", numSix);
add("East",number2Panel);
Panel number3Panel=new Panel();
number3Panel.setLayout(new GridLayout(1, 1, 4, 4));
number3Panel.add("West", numSeven);
number3Panel.add("Center", numEight);
number3Panel.add("East", numNine);
add("South",number3Panel);
Panel number4Panel= new Panel();
number4Panel.setLayout(new GridLayout(1, 1, 4,0));
number4Panel.add("West", numStar);
number4Panel.add("Center", numZero);
number4Panel.add("East", numPound);
add("South",number4Panel);
}
public void ViewNumber()
{
if(nameArray==null)
return;
else
if(nameArray!=null);
for(int k=0;k<nameArray.length;k++)
{
textarea.setText(nameArray[k]);
//textarea.setText(" 909-765-4543 Marquis Hamilton"+"\n"+"767-222-3345 Jason Williams"+"\n"+"876-360-5454 Kamal Hamilton"+"\n"+"718 493 5707 Jonathan Mattews"+"\n"+" 347-917-9543 Chrustyna Larkin");
}
}
public void clear()
{
textarea.setText("");
//Here you should have deleted the last character in the text area
//Do a little research and find out more about the TextArea class.
}
//public void ensureCapacity()
// {
// temp = new Contacts[size*2];
// for(int m=0;m<size;m++)
// {
// temp[m]=contacts[m];
// }
// contacts=temp;
// size*=2;
// }
// This is not good enough! You never place the number in the array!
public void addContact(Contact c)
{
//contact.add(c);
area.append(c.toString());
area.append("\n");
}
public void actionPerformed(ActionEvent action)
{
String name = JOptionPane.showInputDialog(null, "Name");
String number = JOptionPane.showInputDialog(null, "Number");
Contact c = new Contact(name, number);
addContact(c);
}
JTextArea area;
}
public void actionPerformed( ActionEvent thisEvent )
{
Object source = thisEvent.getSource();
if(source == ViewNumberButton)
ViewNumber();
if(source==clearButton)
clear();
if(source==StoreNumberButton)
addContact();
}