here's my code. any help on the stateChanged method???
/**
*
* @author kevin
*/
/**
* @(#)MyClock2.
*
*
* @Kevin
* @version 1.20 2007/4/20
*/
import java.text.*;
import java.text.ParseException;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.io.IOException;
import javax.swing.*;
import javax.swing.SpinnerDateModel;
import javax.swing.event.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.JSpinner.*;
abstract class BigFonts extends JComponent
implements MouseMotionListener, ActionListener,
ChangeListener
{
/*
public void paintComponent(Graphics g){
g.drawString(st, newx, newy);
}
*/
//make draggable
public void MouseDragged(MouseEvent e){
int newx =0;
int newy = 0;
newx=e.getX();
newy=e.getY();
repaint();
}
public static String doTime(String ts){
//Calendar earliestdate, latestdate;
String thetime;
Calendar calendar = Calendar.getInstance();
SimpleDateFormat tf = new SimpleDateFormat( "h:mm:ss a" ) ;
thetime = tf.format(calendar.getTime());
return thetime;
}
public static void addToBox(String thetime){
// make text bigger for visually impaired friend
String alarmTime;
Font big = new Font("Serif", Font.BOLD, 40);
JLabel msg = new JLabel("Time to go.");
JButton thedisplay = new JButton(thetime);
thedisplay.setFont(big);
thedisplay.setSize(200, 200);
// prepare alarm
// put it all in a layout
JFrame display = new JFrame("Set the Alarm, pleas.");
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);;
display.setSize(250, 100);
display.setLayout(new GridLayout());
display.setBackground(Color.blue);
display.setFont(big);
display.add(thedisplay);
display.setVisible(true);
}
// spinner action
public void stateChanged(ChangeEvent evt){
JSpinner alarm = (JSpinner) (evt.getSource());
alarm.setFocusable(true);
alarm.setEnabled(true);
alarm.setValue(alarm.getNextValue());
}
public static void setAlarm(){
Font big = new Font("Serif", Font.BOLD, 40);
JFrame display = new JFrame("Set the Alarm");
Calendar calendar = Calendar.getInstance();
// spinner model -- for setting alarm
Date presentTime = calendar.getTime();
Date earliestTime = calendar.getTime();
Date latestTime = calendar.getTime();
SpinnerDateModel model = new SpinnerDateModel(presentTime ,
earliestTime,
latestTime,
Calendar.SECOND);
JSpinner alarm = new JSpinner(model);
alarm.setFont(big);
alarm.setFocusable(true);
alarm.setBackground(Color.blue);
alarm.setEditor (new JSpinner.DateEditor(alarm,"hh:mm:ss aa"));
alarm.setEnabled(true);
alarm.setSize(200,200);
display.setSize(300, 100);
alarm.setVisible(true);
display.add(alarm);
alarm.setEnabled(true);
display.setVisible(true);
}
public static void main(String[] args){
int newx=125, newy=95; // coordinates of time
boolean set;
set = true;
String st = " Starting ...";
String theTime = " ";
String theAlarm = " ";
Thread t = new Thread();
Calendar calendar = Calendar.getInstance();
t.start();
try{
//setAlarm();
if (set)
setAlarm();
else
for (;;) { // forever
addToBox(doTime(st));
t.sleep(1000);
} // forever
}catch (Exception e){}
//{ who cares?)
}
}
--
Sometimes I'm in a good mood.
Sometimes I'm in a bad mood.
When all my moods have cum to pass
i hope they bury me upside down
so the world can kiss me porcelain,
white, Irish bottom.