help with this program??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babynailah
    New Member
    • Sep 2006
    • 7

    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......H ELP!!

    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.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by babynailah
    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......H ELP!!

    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(Cont act 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
    ?

    Comment

    • babynailah
      New Member
      • Sep 2006
      • 7

      #3
      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?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by babynailah
        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?
        Code:
        import javax.swing.*;
        import java.util.*;
        import java.awt.event.*;
        class Contact {
        	public Contact(String name, String number) {
        		this.name = name;
        		this.number = number;
        	}
        	public String toString() {
        		return name + " : " + number;
        	}
        
        	String name;
        	String number;
        }
        
        
        public class BabyNailah extends JFrame implements ActionListener {
        
        	public BabyNailah() {
        		setSize(300, 300);
        		setTitle("BabyNailah");
        		JPanel p = new JPanel();
        		area = new JTextArea();
        		JButton b = new JButton("Add Contact");
        		b.setActionCommand("add");
        		b.addActionListener(this);
        		p.add(b);
        		getContentPane().add(area, "Center");
        		getContentPane().add(b, "South");
        		setVisible(true);
        	}
        
        
        	public static void main(String[] args) {
        		BabyNailah b = new BabyNailah();
        
        	}
        	public void addContact(Contact c) {
        		contacts.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;
        	List<Contact> contacts = new ArrayList<Contact>();
        }
        Now that I've done all this for you, could you please add a delete contact button and make it work?

        Comment

        • babynailah
          New Member
          • Sep 2006
          • 7

          #5
          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.bor der.*;
          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 phoneNumberLabe l,dialLabel,Vie wNumberLabel,St oreNumberLabel, phoneLabel;
          Font italic =new Font("Helvetica ", Font.ITALIC,15) ;


          JButton numNine,numEigh t,numSeven,numS ix,numFive,numF our,numThree,nu mTwo,numOne,num Zero,numStar,nu mPound,dialButt on,clearButton, StoreNumberButt on,ViewNumberBu tton;

          public void init()
          {


          //size=5;
          //contacts=new Contacts[size];
          //current = 0;



          Container container = new Container();
          container.setLa yout( new FlowLayout() );


          container.setBa ckground(Color. black);
          container.setLa yout(new GridLayout(4,4, 4,4));



          int rows = 10;
          int cols = 30;
          textarea = new TextArea("", rows, cols);


          phoneLabel = new JLabel( "Sprint" );
          phoneLabel.setF ont(italic);
          container.add( phoneLabel);

          ViewNumberButto n = new JButton( "Contacts" );
          ViewNumberButto n.addActionList ener( this );
          container.add(V iewNumberButton );

          clearButton = new JButton( "Clear" );
          clearButton.add ActionListener( this );
          container.add(c learButton);

          dialButton = new JButton( "Dial" );
          dialButton.addA ctionListener( this );
          container.add(d ialButton);

          StoreNumberButt on = new JButton( "Store" );
          StoreNumberButt on.addActionLis tener( this );
          container.add(S toreNumberButto n);

          numNine = new JButton( "9" );
          numNine.addActi onListener( this );
          container.add(n umNine);


          numEight = new JButton( "8" );
          numEight.addAct ionListener( this );
          container.add(n umEight);


          numSeven = new JButton( "7" );
          numSeven.addAct ionListener( this );
          container.add(n umSeven);


          numSix = new JButton( "6" );
          numSix.addActio nListener( this );
          container.add(n umSix);


          numFive = new JButton( "5" );
          numFive.addActi onListener( this );
          container.add(n umFive);


          numFour = new JButton( "4" );
          numFour.addActi onListener( this );
          container.add(n umFour);


          numThree= new JButton( "3" );
          numThree.addAct ionListener( this );
          container.add(n umThree);


          numTwo = new JButton( "2" );
          numTwo.addActio nListener( this );
          container.add(n umTwo);


          numOne = new JButton( "1" );
          numOne.addActio nListener( this );
          container.add(n umOne);

          numStar = new JButton( "*" );
          numStar.addActi onListener( this );
          container.add(n umStar);

          numZero = new JButton( "0" );
          numZero.addActi onListener( this );
          container.add(n umZero);

          numPound = new JButton( "#" );
          numPound.addAct ionListener( this );
          container.add(n umPound);



          Panel displayPanel= new Panel();
          displayPanel.se tLayout (new BorderLayout ());
          displayPanel.ad d("Center",phon eLabel);
          add(textarea,Bo rderLayout.SOUT H);
          add("Center",ph oneLabel);



          Panel buttonPanel = new Panel();
          buttonPanel.set Layout(new GridLayout(1, 1, 4, 4));
          buttonPanel.add ("West",ViewNum berButton);
          buttonPanel.add ("Center",dialB utton);
          buttonPanel.add ("East",StoreNu mberButton);
          buttonPanel.add ("North",clearB utton);
          add("West", buttonPanel);

          Panel numberPanel= new Panel();
          numberPanel.set Layout(new GridLayout(1, 1, 6, 6));
          numberPanel.add ("West", numOne);
          numberPanel.add ("Center", numTwo);
          numberPanel.add ("East", numThree);
          add("South",num berPanel);

          Panel number2Panel= new Panel();
          number2Panel.se tLayout(new GridLayout(1, 1, 6, 4));
          number2Panel.ad d("West", numFour);
          number2Panel.ad d("Center", numFive);
          number2Panel.ad d("East", numSix);
          add("East",numb er2Panel);

          Panel number3Panel=ne w Panel();
          number3Panel.se tLayout(new GridLayout(1, 1, 4, 4));
          number3Panel.ad d("West", numSeven);
          number3Panel.ad d("Center", numEight);
          number3Panel.ad d("East", numNine);
          add("South",num ber3Panel);

          Panel number4Panel= new Panel();
          number4Panel.se tLayout(new GridLayout(1, 1, 4,0));
          number4Panel.ad d("West", numStar);
          number4Panel.ad d("Center", numZero);
          number4Panel.ad d("East", numPound);
          add("South",num ber4Panel);

          }


          public void ViewNumber()
          {
          if(nameArray==n ull)
          return;

          else

          if(nameArray!=n ull);


          for(int k=0;k<nameArray .length;k++)
          {
          textarea.setTex t(nameArray[k]);
          //textarea.setTex t(" 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.setTex t("");
          //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(Cont act c)
          {
          //contact.add(c);
          area.append(c.t oString());
          area.append("\n ");
          }
          public void actionPerformed (ActionEvent action)
          {
          String name = JOptionPane.sho wInputDialog(nu ll, "Name");
          String number = JOptionPane.sho wInputDialog(nu ll, "Number");
          Contact c = new Contact(name, number);
          addContact(c);
          }

          JTextArea area;






          }




          public void actionPerformed ( ActionEvent thisEvent )
          {

          Object source = thisEvent.getSo urce();
          if(source == ViewNumberButto n)
          ViewNumber();
          if(source==clea rButton)
          clear();
          if(source==Stor eNumberButton)
          addContact();


          }

          Comment

          • babynailah
            New Member
            • Sep 2006
            • 7

            #6
            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

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Did ever bother to look at the code I have given you?

              Comment

              • babynailah
                New Member
                • Sep 2006
                • 7

                #8
                i did but it dont work with the code i already have

                Comment

                Working...