AllDatesFormat
import java.util.Locale;
import java.util.Date;
import java.text.DateFormat;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class AllDateFormats extends JFrame{
String output = "";
int row, col;
Container pane;
JTextArea textarea;
private static JFrame winframe = new JFrame();
public static void main(String[] args){
AllDateFormats formats = new AllDateFormats();
formats.setSize(450,560);
formats.setVisible(true);
}
public AllDateFormats(){
super("More on Date Utilities");
//container
pane = getContentPane();
pane.setLayout(new FlowLayout());
pane.setBackground(new Color(10,5,255));
pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//text area
textarea = new JTextArea(row,col);
//window listener
addWindowListener(new WindowHandler());
//output display
outputDisplay();
}
void outputDisplay(){
Date today = new Date();
Locale[] locales = {Locale.US, Locale.UK, Locale.CANADA,Locale.GERMANY,Locale.FRANCE,Locale.ITALY};
int[] styles = {DateFormat.FULL,DateFormat.LONG,DateFormat.MEDIUM,DateFormat.SHORT};
DateFormat fmt;
String[] styleText = {"FULL","LONG","MEDIUM","SHORT"};
//output the Date for each local in four styles
for (int i=0; i
output +="\nThe Date fot"+locales[i].getDisplayCountry()+":";
for (int j=0; j
fmt = DateFormat.getDateInstance(styles[j],locales[i]);
output +="\tIn"+ styleText[j] + "is" + fmt.format(today)+"\n";
}
}
textarea.setText(output);
textarea.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
textarea.setFont(new Font("Lucida Sans",Font.PLAIN,12));
textarea.setToolTipText("Dates Formats in Java");
pane.add(textarea);
}
class WindowHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
winframe.dispose();
System.exit(0);
}
}
}
No comments:
Post a Comment