473,394 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

help with this program??

I need to create this with java but for some reasons it is not working out for me.All that needs to be placed in a textarea......HELP!!

The cell phone must contain an array to hold a list of contacts. Each contact has a name and number. Make the size of the array 5 and be sure to account for increasing the array size if more than 5 numbers are added.
You should be able to add a contact to the list.
Sep 28 '06 #1
7 1639
r035198x
13,262 8TB
I need to create this with java but for some reasons it is not working out for me.All that needs to be placed in a textarea......HELP!!

The cell phone must contain an array to hold a list of contacts. Each contact has a name and number. Make the size of the array 5 and be sure to account for increasing the array size if more than 5 numbers are added.
You should be able to add a contact to the list.
I am assuming you'd have to create a Contact class that stores the name and number.


Do you specifically have to use an array because an ArrayList would be more appropriate?
If you have to use array then
you would need an integer to store the maxPossible size of the array
your addContact(Contact c) method should check to see if the length of the array would exceed the maxPossible if one item is added. If true then create a bigger array, copy all existing contacts into it, add the new array and set it as the current lists of contacts.

What do you mean by
All that needs to be placed in a textarea
?
Sep 28 '06 #2
thank you for the repy but would you happen to have a code that i could go by because words really dont apply to me as much as seeing the data.....and i mean when the data is shown it has to be shown in a textarea?
Sep 28 '06 #3
r035198x
13,262 8TB
thank you for the repy but would you happen to have a code that i could go by because words really dont apply to me as much as seeing the data.....and i mean when the data is shown it has to be shown in a textarea?
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.util.*;
  3. import java.awt.event.*;
  4. class Contact {
  5.     public Contact(String name, String number) {
  6.         this.name = name;
  7.         this.number = number;
  8.     }
  9.     public String toString() {
  10.         return name + " : " + number;
  11.     }
  12.  
  13.     String name;
  14.     String number;
  15. }
  16.  
  17.  
  18. public class BabyNailah extends JFrame implements ActionListener {
  19.  
  20.     public BabyNailah() {
  21.         setSize(300, 300);
  22.         setTitle("BabyNailah");
  23.         JPanel p = new JPanel();
  24.         area = new JTextArea();
  25.         JButton b = new JButton("Add Contact");
  26.         b.setActionCommand("add");
  27.         b.addActionListener(this);
  28.         p.add(b);
  29.         getContentPane().add(area, "Center");
  30.         getContentPane().add(b, "South");
  31.         setVisible(true);
  32.     }
  33.  
  34.  
  35.     public static void main(String[] args) {
  36.         BabyNailah b = new BabyNailah();
  37.  
  38.     }
  39.     public void addContact(Contact c) {
  40.         contacts.add(c);
  41.         area.append(c.toString());
  42.         area.append("\n");
  43.     }
  44.     public void actionPerformed(ActionEvent action) {
  45.         String name = JOptionPane.showInputDialog(null, "Name");
  46.         String number = JOptionPane.showInputDialog(null, "Number");
  47.         Contact c = new Contact(name, number);
  48.         addContact(c);
  49.     }
  50.  
  51.     JTextArea area;
  52.     List<Contact> contacts = new ArrayList<Contact>();
  53. }
Now that I've done all this for you, could you please add a delete contact button and make it work?
Sep 28 '06 #4
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();


}
Sep 28 '06 #5
Your problem is to simulate certain aspects of a cell phone. The following features are required for the first assignment.


The interface must be a GUI that resembles a cell phone.
The cell phone must contain an array to hold a list of contacts. Each contact has a name and number. Make the size of the array 5 and be sure to account for increasing the array size if more than 5 numbers are added.
You should be able to add a contact to the list.
The Cell phone should have a selection that allows you to view your telephone number.
Modify the phone contacts to be stored in a link list.
The contacts must be stored in alphabetical order
You must have an option to edit a contact.
You must have an option to delete a contact


That is what i should have to this point but i dont have none of that because i cant get it to work
Sep 28 '06 #6
r035198x
13,262 8TB
Did ever bother to look at the code I have given you?
Sep 29 '06 #7
i did but it dont work with the code i already have
Sep 29 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: atlanta | last post by:
this is a simple C++ program to write. "Write a complete and functioning structured program that successfully compiles on Visual C++ 6, that uses two-dimensional array (5x5) that stores...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
2
by: sunfox | last post by:
Please help!! I have a difficulty in writing an assignment which is related to Visual C++ V6.0. Can anybody here assist me to write a program which is able to run under DOS? The program will be...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
2
by: prash | last post by:
Hi everybody, I would like to request all the members to help me find the source code for the following : 1.C program for error detecting code: CRC-CCITT and CRC -32. 2.c Program for...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
2
by: Bsnpr8 | last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really...
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.