Need help with array and input


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Need help with array and input

  1. #1
    Join Date
    Nov 2005
    Posts
    2

    Exclamation Need help with array and input

    hi, I'm new to the forum and they have been of help to me before. This is my first semester of taking computer science and I'm having trouble on my 2nd to last homework assignment of the semester (its due tonight at midnight). Here are the details http://moosehead.cis.umassd.edu/cis1...k/hw5/hw5.html and here is what I have so far
    Code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.StringTokenizer;
    
    
    public class InputSort extends Applet implements ActionListener
    {
        private Label prompt;         // The GUI components
        private TextArea numbers;
        private TextArea sortedNumbers;
        private Button up,down,clear;
        private int array[];
      
        public void init()
        {
        	prompt = new Label("Enter a Whole Number");
        	numbers = new TextArea(5,40);
        	sortedNumbers = new TextArea(5,40);
        	numbers.setEditable(true);
        	sortedNumbers.setEditable(false);
        	up = new Button("Up");
        	down = new Button("Down");
        	clear = new Button("Clear");
    
        	add(prompt);
        	add(numbers);
        	add(sortedNumbers);
        	add(up);
        	add(down);
        	add(clear);
        	
            up.addActionListener(this);
            down.addActionListener(this);
            clear.addActionListener(this);
        	
        	setSize(900,120);
        } // init()
        
    
    	
    	private void doUp()
    	{
             // ascending sorting
    	}
    	
    	private void doDown()
    	{
             // descending sorting
    	}
        
        public void actionPerformed(ActionEvent e)
        {
        	if(e.getSource() == clear)
            {
                numbers.setText("");
                sortedNumbers.setText("");
                return;
            }
    		else if (e.getSource() == up)
    			doUp();
    		else if (e.getSource() == down)
    			doDown();
    
        }
        
    }
    what I'm having most trouble with is getting input from user and putting it into the arrays and the StringTokenizer stuff. I think I can figure out the actual sorting of the arrays once I get the other things finished first.
    Any help is appreciated, and if possible be plain and simple in your explanations because I'm still sort of new at this stuff.
    Thanks in advance.
    -Matt
    Last edited by hodgenpodg; 11-28-2005 at 07:21 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    So ... you are prompting your user to type a number in the TextArea ... and you need to use that text.

    what kind of Event can be generated by a TextArea? If the events generated by TextArea are not of the kind that is useful, what component can you add which will generate a more easily used event?

    what kind of listener do you need to catch that Event?

    when you have the correct event triggered, what do you need to do with the text captured from the TextArea?

    Good luck in your efforts!

  3. #3
    Join Date
    Nov 2005
    Posts
    2
    not exactly the user has to be able to enter multiple integers into the textarea and I don't know how many nor can I ask before hand.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    then perhaps you should have a "Accept Input" button which fires an event which takes the text in the TextArea and processes the various ints which can be extracted from the text ...

Similar Threads

  1. Need a Macro plz !
    By geophysicist in forum VB Classic
    Replies: 9
    Last Post: 10-23-2005, 10:15 AM
  2. Problem with Array
    By Wizard1988 in forum Java
    Replies: 10
    Last Post: 10-13-2005, 07:26 PM
  3. Replies: 2
    Last Post: 04-15-2005, 10:06 PM
  4. Discord in Program
    By N. Richards in forum VB Classic
    Replies: 1
    Last Post: 09-09-2000, 06:50 PM
  5. Replies: 0
    Last Post: 07-06-2000, 05:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center