
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

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

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