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 morning. what should i type inside ? thanks

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
ModuleNotFoundError: No module named 'about-time'
ModuleNotFoundError: No module named 'about-time'  Hi, My Python... 'about-time' How to remove the ModuleNotFoundError: No module named 'about-time' error? Thanks   Hi, In your python environment you
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... to be adjusted one hour ahead and adjusted one hour back to standard time every autumn
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
Mysql Time Function
; Mysql Time Function is used to find the current time in hour, minute... time, From Unix Time in hour, minute and second.  Query to select Current... in set (0.00 sec) Query to converts the Time into Hour: The Query to returns
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
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
How to add one hour in php date?
convert the 60 minute (one hour) into time. Then add the both to get and convert...How to add one hour in php date?  I have a date variable in PHP and I want to add one hour to it. What is the code for adding one hour to the PHP
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
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
ModuleNotFoundError: No module named 'api_hour'
ModuleNotFoundError: No module named 'api_hour'  Hi, My Python..._hour' How to remove the ModuleNotFoundError: No module named 'api_hour... to install padas library. You can install api_hour python with following
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
Getting a absolute path
Getting a absolute path     ...\chandan\..\chandan Download this example. Getting the Parents of a Filename.... This method tells about the system property according to the indicating argument
PHP Date add 1 hour
"<br>Date and Time After adding one hour: ".date("Y-m-d H... Current Date and Time: 2009-08-27 10:55:48 Date and Time After adding one hour... In the following example code we are showing how you can add one hour
Show Time in JSpinner Component
the time and change hour from 1 to 12. Following image shows you a JSpinner component... field which returns the hour of the specified time. JSpinner.DateEditor(spinner... Show Time in JSpinner Component   
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
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'  ...: No module named 'odoo10-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'  ...: No module named 'odoo12-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour'  ...: No module named 'odoo12-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour'  ...: No module named 'odoo10-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-holidays-hour' error
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'
ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour'  ...: No module named 'odoo11-addon-hr-holidays-hour' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-holidays-hour' error
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 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
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
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 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  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
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
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
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
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.ADS_TO_REPLACE_1
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
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