me agian lol

I posted on here over a week ago about a java assignment.. thanks to those who offered help i really appreciate it even tho it wasnt much help to me at the time ;) ... i am ashamed to say, that even with all the great advice, i still didnt understand

i have been pointed in the right direction by a very helpful lab tutor, but we only get an hour a week and in my case its not enough, i'm still struggling :eek: oh and i bought big java... but its so ummm BIG lol

i have spent many hours (40+ i kid u not) trying to get this thing done and i only have until monday to get it working so i hope u will be kind enough to help

firstly my program is supposed to get the time from the user via a text area.. it should then convert to military time and paint a sad face for night and a happy face for day..

my questions....

the biggest problem i have at the mo, is that my applet is not initialising and i have no idea why..

where do i put the code that coverts the time?

how do i get the input to display?

have i done anything else wrong? (so far)

as u can see i have tried many things... and this is my third draft.. :rolleyes:

import java.applet.*;	//Applet Class
import java.awt.*;		//All the classes
import java.awt.event.*;
import java.util.*;


public class MilitaryTime1 extends Applet implements ActionListener
{
	int hrs, mins, secs;
	String am, pm;
	Label promptTime;
	TextField timeIn;
	Label promptAmPm;		//Remind user to enter am or pm
	TextField inputAmPm;
	//StringTokenizer inputTime;

	public void init()
	{
		setSize(600,400);
		promptTime = new Label("Input current time");
		timeIn = new TextField(7);
		promptAmPm=new Label("Enter am or pm?");
		inputAmPm = new TextField(2);

		add(promptTime);
		add(timeIn);
		add(promptAmPm);
		add(inputAmPm);

		timeIn.addActionListener(this);
		inputAmPm.addActionListener(this);

		StringTokenizer timeIn = new StringTokenizer(" ,\t\n");
		String hrs = timeIn.nextToken();
		String mins = timeIn.nextToken();
		String secs  = timeIn.nextToken();;

	//	String valInputAmPm;
	//	valInputAmPm=inputAmPm.getText();

	//	hrs = Integer.parseInt();
	//	mins = Integer.parseInt(mins.getText());
	//	secs = Integer.parseInt(secs.getText());

	}

	public void paint(Graphics graf)
	{
		if (inputAmPm.getText() == am)
		{
			graf.setColor(Color.yellow);
			graf.fillOval(0,0,200,200);
			graf.setColor(Color.black);
			graf.fillOval(50,50,25,25);
			graf.fillOval(125,50,25,25);
			graf.drawArc(75,125,50,50,180,180);
		}
		else
		{
			graf.setColor(Color.yellow);
			graf.fillOval(0,0,200,200);
			graf.setColor(Color.black);
			graf.fillOval(50,50,25,25);
			graf.fillOval(125,50,25,25);
			graf.drawArc(75,125,50,50,360,180);
		}
	}

	public void actionPerformed (ActionEvent ev)
	{
		Object source = ev.getSource();

		{

	//	String valInputAmPm;
	//	valInputAmPm=inputAmPm.getText();
		if (timeIn.getText() == am)
		{
			System.out.println("The time in military format is: " + hrs + ":" + mins + ":" + secs);
	 	//st = new StringTokenizer(inputTime.getText() " ,.:");
		//String hrs = inputTime.nextToken();
		//String mins = inputTime.nextToken();
		//String secs  = inputTime.nextToken();
		//System.out.println(hrs +":"+ mins +":"+ secs);

		//inputHrs.setText("");
		//inputMins.setText("");
		//inputSecs.setText("");
		//repaint();
		}
		else
		{

	//	System.out.println(hrs + 12)":"+ mins +":"+ secs);

		}
}
	}
}

have you tried replacing ....getText() == am etc. by
getText().equals(am)...

or : ...getText().indexOf(am) >= 0 // when String am doesn't appear in ...getText(), indexOf(..) returns -1

see you
peter

This article has been dead for over six months. Start a new discussion instead.