error message

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 14
Reputation: foxy xx is an unknown quantity at this point 
Solved Threads: 0
foxy xx foxy xx is offline Offline
Newbie Poster

error message

 
0
  #1
Nov 16th, 2006
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:

  1.  
  2. import java.applet.*; //Applet Class
  3. import java.awt.*; //All the classes
  4. import java.awt.event.*;
  5. import java.util.*;
  6.  
  7.  
  8. public class MilitaryTime1 extends Applet implements ActionListener
  9. {
  10. int hrs, mins, secs;
  11. String am, pm;
  12. Label promptTime;
  13. TextField timeIn;
  14. Label promptAmPm; //Remind user to enter am or pm
  15. TextField inputAmPm;
  16. //StringTokenizer inputTime;
  17.  
  18. public void init()
  19. {
  20. setSize(600,400);
  21. promptTime = new Label("Input current time");
  22. timeIn = new TextField(7);
  23. promptAmPm=new Label("Enter am or pm?");
  24. inputAmPm = new TextField(2);
  25.  
  26. add(promptTime);
  27. add(timeIn);
  28. add(promptAmPm);
  29. add(inputAmPm);
  30.  
  31. timeIn.addActionListener(this);
  32. inputAmPm.addActionListener(this);
  33.  
  34. StringTokenizer timeIn = new StringTokenizer(" ,\t\n");
  35. String hrs = timeIn.nextToken();
  36. String mins = timeIn.nextToken();
  37. String secs = timeIn.nextToken();;
  38.  
  39. // String valInputAmPm;
  40. // valInputAmPm=inputAmPm.getText();
  41.  
  42. // hrs = Integer.parseInt();
  43. // mins = Integer.parseInt(mins.getText());
  44. // secs = Integer.parseInt(secs.getText());
  45.  
  46. }
  47.  
  48. public void paint(Graphics graf)
  49. {
  50. if (inputAmPm.getText() == am)
  51. {
  52. graf.setColor(Color.yellow);
  53. graf.fillOval(0,0,200,200);
  54. graf.setColor(Color.black);
  55. graf.fillOval(50,50,25,25);
  56. graf.fillOval(125,50,25,25);
  57. graf.drawArc(75,125,50,50,180,180);
  58. }
  59. else
  60. {
  61. graf.setColor(Color.yellow);
  62. graf.fillOval(0,0,200,200);
  63. graf.setColor(Color.black);
  64. graf.fillOval(50,50,25,25);
  65. graf.fillOval(125,50,25,25);
  66. graf.drawArc(75,125,50,50,360,180);
  67. }
  68. }
  69.  
  70. public void actionPerformed (ActionEvent ev)
  71. {
  72. Object source = ev.getSource();
  73.  
  74. {
  75.  
  76. // String valInputAmPm;
  77. // valInputAmPm=inputAmPm.getText();
  78. if (timeIn.getText() == am)
  79. {
  80. System.out.println("The time in military format is: " + hrs + ":" + mins + ":" + secs);
  81. //st = new StringTokenizer(inputTime.getText() " ,.:");
  82. //String hrs = inputTime.nextToken();
  83. //String mins = inputTime.nextToken();
  84. //String secs = inputTime.nextToken();
  85. //System.out.println(hrs +":"+ mins +":"+ secs);
  86.  
  87. //inputHrs.setText("");
  88. //inputMins.setText("");
  89. //inputSecs.setText("");
  90. //repaint();
  91. }
  92. else
  93. {
  94.  
  95. // System.out.println(hrs + 12)":"+ mins +":"+ secs);
  96.  
  97. }
  98. }
  99. }
  100. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 263
Reputation: Dukane is an unknown quantity at this point 
Solved Threads: 22
Dukane's Avatar
Dukane Dukane is offline Offline
Posting Whiz in Training

Re: error message

 
0
  #2
Nov 16th, 2006
Where is the main method?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: error message

 
0
  #3
Nov 17th, 2006
applets don't need a main method
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 17
Reputation: p.bondam is an unknown quantity at this point 
Solved Threads: 0
p.bondam's Avatar
p.bondam p.bondam is offline Offline
Newbie Poster

Re: error message

 
0
  #4
Nov 17th, 2006
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
maybe later
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC