Solved

How can I set an array

Posted on 2004-04-01
8
196 Views
Last Modified: 2010-03-31
When the ReadingButton is clicked in Frame1, Frame1 disappears and Frame2 appears with blank data entry fields. This will enable me to enter data into the CustomerIdText field and CustomerReadingText field of frame 2. However this needs to be stored in an array, which I dont't quite know how to achieve. In addition I am having problems with the CustomerReadingButton which stores the data entered in the text fileds, explained above, and then clears the displayed data so that it is ready for a new set of data entries.

Could you please help me with the problems i have encountered asap.

Here is the text file for frame 1:

/**
 * Write a description of class Frame1 here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
import java.awt.*;
import java.awt.event.*;
class Frame1 extends Frame implements ActionListener    
   
    {
    private Button ReadingButton;
    private Button FaultsButton;
    private Button PotentialButton;
    private Button ListReadingButton;
    private Button ListFaultsButton;
    private Button ListPotentialButton;
    private Button ExitButton;
    private Frame2 frame2;
    private Frame3 frame3;
    private Frame4 frame4;
   
    public Frame1()
        {
        super();
        frame2 = new Frame2(this);
        frame3 = new Frame3(this);
        frame4 = new Frame4(this);
        ReadingButton = new Button("Customer reading data entry");
        FaultsButton = new Button("Customer reading with fault data entry");
        PotentialButton = new Button("Potential customer data entry");
        ListReadingButton = new Button("List readings");
        ListFaultsButton = new Button("List customers with faults");
        ListPotentialButton = new Button("List potential customers");
        ExitButton = new Button("Exit");
        setLayout(new GridLayout (7,1));
               
        add (ReadingButton);
        add (FaultsButton);
        add (PotentialButton);
        add (ListReadingButton);
        add (ListFaultsButton);
        add (ListPotentialButton);
        add (ExitButton);
       
        ReadingButton.addActionListener(this);
        FaultsButton.addActionListener(this);
        PotentialButton.addActionListener(this);
       
        setSize(700,400);
        setVisible(true);
       
       
        }
    public void actionPerformed(ActionEvent e)
        {
        if
        (e.getSource() == ReadingButton)
            {
            setVisible (false);
            frame2.setVisible(true);
            }
        else if
        (e.getSource() == FaultsButton)
            {
            setVisible (false);
            frame3.setVisible(true);
            }
        else if
        (e.getSource() == PotentialButton)
            {
            setVisible (false);
            frame4.setVisible(true);
            }
        else
      {
      frame2.dispose();
      dispose();
      System.exit(0);
      }
    }

  public static void main (String[] args)
    {
    Frame1 f = new Frame1();
    }
  }        

Here is the text file for frame2

/**
 * Write a description of class Frame2 here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
import java.awt.*;
import java.awt.event.*;
class Frame2 extends Frame implements ActionListener    
   
    {
    private Button ReturnButton;
    private Button CustomerReadingButton;
    private TextField CustomerIdText;
    private TextField CustomerReadingText;
    private Label CustomerIdLabel;
    private Label CustomerReadingLabel;
    private Panel CustomerIdPanel;
    private Panel CustomerReadingPanel;
    private Frame1 frame1;
    int[] CustomerId;
   
    public Frame2(Frame1 f)
        {
        super();
        frame1 = f;
        CustomerReadingButton = new Button("Enter customer reading");
        ReturnButton = new Button("Return to main window");
        CustomerIdText = new TextField(15);
        CustomerReadingText = new TextField(15);
        CustomerIdLabel = new Label("Customer id :");
        CustomerReadingLabel = new Label("Customer reading :");
        CustomerIdPanel = new Panel();
        CustomerReadingPanel = new Panel();
        setLayout(new GridLayout (4,1));
       
       
       
        CustomerIdPanel.add(CustomerIdLabel);
        CustomerIdPanel.add(CustomerIdText);
        CustomerReadingPanel.add(CustomerReadingLabel);
        CustomerReadingPanel.add(CustomerReadingText);
       
        add (CustomerIdPanel);
        add (CustomerReadingPanel);
        add (CustomerReadingButton);
        add (ReturnButton);
        CustomerReadingButton.addActionListener(this);
        ReturnButton.addActionListener(this);
        setSize(500,300);
        setVisible(false);
        }
       
       
               
        public void actionPerformed(ActionEvent e)
        {
        if(e.getSource() == ReturnButton)
        setVisible (false);
        frame1.setVisible(true);
        }
  }
  class CustomerId
            {
            public static void main(int[] args)
                {
                CustomerId = new int[5];
                int sum = 0;
                for(int i = 0; i < CustomerId.length; i = i ++)
               
                {
                CustomerId[i] = Integer.parseInt(t.getText());;
                }
  }

NOTE: Both files have been created in BLUE J, java software.
0
Comment
Question by:Sonyhil
  • 3
8 Comments
 
LVL 2

Accepted Solution

by:
j79 earned 125 total points
ID: 10735348

to clear the values of a frame make it with "new Frame()" on perform.

The CustomerID[i] problem you should can solve with:

CustomerId[i] = Integer.valueOf(String.valueOf(t.getText())).intValue();

Take attention to not get out of bounds with your array size and also do try/catch if a field is empty because an empty "text" can't be parsed into an Integer/int.

j79

0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10738360
AnnieMod,

Please also have a look at:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20937708.html

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20937635.html

- seems to be the same multiple-account problem (krizmotlhala/ deweber1).

0
 
LVL 37

Expert Comment

by:zzynx
ID: 10740128
Hi mayankeagle,
I already mentioned that one.
See http://www.experts-exchange.com/Community_Support/Q_20936454.html
;)
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10740288
Hi zzynx,

I know that you mentioned it, but I was wondering if AnnieMod noticed it or not, 'coz I didn't see her comment on those pages. Since she is listening to this page, I thought I might post here to bring it to notice.

Mayank.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10740300
Oh sorry, I didn't notice that :-)

Its your Q in Community Support. Well, I was talking about whether AnnieMod has noticed http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20937708.html or not.

All right :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 84
Safari, Firefox, IE, Java, Plugin, Java Security error 13 41
json format text only 4 65
recursion example 16 70
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now