Began Java

Since I'll be enrolled in an online course through a university, I figured why not take a step towards their focused programming language, Java. Its a little different to C#, but hell, I;m going to have fun with it... after deliberation, I produced my first Java Application, enjoy :)



 *
 * myWidget v 1.0 (Alpha)
 *  myWidget is a project invoking a Digital clock
 *  and a post it not service.
 *  Written by N0Kturn4lLC0d3M0nK33
 *
 *
 */
import java.awt.*;

import javax.swing.*;

import java.text.SimpleDateFormat;
import java.util.*;

class DigiClock extends JFrame implements Runnable {
Thread runner;
Font ClockFont;
Font love;
Font Note;
public String[] postIt = { "Do NOT eat junk food!", "Do NOT drink pop!",
"Eat at least 4 meals a day!", "Leave a meal hungry!",
"Camping July 19th-July 22nd" };

DigiClock() {
super("myWidget");
setSize(250, 394);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);

ClockFont = new Font("DS-DIGITAL", Font.BOLD, 40);
love = new Font("Courier New", Font.BOLD, 17);
Note = new Font("Courier New", Font.BOLD, 13);
Container contentArea = getContentPane();

ClockPanel timeDisplay = new ClockPanel();

contentArea.add(timeDisplay);
setContentPane(contentArea);
start();
}

class ClockPanel extends JPanel {
@Override
public void paintComponent(Graphics painter) {
Image Pic = Toolkit
.getDefaultToolkit()
.getImage(
"C:\\Users\\Nick\\workspace\\myWidget\\src\\background.jpg");
if (Pic != null) {
painter.drawImage(Pic, 0, 0, this);
}

painter.setFont(ClockFont);
painter.setColor(Color.white);
painter.drawString(getTimeNow(), 30, 100);
painter.setFont(love);
painter.drawString("I love my baby girl!", 20, 120);

// Note section
int y = 200;
painter.drawString("Notes:", 10, y);
painter.setFont(Note);
for (int i = 0; i <= 4; i++) {
y += 20;
painter.drawString(postIt[i], 15, y);

}
}
}

public String getTimeNow() {
Date now = new Date();
SimpleDateFormat f = new SimpleDateFormat("hh:mm:ss a");
String time = f.format(now);
return time;
}

public void start() {
if (runner == null)
runner = new Thread(this);
runner.start();
}

@Override
public void run() {
while (runner == Thread.currentThread()) {
repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException IE) {
System.out.println("Error: Thread unexpectedly seized!");
}
}

}

public static void main(String[] args) {
DigiClock exec = new DigiClock();

}
}

Comments

Popular Posts