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



Home Answers Viewqa Date-Calendar about getting the hour time
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Nur Mawaddah
about getting the hour time
2 Answer(s)      4 years 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 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
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
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 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
Advertisements
 

 

 

DMCA.com