selfexplantory
I have tried to write this program. the clock, itself,
was 'easy' the alarm won't go. i am deaf and hopefully
can use my skills in finding a productive job. contact:
beelzibub2@comcast.net
if you are unable to help me please forward this.
ADthxVANCE;
kevin
/*
* BigFonts7.1 -- by: kevin
*
* @author kevin
*/
import java.text.*;
import java.io.*;
import java.text.ParseException;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent.*;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar.*;
import java.util.Date.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.JSpinner.*;
import javax.swing.BorderFactory.*;
import javax.swing.JFrame;
import javax.swing.border.Border;
abstract class BigFont71 extends JComponent
implements ActionListener,ChangeListener {
public static String doTime(String ts){
String thetime = " ";
Calendar calendar = Calendar.getInstance();
SimpleDateFormat tf = new SimpleDateFormat( "h:mm:ss aa" ) ;
thetime = tf.format(calendar.getTime());
return thetime;
}
public void ActionPerformed(ActionEvent e){
if(e.getActionCommand() == "done"){}
}
public static boolean AllSet(){
boolean flag = true;
int done = JOptionPane.showConfirmDialog(null,
"Done setting alarm? "+
JOptionPane.YES_NO_OPTION );
switch (done){
case JOptionPane.NO_OPTION:
flag = false;
case JOptionPane.YES_OPTION:
flag = true;
}
return flag;
}
public static boolean alarmChoice(){
String seed = " ";
boolean flag = true;
int result = JOptionPane.showConfirmDialog(null,
"Do you want an alarm? "+
JOptionPane.YES_NO_OPTION );
switch (result){
case JOptionPane.NO_OPTION:
flag = false;
case JOptionPane.YES_OPTION:
flag = true;
}
return flag;
}
public static void putTime(String thetime){
// make text bigger for visually impaired friend
JFrame display = new JFrame("Time Is: ");
Font big = new Font("Serif", Font.BOLD, 40);
Border matte ;
matte = BorderFactory.createMatteBorder(1, 10, 10, 10, Color.blue);
JButton thedisplay = new JButton(thetime);
thedisplay.setSize(400,400);
display.add(thedisplay);
display.setBounds(30,5,230, 90);
display.setLayout(new GridLayout(1,1));
display.setVisible(true);
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
display.setBackground(Color.blue);
thedisplay.setFont(big);
thedisplay.setBackground(Color.blue);
thedisplay.setBorder(matte);
thedisplay.setVisible(true);
}
public static boolean soundAlarm(JSpinner alarm, JSpinner now){
JLabel go = new JLabel("Time to go ...");
if (alarm.getValue() == now.getValue());
go.setVisible(true);
return true;
}
public static JSpinner setAlarm(JSpinner hour, JSpinner minute, JSpinner second){
String value = null;
String value2 = null;
String value3 = null;
String theTime = "";
try{
value = (String)hour.getValue();
hour.commitEdit();
}catch (ParseException p){
System.err.println("Exception: "+ p.getMessage());
}
try{
value2 = (String)minute.getValue();
minute.commitEdit();
}catch (ParseException p2){
System.err.println("Exception: "+ p2.getMessage());
try{
value3 = (String)second.getValue();
second.commitEdit();
}catch (ParseException p3){
System.err.println("Exception: "+ p3.getMessage());
}
theTime = (value + value2 +value3);
{
try{
hour.setValue(new Date(theTime));
hour.commitEdit();
}catch (ParseException p4){
System.err.println("Exception: "+ p4.getMessage());
}
//Date alarm = (Date) hour.getValue();
}
return hour;
}
}
public static boolean runAlarm(JSpinner alarm){
Thread t = new Thread();
t.start();
try{
Calendar cal = Calendar.getInstance();
if (alarm.getValue()== cal.getTime()){
soundAlarm(alarm, alarm);
Thread.sleep(1000);}
}catch (Exception e){
System.err.println("Exception" + e);
}
return true;
}
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "done")
//display2.setVisible(false)
;
};
public void closeAlarm (JFrame display2){
JButton b1 = new JButton("?");
b1.setSize(new Dimension(1,1));
b1.addActionListener(actionListener);
b1.setActionCommand("done");
b1.setEnabled(true);
b1.setVisible(true);
display2.add(b1);
if(b1.getActionCommand()=="done")
display2.setVisible(false);
}
public JButton addButton(){
JButton done = new JButton();
done.setSize(new Dimension (2,2));
done.setText("done");
done.addActionListener(actionListener);
done.setActionCommand("done");
//done.add(done);
done.setEnabled(true);
done.setVisible(true);
return done;
}
public void showAlarm(JSpinner hour, JSpinner minute, JSpinner second){
Font big = new Font("Serif", Font.BOLD, 20);
JFrame display2 = new JFrame("Set Allarm : ");
JButton done = new JButton("done");
//display2.setBounds(30, 10, 2300, 90);
display2.setVisible(true);
Border matte;
matte = BorderFactory.createMatteBorder(5, 5, 10, 10, Color.blue);
display2.setLayout(new GridLayout(2,2));
hour.setFocusable(true);
hour.setBorder(matte);
hour.setVisible(true);
hour.setFont(big);
display2.add(hour);
minute.setFocusable(true);
minute.setBorder(matte);
minute.setFont(big);
minute.setVisible(true);
display2.add(minute);
second.setFont(big);
second.setBorder(matte);
second.setVisible(true);
display2.add(second);
closeAlarm(display2);
}
public void stateChanged(ChangeEvent evt){
try{
JSpinner setit = (JSpinner) (evt.getSource());
setit.commitEdit();
}catch (ParseException ex) {
System.err.println("Parse Exception" + ex);
}
}
public void addSpinners(){
ChangeListener cl;
Calendar calendar = Calendar.getInstance();
Date initDate = calendar.getTime();
Date earliestDate = calendar.getTime();
Date latestDate = calendar.getTime();
SpinnerDateModel model = new SpinnerDateModel(initDate,
earliestDate,
latestDate,
Calendar.SECOND);
JSpinner hour = new JSpinner(model);
model.addChangeListener(cl);
hour.setEditor(new JSpinner.DateEditor(hour, "00"));
hour.setVisible(true);
JSpinner minute = new JSpinner(model);
model.addChangeListener(cl);
minute.setEditor(new JSpinner.DateEditor(minute, "00"));
minute.setVisible(true);
JSpinner second = new JSpinner(model);
model.addChangeListener(cl);
second.setEditor(new JSpinner.DateEditor(second, "00"));
second.setVisible(true);
}
};
public static void main(String[] args){
JSpinner hour = new JSpinner();
JSpinner minute = new JSpinner();
JSpinner second = new JSpinner();
boolean set;
set = true;
String st = " Starting ...";
String theTime = " ";
String theAlarm = " ";
Thread t = new Thread();
set = alarmChoice();
if (set){
try{
t.start();
putTime(doTime(st));
Thread.sleep(1000);
}catch (Exception e2) {
System.err.println("Exception: " + e2.getMessage());
}
}
else
try{
t.start();
putTime(doTime(st));
AllSet();
showAlarm(hour,minute,second);
setAlarm(hour, minute, second);
runAlarm(hour);
soundAlarm(hour, hour);
Thread.sleep(1000);
}catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
{
}
}
JFrame dispay2;
}
}
July 20,