Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Default Any help much appreciated

    Hi,
    Firstly, thanks for taking the time to have a look. I am pretty new to Java and I am meeting a few problems along the way. Unfortunately I don't personally know anyone who can help out so here I am.

    I'm trying to get the following applet to accept input from the user in the form of an integer. The input should only be equal to a month. e.g. 1 = January, 2 = February, 0 = invalid etc..

    I can get the program running no problem but when it executes the reult is only showing in the command line and not in the showStatus area. I've spent a lot of time on this and would really apreciate any help.

    Oh, this is my first Applet so apologies if it's not up to par !!

    Java Code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    
    public class P1AppletMonth extends Applet implements ActionListener
    {
    	Label lblprompt;
    	TextField tfinput;
    
    	int number;
    
    	public void init()
    	{
    		lblprompt = new Label ("Please enter a number that corrosponds to a month");
    		add (lblprompt);
    
    		tfinput = new TextField(10);
    		add(tfinput);
    
    		tfinput.addActionListener (this);
    	}
    
    	public void actionPerformed (ActionEvent e)
    	{
    		number = Integer.parseInt(e.getActionCommand());
    		tfinput.setText("");
    
    	if (number>=1||number>=12)
    		{
    
    		System.out.println("Valid input");
    		}
    	else
    		{
    		System.out.println("Invalid input");
    		}
    
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Any help much appreciated

    By result, I asume you mean the "Valid input" and "Invalid input" text?

    If so, then they need to be on the JLabel.
    That is, you need to setText() on the lblprompt variable, rather than using Sysout.println() (which, as you saw, goes to the console).
    Then you need to call get the Applet to repaint().
    For which I would recommend using a JApplet, rather than an Applet.
    Please do not ask for code as refusal often offends.

  3. #3
    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Default Re: Any help much appreciated

    Thank you tolls.

    What would be the drawback if I used the following instead of System.out.println...

    showStatus ("valid input");

    Or is there any drawback ?

    I managed to get it working using the way above but if the way suggested by you is better then I would like to know how to use it.

    Thanks

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Any help much appreciated

    Oh, that "showStatus area"...:)
    You can tell I don't do Applets.

    My way is by no means "better", and also doesn't seem to be what you require.
    Stick with showStatus().
    Please do not ask for code as refusal often offends.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Any help much appreciated

    Theringmaster26, please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help would be Greatly Appreciated.. please
    By aejames23 in forum New To Java
    Replies: 6
    Last Post: 11-04-2012, 10:54 PM
  2. Any Help Much Appreciated!
    By danielinthebed in forum Advanced Java
    Replies: 4
    Last Post: 01-04-2012, 09:27 AM
  3. Stumped... any help would be appreciated!
    By gard007 in forum New To Java
    Replies: 3
    Last Post: 12-01-2011, 07:42 AM
  4. Java need help! Help will be very much appreciated
    By paccerz in forum New To Java
    Replies: 1
    Last Post: 08-23-2011, 08:47 PM
  5. Help with newb-project much appreciated
    By barr in forum New To Java
    Replies: 7
    Last Post: 12-11-2008, 11:14 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
  •