-3
 public class Chap extends Frame implements ActionListener
 {
   private Button keys[];
 private Panel keypad;
private Panel fields;
 private TextField nameField;
private TextField numberField;
private String name;
 private int number;
 private boolean clearText;
private boolean foundKey;
Button enterButton = new Button("Enter");
Button clearButton = new Button("Clear");
Button printButton = new Button("Print");
String names, numbers;
String ArrayValues[][] = new String[10][2];

  public Chap()
  {

enterButton.addActionListener(this);
clearButton.addActionListener(this);
printButton.addActionListener(this);

enterButton.setActionCommand("Enter");
clearButton.setActionCommand("Clear");
printButton.setActionCommand("Print");

// construct components and initialize beginning values
nameField = new TextField(20);
numberField = new TextField(20);
nameField.setEditable(true);
numberField.setEditable(false);
keypad = new Panel();
fields = new Panel();
keys = new Button[10];
number = 0;
name = "";
clearText = true;

fields.add(nameField);
fields.add(numberField);
fields.add(enterButton);
fields.add(clearButton);
fields.add(printButton);


public void actionPerformed(ActionEvent e)
{


 if(arg == "About")
{
  String message = "Program";
  JOptionPane.showMessageDialog(null,message,"About Program",JOptionPane.INFORMATION_MESSAGE);
} 

 if(arg == "Enter")
{
   for (int counter = 0; counter < 10; counter ++)
   {

   }

} 

 if(arg == "Print")
 {
   JOptionPane.showMessageDialog(null,ArrayValues,"Info",JOptionPane.INFORMATION_MESSAGE);
 }

i have to create a program that store up to 10 phone numbers and names. once the user clicks print, all of the stored data should be displayed. i'm unsure of how to store the data in the array. the name field is editable, while the number field is only able to accessed through the numeric keypad

Jodie
  • 11
  • 5
  • How is your question related to all that code you've posted? Please only add the minimal code necessary to reproduce or explain your issue. – Savior Apr 14 '16 at 19:35
  • @pillar I wasn't sure what all would be needed in fixing the issue. – Jodie Apr 14 '16 at 19:35
  • Then you probably need to take more time researching. For your next question: http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – Savior Apr 14 '16 at 19:41
  • @Pillar lol thanks anyways – Jodie Apr 14 '16 at 19:43

2 Answers2

0

You could use LinkedHashMap for this, here is an example:

LinkedHashMap<String, String> test = new LinkedHashMap<String, String>();
test.put("Dan", "867-5309");
test.put("Sam", "123-4567");
for(String key : test.keySet()) {
    System.out.println(key + "'s phone number is " + test.get(key));
}

Which will print:

Dan's phone number is 867-5309
Sam's phone number is 123-4567

The difference between LinkedHashMap and just plain ol' HashMap is that LinkedHashMap maintains the order of the "keys" as you put them in, HashMap disregards the order completely.

Daniel Griffin
  • 321
  • 1
  • 9
0

Not sure what exactly you mean, but this might help you get the logic:

String[] arr=new String[10] // to store 10 phone numbers

to add elements to array:

arr[i]=numberField.getText();

set counter on "i" for each Action Event. Then print the array elements using loop.

s_anzer
  • 123
  • 1
  • 1
  • 10