For Programmers: Free Programming Magazines  


Home > Archive > Java Help > June 2007 > almost ther ...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author almost ther ...
beelzibub @ bawston school for idiots

2007-06-14, 10:10 pm

.... it's the stateChange. when i click once once it goes up
one. clik again and it shoots up? other than that i think
it's fine.


/**
* @(#)BigFonts4
*
*
* @Kevin
* @version 1.40 2007/4/20
*/
import java.text.*;
import java.text.ParseException;

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Font;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.util.logging.Level;
import java.util.logging.Logger;

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.*;
import javax.swing.BorderFactory.*;
import javax.swing.border.Border;

abstract class BigFonts extends JComponent
implements MouseMotionListener, 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 static void addToBox(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, 100);
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 void soundAlarm (JSpinner alarm, JSpinner now){
Date warning = new Date(5);
JLabel go = new JLabel ("Time to go ...");
if (alarm.getValue() == now.getValue());
go.setVisible(true);
}


public static void setAlarm(JSpinner hour, JSpinner minute, JSpinner
second){

try{
String value,value2, value3;
value = (String)hour.getValue();
value2 = (String)minute.getValue();
value3 = (String)second.getValue();
hour.setValue(value + value2 + value3);
hour.commitEdit();
}catch (ParseException p) {}
}

public static void showit(JSpinner hour, JSpinner minute, JSpinner
second){

JFrame display2 = new JFrame("Set Allarm : ");
Border matte ;
matte = BorderFactory.createMatteBorder(1, 1, 10, 10,
Color.blue);
display2.setBounds(30,100,230,80);
display2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);;
display2.setLayout(new GridLayout(1,1));
hour.setFocusable(true);
hour.setBorder(matte);
display2.add(hour);
minute.setFocusable(true);
minute.setBorder(matte);
display2.add(minute);
second.setBorder(matte);
second.setFocusable(true);
display2.add(second);
display2.setVisible(true);
display2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

// spinner action


public void stateChanged(ChangeEvent evt){

try{
JSpinner setit = (JSpinner) (evt.getSource());
setit.enableInputMethods(true);
setit.commitEdit();
}catch (ParseException ex) {}
}

public void addSpinners(){

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(this);
hour.setEditor(new JSpinner.DateEditor(hour, ""));
hour.setVisible(true);

JSpinner minute = new JSpinner(model);
model.addChangeListener(this);
minute.setEditor(new JSpinner.DateEditor(minute, ""));
minute.setVisible(true);

JSpinner second = new JSpinner(model);
model.addChangeListener(this);
second.setEditor (new JSpinner.DateEditor(second, ""));
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();

t.start();
try{
for (;;) {
addToBox(doTime(st));
//setAlarm(hour, minute, second);
showit(hour, minute, second);
soundAlarm(hour, hour);
Thread.sleep(1000);

}
}catch (Exception e){}
}
}
--
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.
Lew

2007-06-14, 10:10 pm

beelzibub @ bawston school for idiots wrote:
> 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();
>
> t.start();
> try{
> for (;;) {
> addToBox(doTime(st));
> //setAlarm(hour, minute, second);
> showit(hour, minute, second);
> soundAlarm(hour, hour);
> Thread.sleep(1000);
> }
> }catch (Exception e){}
> }
> }


I am curious - why do you start a Thread that ends almost immediately?
> Thread t = new Thread();
>
> t.start();


And why have you not responded to my previous comments on this matter?

I am also curious - why have you continued to ignore several people's advice
not to ignore the Exception?

Please answer these three questions.

--
Lew
Knute Johnson

2007-06-14, 10:10 pm

Lew wrote:
> beelzibub @ bawston school for idiots wrote:
>
> I am curious - why do you start a Thread that ends almost immediately?
>
> And why have you not responded to my previous comments on this matter?
>
> I am also curious - why have you continued to ignore several people's
> advice not to ignore the Exception?
>
> Please answer these three questions.
>


He's a troll!

--

Knute Johnson
email s/nospam/knute/
JT

2007-06-14, 10:10 pm

beelzibub @ bawston school for idiots wrote:
> ... it's the stateChange. when i click once once it goes up
> one. clik again and it shoots up? other than that i think
> it's fine.


That depends on what you mean by fine. When I loaded your class into NB
and built it, I ran it and all I saw was a whole bunch of windows
appearing, like 1 second apart. Is that what you intended because to
me, it doesn't have a very good level of usability. I am running under
jdk1.6 on Ubuntu Feisty.
beelzibub @ bawston school for idiots

2007-06-14, 10:11 pm

Lew wrote:
> beelzibub @ bawston school for idiots wrote:
>
> I am curious - why do you start a Thread that ends almost immediately?
>
> And why have you not responded to my previous comments on this matter?
>
> I am also curious - why have you continued to ignore several people's
> advice not to ignore the Exception?
>
> Please answer these three questions.
>

1. how else am i suppose to get it to call every 1000 mils?

2. no one has ever told me what to do with it.

b


--
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.
beelzibub @ bawston school for idiots

2007-06-14, 10:11 pm

Knute Johnson wrote:
> Lew wrote:
>
> He's a troll!
>

.... i've been meaning to answer this false accusation. a troll is
characterized by a very long 'To' field. now go back in your archives
trash folder and LOOK at everyone of my posts. how many newsgroups have
i posted to (1).

.... see, you don't know me. i could be blind though i'm not. but why
should i tell you what i am? to you and every other group member i'm a
screen but a screen that's learning java. i like that and if i offend
you or anyone else well you can just get out of my sandbox.

bps;
balls in your court



--
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.
Patricia Shanahan

2007-06-14, 10:11 pm

beelzibub @ bawston school for idiots wrote:
> Knute Johnson wrote:

....
> ... i've been meaning to answer this false accusation. a troll is
> characterized by a very long 'To' field. now go back in your archives
> trash folder and LOOK at everyone of my posts. how many newsgroups have
> i posted to (1).

....

I think you may be confusing "troll" and "spammer". A troll can work on
a single newsgroup. See http://en.wikipedia.org/wiki/Internet_troll.

Personally, I don't care whether someone is a troll or not. If a repeat
poster shows no signs of making use of any advice, trying to help them
is a waste of time.

Patricia

Lew

2007-06-14, 10:11 pm

Lew wrote:

beelzibub @ bawston school for idiots wrote:[color=darkred]
> 1. how else am i suppose to get it to call every 1000 mils?


The idiom you show here doesn't do that. Does it help to use an idiom that
doesn't work because you can't think of one that does?

All this code does is start a Thread that immediately stops.

You might consider java.util.Timer or one of its ilk.

[color=darkred]
[color=darkred]
> 2. no one has ever told me what to do with it.


That's not true. I remember other posters telling you to at least log the
Exception.

For example, assuming log4j:

import org.apache.log4j.Logger;
public class SomethingOrOther
{
private Logger logger = Logger.getLogger( getClass() );
public static void main( String [] args )
{
try
{
doSomethingThatMightThrowAnException();
}
catch( AnException exc )
{
String msg = "AnException: "+ exc;
logger.error( msg ); // /* or use */ System.err.println( msg );
}
}
}

--
Lew
Oliver Wong

2007-06-15, 10:12 pm


"beelzibub @ bawston school for idiots" <comprehensivecenter> wrote in
message news:0ZednQv9-Jj9TezbnZ2dnUVZ_jydnZ2d@comcast.com...
> Knute Johnson wrote:
> ... i've been meaning to answer this false accusation. a troll is
> characterized by a very long 'To' field. now go back in your archives
> trash folder and LOOK at everyone of my posts. how many newsgroups have
> i posted to (1).


Clearly, your definition of troll differs from mine.

To me, a troll in this context is a person whose purpose is to disrupt
online discussion, rather than participate in it.

I don't know if you are a troll or not, but I can see how a reasonable
person might deduce that you are a troll based on your behaviour (e.g.
ignoring questions presented to you, asserting definitions that are not
generally agreed upon, etc.).

>
> ... see, you don't know me. i could be blind though i'm not. but why
> should i tell you what i am? to you and every other group member i'm a
> screen but a screen that's learning java. i like that and if i offend
> you or anyone else well you can just get out of my sandbox.


Putting the accusations aside for a moment, if you really want help
with your problems, I suggest you cooperate with the people trying to help
you. You might also want to work on your articulation skills. Based on
your writing, you sound like a native speaker of English, but I often have
trouble understanding what you're talking about. I saw elsewhere in this
thread you posted something which vaguely resembles answers to Lew's
questions. Note however that Lew specifically mentioned 3 questions, and
you posted 2 pseudo-answers. It's stuff like that that makes it hard to
understand what you're saying and thus hard to help you.

- Oliver


Lew

2007-06-15, 10:12 pm

Lew wrote:
> at least log the Exception.
>
> For example, assuming log4j:
>
> import org.apache.log4j.Logger;
> public class SomethingOrOther
> {
> private Logger logger = Logger.getLogger( getClass() );
> public static void main( String [] args )
> {
> try
> {
> doSomethingThatMightThrowAnException();
> }
> catch( AnException exc )
> {
> String msg = "AnException: "+ exc;
> logger.error( msg ); // /* or use */ System.err.println( msg );
> }
> }
> }


I made several mistakes in this example, at least one carelessly. It wasn't
meant to be compilable anyway, but I really shouldn't have mixed static and
instance stuff:

import org.apache.log4j.Logger;
public class SomethingOrOther
{
static class AnException extends Exception
{
public AnException(){}
public AnException( String msg ){ super( msg ); } // other two omitted
}
private final Logger logger = Logger.getLogger( getClass() );
private void doSomething() throws AnException
{
throw new AnException("oops");
}
public final void handle()
{
try
{
doSomething();
System.out.println( "Success" );
}
catch( AnException exc )
{
String msg = "AnException: "+ exc;
logger.error( msg ); // /* or use */ System.err.println( msg );
}
}
public static void main( String [] args )
{
SomethingOrOther soo = new SomethingOrOther();
soo.handle();
}
}

--
Lew
beelzibub @ bawston school for idiots

2007-06-15, 10:12 pm

Lew wrote:
> Lew wrote:
>
> I made several mistakes in this example, at least one carelessly. It
> wasn't meant to be compilable anyway, but I really shouldn't have mixed
> static and instance stuff:
>
> import org.apache.log4j.Logger;
> public class SomethingOrOther
> {
> static class AnException extends Exception
> {
> public AnException(){}
> public AnException( String msg ){ super( msg ); } // other two omitted
> }
> private final Logger logger = Logger.getLogger( getClass() );
> private void doSomething() throws AnException
> {
> throw new AnException("oops");
> }
> public final void handle()
> {
> try
> {
> doSomething();
> System.out.println( "Success" );
> }
> catch( AnException exc )
> {
> String msg = "AnException: "+ exc;
> logger.error( msg ); // /* or use */ System.err.println( msg );
> }
> }
> public static void main( String [] args )
> {
> SomethingOrOther soo = new SomethingOrOther();
> soo.handle();
> }
> }
>

.... non comprende, monsiuer. wouldn't it be easier to just put a
System.out.writeln("oops") after i have caught it since it theoretically
will never get there. we catch for show.

b


--
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.
Lew

2007-06-15, 10:12 pm

Lew wrote:

beelzibub @ bawston school for idiots wrote:[color=darkred]
> ... non comprende, monsiuer. wouldn't it be easier to just put a
> System.out.writeln("oops") after i have caught it since it theoretically
> will never get there. we catch for show.


You do /not/ catch Exceptions just for show! This is what people have been
telling you.

You catch Exceptions to allow issues to be detected and resolved, and to
permit the program to resume a valid state. It is /not/ just for show!

You do /not/ catch Exceptions just for show!

I don't know what you mean by "after" you've caught the Exception. The code
sample above shows where you would put the System.err.println() (a better
choice for error messages than System.out). I have eliminated the log4j stuff
to simplify matters.

It is not enough to simply create an error message without the Exception
information. You should include information from the Exception in the message
so you can solve what happened. I don't show it in the example above, but it
is usually helpful to log at least part of the stack trace.

This code example is complete. Did you try running it? What happened?

That's two questions I'm asking. Make sure the answer to the first one is
"yes" before replying.

--
Lew
Lew

2007-06-15, 10:12 pm

-------- Original Message --------
From: beelzibub2
Organization: i could tell you but then i'd have to kill you

> ... ok, i ran it. it doesnot appear to do anything. umm, is there a way
> to maSK A STRING TO A DATE???


When I run it this happens:

$ java testit/SomethingOrOther
AnException: testit.SomethingOrOther$AnException: oops

I ran the exact code I sent, save that it was in a package.

This is not what you saw?

--
Lew
Lew

2007-06-15, 10:12 pm

beelzibub @ bawston school for idiots wrote:
.... directly to Lew

I have requested several times that you send your questions to the newsgroup.
Please send your questions to the newsgroup. I do not run a help desk.

If you want private consultation let's talk big American dollars.

--
Lew


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com