package countd;
import java.awt.*;
import java.text.*;
import javax.swing.*;
import org.joda.time.DateTime;
import org.joda.time.Period;
import java.awt.event.*;
public class Count {
static JFrame fCount = new JFrame("Countdown");
static JLabel lCount = new JLabel();
public static void main(String[] args) {
lCount.setBounds(0, 0, 400, 80);
fCount.getContentPane().add(lCount);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
fCount.setLocation( (d.width - fCount.getSize().width ) / 2,
(d.height- fCount.getSize().height) / 2 );
fCount.setDefaultCloseOperation(fCount.EXIT_ON_CLOSE);
fCount.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
fCount.setUndecorated(true);
lCount.setFont(new Font("Comic Sans MS",Font.BOLD,72));
lCount.setHorizontalAlignment(SwingConstants.CENTER);
lCount.setBackground(Color.RED);
lCount.setForeground(Color.WHITE);
lCount.setOpaque(true);
while(true)
{
countdown();
weekend();
}
}
public static void countdown()
{
String output;
DecimalFormat df = new DecimalFormat("00");
Period extern_period;
do
{
DateTime today = new DateTime();
DateTime nextFriday1930 = today.weekOfWeekyear().toInterval().getEnd()
.minusDays(3).withHourOfDay(19).withMinuteOfHour(30);
Period period = new Period(today, nextFriday1930);
extern_period = period;
output = "Zeit: "+df.format(period.getHours())+":"+df.format(period.getMinutes())+":"+df.format(period.getSeconds())+"\n";
lCount.setText(output);
fCount.pack();
fCount.show();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
fCount.setLocation( (d.width - fCount.getSize().width ) / 2,
(d.height- fCount.getSize().height) / 2 );
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}while(extern_period.getHours() >= 0 & extern_period.getMinutes() >= 0 & extern_period.getSeconds() >= 0);
}
public static void weekend()
{
String output;
Period extern_period;
do
{
DateTime today = new DateTime();
DateTime nextFriday1930 = today.weekOfWeekyear().toInterval().getEnd();
Period period = new Period(today, nextFriday1930);
extern_period = period;
output = "Wochenende";
lCount.setText(output);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
fCount.setLocation( (d.width - fCount.getSize().width ) / 2,
(d.height- fCount.getSize().height) / 2 );
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
} while(extern_period.getHours() >= 0 & extern_period.getMinutes() >= 0 & extern_period.getSeconds() >= 0);
}
}