Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Date-Calendar about getting the hour time

Have Programming Question? Ask it here!
 
 
 


Nur Mawaddah
about getting the hour time
2 Answer(s)      3 years and 5 months ago
Posted in : Date-Calendar


if i want to say, if the hour shows before noon, display message "good morning" and if otherwise, display "good afternoon" and so on..and im using tag..the problem is i dont know the code for Good morning. what should i type inside ? thanks


Advertisement
View Answers

November 15, 2010 at 5:27 PM


Hi Friend,

Try the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;

class DisplayMesage extends JFrame {
    JTextField text; 
    JLabel label;
    public DisplayMesage() {
        text = new JTextField(5);
        text.setEditable(false);
        text.setFont(new Font("Arial", Font.PLAIN, 20));

        label = new JLabel();
        label.setFont(new Font("Arial", Font.PLAIN, 22));
        label.setForeground(Color.BLUE);

        JPanel time = new JPanel();
        time.setLayout(new FlowLayout());
        time.add(text); 
        JPanel message = new JPanel();
        message.setLayout(new FlowLayout());
        message.add(label); 

        add(time,BorderLayout.NORTH);
        add(message,BorderLayout.SOUTH);
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        setVisible(true);
        javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());
        t.start();
    }
        class ClockListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            Calendar now = Calendar.getInstance();
            int h = now.get(Calendar.HOUR_OF_DAY);
            int m = now.get(Calendar.MINUTE);
            int s = now.get(Calendar.SECOND);
            text.setText("" + h + ":" + m + ":" + s);
            if(h<12){
                label.setText("Good Morning!");
            }
            else if(h>12&&h<15){
                label.setText("Good Afternoon!");
            }
            else if(h>15&&h<19){
                label.setText("Good Evening!");
            }
            else{
                label.setText("Good Night!");
            }
    }
        }
    public static void main(String[] args) {
        DisplayMesage f = new DisplayMesage();
        }
}

Thanks



November 15, 2010 at 7:40 PM


wow..thank you so much. actually, im just a beginner so i have to familiarise with these codes. thanks again! :)



Related Tutorials/Questions & Answers:
about getting the hour time
about getting the hour time  if i want to say, if the hour shows before noon, display message "good morning" and if otherwise, display "good afternoon" and so on..and im using tag..the problem is i dont know the code for Good
javascript add hour to time
javascript add hour to time  I want to add numbers of hours to time...; } document.write("Time : " + newHrs + " : " + minutes... in standard format with current day,date,time and GMT.You can have your own format
Advertisements
Getting the Current Time
Getting the Current Time       This section shows the way of getting  the current time... time in the proper format (Hour:Minute:Second AM/PM). This program shows
Hour Format Example
Hour Format Example       This example shows how to format hour using Format class. In this program we use a pattern of special characters to time format. Description
Getting Information of All Available Time Zones
Getting Information of All Available Time Zones... information about the time zones for setting up the time according... ahead and adjusted one hour back to standard time every autumn. Many countries
Mysql Time Function
; Mysql Time Function is used to find the current time in hour, minute... Time in hour, minute and second.  Query to select Current Time  use... of the specified time using "HOUR(time)" mysql> SELECT HOUR('02:02:14
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1
Getting information about Constructor
Getting information about Constructor       In this section you will learn, how to retrieve the information about the constructor by using the getConstructors() method. Here is an example
Getting time in Milliseconds
Getting time in Milliseconds   ... and time in the milliseconds. To do this we have used getTime() method of Date class. getTime() returns the total time in milliseconds since 1 January 1970 00:00
PHP Date add 1 hour
In the following example code we are showing how you can add one hour to a date object. <?php //This PHP Example code shows how to add one hour... date $currentTime = time($todayDate); //Change date into time //echo "
Convert Time to Seconds
Convert Time to Seconds       In this section, you will learn to convert Time to seconds. An hour has...: This example helps you in converting a Time to seconds. Here, first of all we have
actullay iam week in programming logic , and than iam not getting how to trace the programming while excuting time ..
actullay iam week in programming logic , and than iam not getting how to trace the programming while excuting time ..  how to find the auto widening and explicit narrowing? and than what's the difference between auto widening
actullay iam week in programming logic , and than iam not getting how to trace the programming while excuting time ..
actullay iam week in programming logic , and than iam not getting how to trace the programming while excuting time ..  how to find the auto widening and explicit narrowing? and than what's the difference between auto widening
time
time  sir, i want to show system time on a textfield in awt(java). woulk you send me an example of time which can show time in standard format like H:M:S pls help me sir   Display time in JTextField import
Get Time And Date
to describe you a code that helps you in understanding in a Getting Time and Date... Get Time And Date       The Class  Date provides you  a specific instant in time
Convert Time to Milliseconds
Convert Time to Milliseconds       In this section, you will learn to convert Time to seconds. An hour has 3600 seconds, a minute has sixty seconds and a millisecond is one
Getting a absolute path
Getting a absolute path     ... this example. Getting the Parents of a Filename Program uses... of the java.lang.*; package. This method tells about the system property according
Getting the modification date and time of file or folder in Java
C:\nisha>java GetDirectoryAndFileModifiedTime Enter file or directory name in proper format to get the modification date and time... and time : Thu Oct 04 16:31:39 GMT+05:30 2007 C
time
time  how to find the current system time between the user login and logout using java
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time display only as hh:mm.  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
retrieved time from mysql database  Hi. I have retrieved time from.... wat to do?   Here is a jsp example that fetch the time from... is a jsp example that fetch the time from the database and display in different
Show Time in JSpinner Component
the time and change hour from 1 to 12. Following image shows you a JSpinner component... Show Time in JSpinner Component       In this section, you will learn about the creation
GUI Interface .Reply me with in hour..Its Urgent - Java Beginners
GUI Interface .Reply me with in hour..Its Urgent  Hi ... Now i am doing project for Voting finger print Authentication .. Can any pls assit me.. I have to create GUI Interace ..How should i create the Interface. In Existing
Getting NumberFormatException
Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt...("time"); int t1=Integer.parseInt(t2, 10); String str=""; %>... is the object from class DBLogic which has a method to insert time in Database
Time validation
Time validation  Hi. I have a text box in html to get time in the format of hour:minutes. I have to validate that the given information in that text... project.   Here is a code that accepts the time in the format hh:mm
Getting NumberFormatException
Getting NumberFormatException  Thanks for the reply. Its works well, but whenever I'm using numeric value from 0010 to 0757 it is returning some... t=request.getParameter("time"); %> <%=t2%> ");`   Hi Friend
Getting Exception
Getting Exception  How to get exception from commented code in java
getting variables
getting variables   how to get variables from servlet program to webservice program
about array in java
about array in java  speed of a vehicle is measured using the total time and the distance by using the equation given bellow speed(km/hour)=distance(km)/time(hour) Each vehicle is given a unique identification number
Getting date by time
Getting date by time      ... of java.util.Date(). For creating or generating Date by the specific time we have used... with the specified time .      Here is the example code
gettimeofday()
PHP gettimeofday() Function The gettimeofday() function returns an array containing current time information. It returns an array by default. It returns float if return_float is set. Syntax about gettimeofday() Function PHP
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM... start INFO: Jk running ID=0 time=0/15 config=null Oct 5, 2012 10:18:16 AM
getting the emplo
getting the emplo   I have one table "EMPLOYEEMASTER" contains 'emp id', 'employee name' for eg: emp id employee name... kumar i want the sql statement for getting like emp id
Getting the Log Level of a Logger
Getting the Log Level of a Logger       This section helps you to learn about the getting log level... thing is getting log level and display it in the console. Description of code
PHP Make Time
PHP  Make Time In PHP, mktime() funtion is used for doing date arithmetic...: hour The number of the hour... is set to either of these values: 1 if the time is during Daylight
Mysql Time Zone Conversion
Mysql Time Zone Conversion       The Tutorial illustrate you an example from 'Mysql Time Zone Conversion' that describes you about the time zone conversion. SYNTAX:-CONVERT_TZ
getting errors
getting errors  public class positive { public static void main(String[] args) { retainPositiveNumbers(a); } private static int n; private static int j; static int a[]={-1,2,3,4,-5}; static int
getting voucherPin
getting voucherPin  I am doin an online credit topup application..and i need a method to fetch and decrypt the voucherpin from Database.. this is my voucher repository Class. public interface VoucherRepository extends
getting coords from an image.
getting coords from an image.  how to get coordinates dynamically(in run time) from an image?? pls help me
 

 

 

DMCA.com