For Programmers: Free Programming Magazines  


Home > Archive > Java Help > April 2007 > take a look ... it's basic but it's mine, all mine!!!









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 take a look ... it's basic but it's mine, all mine!!!
i'm not llloyd wood

2007-04-20, 10:07 pm

/**
* @(#)theButton.java
*
*
* @author
* @version 1.00 2007/4/18
*/

import java.text.*;
import java.text.SimpleDateFormat.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
import java.util.Date;

public class theButton
{

private static void out(String s) {
System.out.print(s);
}
private static void out(Calendar d) {
System.out.println(d);
}
private static void out(int i) {
System.out.println(i);
}

public static void drawTime(Calendar d){
out(d.toString());
}


public static void main (String[] args){

Thread t = new Thread();
t.start();
int i = 0;
while (i++ < 10) // do
{
Calendar now = Calendar.getInstance();
String theTime;
Date stringTime = now.getTime(); // had to use Date
JFrame frame = new JFrame("Wht time is it?");
JPanel pane = new JPanel();
JButton theButton = new JButton(stringTime.toString());
pane.setVisible(true);
pane.setSize(500,500);
frame.add(theButton);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
try{
t.sleep(1000);
}
catch (Exception e) {
// do nothing
}
}
}
}
--
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.
Eric Sosman

2007-04-20, 10:07 pm

i'm not llloyd wood wrote On 04/20/07 15:12,:
> /**
> * @(#)theButton.java
> [...]


Did you mean to ask a question about the code?
There are some awkwardnesses and oddities; were you
perhaps looking for commentary? Sad to say, a few
of us out here in Usenetland are not mind readers.

--
Eric.Sosman@sun.com
Knute Johnson

2007-04-20, 10:07 pm

i'm not llloyd wood wrote:
> /**
> * @(#)theButton.java
> *
> *
> * @author
> * @version 1.00 2007/4/18
> */
>
> import java.text.*;
> import java.text.SimpleDateFormat.*;
> import java.awt.event.*;
> import javax.swing.*;
> import java.util.Calendar;
> import java.util.Date;
>
> public class theButton
> {
>


All of these out() methods are never used

> private static void out(String s) {
> System.out.print(s);
> }
> private static void out(Calendar d) {
> System.out.println(d);
> }
> private static void out(int i) {
> System.out.println(i);
> }
>
> public static void drawTime(Calendar d){
> out(d.toString());
> }
>
>
> public static void main (String[] args){
>


This thread does nothing

> Thread t = new Thread();
> t.start();
> int i = 0;


Every time this loops you are making a whole new set of components, you
only need to make them once.

> while (i++ < 10) // do
> {
> Calendar now = Calendar.getInstance();
> String theTime;
> Date stringTime = now.getTime(); // had to use Date
> JFrame frame = new JFrame("Wht time is it?");
> JPanel pane = new JPanel();


Since you aren't using the button to do any actions maybe a component
such as a JLabel would be better here.

> JButton theButton = new JButton(stringTime.toString());


There is no need to set the JPanel visible as it becomes visible when
the JFrame is made visible.

> pane.setVisible(true);
> pane.setSize(500,500);
> frame.add(theButton);
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> frame.setSize(300, 300);
> frame.setVisible(true);
> try{
> t.sleep(1000);
> }
> catch (Exception e) {
> // do nothing
> }
> }
> }
> }


Swing GUI components should be constructed and modified on the Event
Dispatch Thread (with some minor exceptions). To do that you need to
put your GUI creation code inside of code similar to this:

Runnable r = new Runnable() {
public void run() {
// create gui
}
};
EventQueue.invokeLater(r);

This starts the code in the Runnable on the Event Dispatch Thread.

To update your clock you need to have a thread or timer running that can
put new data in your time display (whether you use a button or a label).

To create a class that has a runnable thread use something like this:

public class Runner implements Runnable {
public Runner() {
}

public void run() {
while ( ) { // some condition is true, run
}
}

public static void main(String[] args) {
Runner runner = new Runner();
new Thread(runner).start();
}
}

So for example, a non-GUI clock program could look like this;

import java.util.*;

public class Clock implements Runnable {
public void run() {
while (true) {
Date now = new Date();
System.out.print(now.toString()+"\r");
try {
Thread.sleep(1000);
} catch (InterruptedException ie) { }
}
}
public static void main(String[] args) {
new Thread(new Clock()).start();
}
}

--

Knute Johnson
email s/nospam/knute/
Encetendick7

2007-04-24, 3:22 am

http://Halle-Berry-anal-action.org/...hp?movie=148803
i'm not llloyd wood

2007-04-28, 10:09 pm

Eric Sosman wrote:
> i'm not llloyd wood wrote On 04/20/07 15:12,:
>
> Did you mean to ask a question about the code?
> There are some awkwardnesses and oddities; were you
> perhaps looking for commentary? Sad to say, a few
> of us out here in Usenetland are not mind readers.
>
> /**
> * @(#)MyClock2.java
> *
> *
> * @Kevin
> * @version 1.00 2007/4/20
> */
> import java.awt.*;
> import java.awt.Font;
> import java.text.*;
> import java.text.DateFormat;
> import java.util.*;
> import java.util.Calendar;
> import javax.swing.*;
>
>
>
>
> public class BigFonts {
>
>
> public static String doTime(String ts){
>
>
> Calendar calendar = Calendar.getInstance();
> String am_pm="";
> String timeString= "";
>
> String s ="";
> String m ="";
>
> int second = calendar.get(Calendar.SECOND);
> int minute = calendar.get(Calendar.MINUTE);
> int hour = calendar.get(Calendar.HOUR);
>
> if(calendar.get(Calendar.AM_PM) == 0)
> am_pm = " AM";
> else
> am_pm = " PM";
>
> timeString = hour+":"+minute+":"+second+am_pm;
> if (second < 10){
> s = "0" + second;
> timeString= hour+":"+minute+":"+s+am_pm;
> }
> if (minute < 10){
> m = "0"+minute;
> timeString= hour+":"+m+":"+second+am_pm;
> }
>
> if(hour >= 12){
> hour = hour - 12; // force 12 hour clock
> timeString= hour+":"+minute+":"+second+am_pm;
> }
> return timeString;
>
>
> }
>
>
>
> public static void addToBox(String theTime)
> {
> Font big = new Font("Serif", Font.BOLD, 50);
> JButton thedisplay = new JButton(theTime);
> thedisplay.setFont(big);
> JFrame display = new JFrame("What Time is it?");
> display.add(thedisplay);
> display.setBackground(Color.CYAN);
> display.setSize(300,100);
> display.setFont(big);
> display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> display.setVisible(true);
>
> }
>
>
>
> public static void main(String[] args){
>
> String st = " ";
> Thread t = new Thread();
> t.start();
> try{
> for (;;) { // forever
> addToBox(doTime(st));
> t.sleep(1000);
> } // forever
> }catch (Exception e){
> //{ who cares?)
> } // catch
> }
>
> }
>


.... yes pls.

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.
i'm not llloyd wood

2007-04-28, 10:09 pm

Knute Johnson wrote:
> i'm not llloyd wood wrote:
>
> All of these out() methods are never used
>
>
> This thread does nothing
>
>
> Every time this loops you are making a whole new set of components, you
> only need to make them once.
>
>
> Since you aren't using the button to do any actions maybe a component
> such as a JLabel would be better here.
>
>
> There is no need to set the JPanel visible as it becomes visible when
> the JFrame is made visible.
>
>
> Swing GUI components should be constructed and modified on the Event
> Dispatch Thread (with some minor exceptions). To do that you need to
> put your GUI creation code inside of code similar to this:
>
> Runnable r = new Runnable() {
> public void run() {
> // create gui
> }
> };
> EventQueue.invokeLater(r);
>
> This starts the code in the Runnable on the Event Dispatch Thread.
>
> To update your clock you need to have a thread or timer running that can
> put new data in your time display (whether you use a button or a label).
>
> To create a class that has a runnable thread use something like this:
>
> public class Runner implements Runnable {
> public Runner() {
> }
>
> public void run() {
> while ( ) { // some condition is true, run
> }
> }
>
> public static void main(String[] args) {
> Runner runner = new Runner();
> new Thread(runner).start();
> }
> }
>
> So for example, a non-GUI clock program could look like this;
>
> import java.util.*;
>
> public class Clock implements Runnable {
> public void run() {
> while (true) {
> Date now = new Date();
> System.out.print(now.toString()+"\r");
> try {
> Thread.sleep(1000);
> } catch (InterruptedException ie) { }
> }
> }
> public static void main(String[] args) {
> new Thread(new Clock()).start();
> }
> }
>

.... i learned a lot from it and now want to
try a calendar. any tips? um, what is the
marque???

?
--

--
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.
a24900@googlemail.com

2007-04-28, 10:09 pm

On Apr 28, 7:25 pm, i'm not llloyd wood <comprehensivecenter> wrote:
> any tips?


Get your head examined.

Sponsored Links







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

Copyright 2008 codecomments.com