•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# binary clock.javaStyle();

binary-clock

No replies to this topic

### #1 UniBrain

UniBrain

CC Regular

• Validating
• 48 posts
• Programming Language:C, Java, C++, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Pascal, Assembly, Scheme, Prolog, Others
• Learning:Others

Posted 17 March 2013 - 12:05 PM

Before we commence, I must shamelessly showoff a conceptual operating system interface of mine, (brain universe-synonymous interface) created via java:

To be fair, it features a freshly baked binary clock[size=small].javaStyle().

Capture of binary clock for clarity:

A carefully scribed definition:
The binary clock consists, of three segments, symbolizing hour, minutes and seconds respectively.

Each segment consists of two columns, the first symbolizing objects that may yield 10's digit values, where as the second column may yield 1's digit values.

~The meaning of the second column~
Now for all segments, the 1's digit columns (second column) consist of 4 objects, that enable yeilding of values in range 0-9.

~The meaning of the first column~
With the exception of the first segment, the segements first columns consist of 3 objects, that enable yeilds of values in range 0-6.
{EXAMPLE: Minimum Seconds/Minutes: 00, Maximum Seconds/Minutes :60}

~Conclusion~
The first segment is an exception. The first column has one less object, due to the simple factum that only values of 0-2 may be represented, since there is only
24 hours in one day.
{EXAMPLE: Minimum Hours: 00 Maximum Hours:20}

~Code-Scheme~
The most important aspect, is that you discover a way to map the different possible combinations of time values, with respect to the circles that occur in a binary clock.

Here is a nicely scribed image of mine that illustrates just this:

Code:

The convenience class of common functions:

```

//Author(s): Jordan Micah Bennett
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import java.awt.Font;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.FontMetrics;
import java.awt.geom.Rectangle2D;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.awt.Color;
import java.util.regex.Pattern;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import javax.imageio.ImageIO;
import java.awt.Cursor;
import java.awt.event.MouseEvent;

public class UNICODE_ConveniencePack
{
//attributes
public UNICODE_ConveniencePack ( )
{
}

//misc
public void hideCursor ( JPanel context )
{
ImageIcon imageIcon = new ImageIcon ( "null" );
Image image = imageIcon.getImage ( );
image = context.createImage ( image.getSource ( ) );

Cursor blankCursor = Toolkit.getDefaultToolkit ( ).createCustomCursor ( image, new Point ( 0, 0 ), "blank cursor" );

context.setCursor ( blankCursor );
}

public void restoreCursor ( JPanel context )
{
context.setCursor ( Cursor.getDefaultCursor ( ) );
}

public String [ ] getDelimitedArray ( String data, String skip_data, String delimiter, int num_elements )
{
String [ ] string = new String [ num_elements ];
//if i tell the function to perform exept when data is type  skip data, it
//will do so without attempting to segment the aformentioned data type
//establish data we want to delimit as delimited data
Scanner scanner = new Scanner ( data ).useDelimiter ( delimiter );

for ( int elements = 0; elements < num_elements; elements ++ )
{
if ( !data.equals ( skip_data ) )
string [ elements ] = scanner.next ( );
else
string [ elements ] = skip_data;
}

return string;
}

//get whether a substring of a string exists within a bigger string.
public boolean stringSubsetEnquiry ( String full_string, String sub_string, int sub_portion_start, int sub_portion_end )
{
return full_string.indexOf ( sub_string.substring ( sub_portion_start, sub_portion_end ) ) != -1;
}
public String [ ] grownArray ( String [ ] array, String newElement )
{
String [ ] grownArray = new String [ array.length + 1 ];

//pump old data into new array
for ( int i = 0; i < array.length; i ++ )
grownArray [ i ] = array [ i ];

//pump new data into new array
grownArray [ grownArray.length - 1 ] = newElement;

//redefine original array wrt grown array
return grownArray;
}
//get whether a substring of a string exists within a bigger string.
public boolean stringSubsetEnquiry ( String full_string, String sub_string )
{
return full_string.indexOf ( sub_string ) != -1;
}

//make array
public String [ ] makeArray ( String list, String delimiter )
{
String [ ] array = list.split ( delimiter );
return array;
}

public File makeFile ( String stream )
{
return new File ( stream );
}
public void makeDirectory ( String fileStream )
{
new File ( fileStream ).mkdir ( );
}
public void makePhysicalFile ( String fileStream )
{
try
{
PrintWriter pw = new PrintWriter ( new FileWriter ( fileStream ) );
pw.write ( "" );
pw.close ( );
}
catch ( Exception error ) { };
}
public String getFileContent ( String fileStream, String contentDelimiter )
{
String value = "";
try
{
Scanner scanner = new Scanner ( new File ( fileStream ) );
while ( scanner.hasNext ( ) )
value += scanner.nextLine ( ) + contentDelimiter;
}
catch ( Exception error ) { }
return value;
}

public void makePhysicalFile ( String fileStream, String content )
{
try
{
PrintWriter pw = new PrintWriter ( new FileWriter ( fileStream ) );
pw.write ( content );
pw.close ( );
}
catch ( Exception error ) { };
}
public void deleteFile ( File file )
{
file.delete ( );
}

//method to convert string to url
public URL makeUrl ( String path )
{
URL url = null;
File file = new File ( path );
try
{
url = file.toURL ( );
}
catch ( Exception error )
{
}
return url;
}

public void displayMessage ( JFrame frame, String message, String title, String iconType )
{
if ( ( iconType == "i" ) || ( iconType == "I" ) )
JOptionPane.showMessageDialog ( frame, message, title, JOptionPane.INFORMATION_MESSAGE );
if ( ( iconType == "w" ) || ( iconType == "W" ) )
JOptionPane.showMessageDialog ( frame, message, title, JOptionPane.WARNING_MESSAGE );
if ( ( iconType == "e" ) || ( iconType == "E" ) )
JOptionPane.showMessageDialog ( frame, message, title, JOptionPane.ERROR_MESSAGE );
if ( ( iconType == "q" ) || ( iconType == "Q" ) )
JOptionPane.showMessageDialog ( frame, message, title, JOptionPane.QUESTION_MESSAGE );
}

//tests if filename is of type specified as target
public boolean getFileTypeEnquiry ( String filename, String enquiryTarget )
{
return stringSubsetEnquiry ( filename, enquiryTarget );
}

//checks if file exists wrt file location supplied.
//if not it creates this file physically (not in memory)
public boolean getFileExistenceEnquiry ( String fileStream )
{
boolean flag = false;
File file = new File ( fileStream );
if ( file.exists ( ) )
flag = false;
else
{
flag = true;
makePhysicalFile ( fileStream );
file = null;
}
return flag;
}

//make timer data -- array containing minutes aat index 0, and seconds at index 1
public int [ ] makeTimerData ( int elapsedTime )
{
int [ ] TimerData = new int [ 2 ];
int rawSeconds = elapsedTime/1000;
int refinedSeconds = rawSeconds % 60;
int minutes = rawSeconds / 60;
TimerData [ 0 ] = minutes;
TimerData [ 1 ] = refinedSeconds;
return TimerData;
}

//convert minutes to milliseconds
public int makeMilliseconds ( int minutes )
{
int seconds = minutes * 60;
int milliseconds = seconds * 1000;
return milliseconds;
}

public int makeMillisecondsFromSeconds ( int seconds )
{
int milliseconds = seconds * 1000;
return milliseconds;
}

//make proper time from milliseconds
//used to display time remaining from user profile in (user freindly form)
public String [ ] getTimeFromMilliseconds ( int milliseconds )
{
//get seconds
int rawSeconds = milliseconds / 1000;
int refinedSeconds = rawSeconds % 60;
//get minutes
int minutes = rawSeconds/60;

String finalSeconds = "";

if ( refinedSeconds < 10 )
finalSeconds = "0" + refinedSeconds;

else
finalSeconds = "" + refinedSeconds;

String value [ ] = { "" + minutes, finalSeconds, "" + refinedSeconds };
return value;
}

//make proper time from milliseconds
//used to display time remaining from user profile in (user freindly form)
public String getTime ( int milliseconds )
{
//get seconds
int rawSeconds = milliseconds / 1000;
int refinedSeconds = rawSeconds % 60;
//get minutes
int minutes = rawSeconds/60;

String finalSeconds = "";

if ( refinedSeconds < 10 )
finalSeconds = "0" + refinedSeconds;

else
finalSeconds = "" + refinedSeconds;

String value = minutes + " : " + finalSeconds;
return value;
}

//get secs from millisecs
public int getSeconds ( double milliseconds )
{
return ( int ) ( milliseconds / milliseconds );
}

public Font getCustomFont ( String inputStream )
{
Font font = null;
try
{
font = Font.createFont ( Font.TRUETYPE_FONT, new File ( inputStream ) );
}
catch ( Exception error ) { }
return font;
}

public void createCustomCursor ( String cursorImageStream, JPanel destinationPanel )
{
//create image
ImageIcon imageIcon = new ImageIcon ( cursorImageStream );
Image image = imageIcon.getImage ( );
image = destinationPanel.createImage ( image.getSource ( ) );

//initalise "hot spot"
Point point = new Point ( 0, 0 );

//create toolkit
Toolkit toolkit = Toolkit.getDefaultToolkit ( );

//initialise cursor
Cursor cursor = toolkit.createCustomCursor ( image, point, "Cursor" );
}

public String getUpperCaseFirstLetterOfWord ( String word )
{
String firstLetter = "" + word.charAt ( 0 );
String finalWord = firstLetter.toUpperCase ( ) + word.substring ( 1, word.length ( ) );
return finalWord;
}

//burrowed function
public String getNonDupilatedCharacters ( String duplicateTarget )
{
StringBuilder noDupes = new StringBuilder ( );
for ( int i = 0; i < duplicateTarget.length ( ); i++ )
{
String si = duplicateTarget.substring ( i, i + 1 );
if ( noDupes.indexOf ( si ) == -1 )
{
noDupes.append ( si );
}
}
return noDupes.toString ( );
}

public boolean getIntegerIncrementEnquiry ( int integer, int max )
{
boolean flag = false;
int previous = integer;
int next = integer + 1;
if ( next < max )
{
if ( next > previous )
flag = true;
else
flag = false;
}
return flag;
}

public boolean getIntegerDecrementEnquiry ( int integer, int min )
{
boolean flag = false;
int next = integer;
int previous = integer - 1;
if ( previous > min )
{
if ( previous < next )
flag = true;
else
flag = false;
}
return flag;
}

public double getDisplayWidthFromString ( String input, int fontSize )
{
Font font = new Font ( "Times New Roman", Font.PLAIN, fontSize );
FontMetrics fontMetrics = new FontMetrics ( font ) { };
return fontMetrics.getStringBounds ( input, null ).getWidth ( );
}

public double getDisplayHeightFromString ( String input, int fontSize )
{
Font font = new Font ( "Times New Roman", Font.PLAIN, fontSize );
FontMetrics fontMetrics = new FontMetrics ( font ) { };
return fontMetrics.getStringBounds ( input, null ).getHeight ( );
}

public int getLargestInteger ( ArrayList numList )
{
java.util.Collections.sort ( numList );
return ( int ) numList.get ( numList.size ( ) - 1 );
}

public void printFile ( String content, String stream )
{
try
{
PrintWriter pw = new PrintWriter ( new FileWriter ( stream ) );
pw.print ( content );
pw.close ( );
}
catch ( Exception e ) { }
}

public ArrayList generateArrayListContentFromFile ( String fileStream )
{
ArrayList value = new ArrayList ( );
try
{
Scanner scanner = new Scanner ( new File ( fileStream ) );
while ( scanner.hasNext ( ) )
value.add ( scanner.nextLine ( ) );
scanner.close ( );
}
catch ( Exception e ) { }
return value;
}

public String getFileContent ( String fileStream )
{
String value = "";
try
{
Scanner scanner = new Scanner ( new File ( fileStream ) );
while ( scanner.hasNext ( ) )
value += scanner.nextLine ( ) + "\n";
}
catch ( Exception error ) { }
return value;
}

public String getMatchingValue ( String input, String searchTag, String searchTag2, String delimiter )
{
String value = "";
ArrayList valueList = new ArrayList ( );

//divide input into segments
try
{
Scanner scanner = new Scanner ( input ).useDelimiter ( delimiter );

while ( scanner.hasNext ( ) )
valueList.add ( scanner.next ( ) );
scanner.close ( );
}
catch ( Exception error ) { }

//loop through the segment collection checking against the search tag
for ( int i = 0; i < valueList.size ( ); i ++ )
if ( stringSubsetEnquiry ( ( String ) valueList.get ( i ), searchTag ) )
value = ( String ) valueList.get ( i );
else if ( stringSubsetEnquiry ( ( String ) valueList.get ( i ), searchTag2 ) )
value = ( String ) valueList.get ( i );

return value;

//proud of myself wrote this once, worked, well, as usual...
}

public void enableFullScreenMode ( JFrame applicationFrame )
{
java.awt.GraphicsEnvironment graphicsEnvironment = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment ( );
java.awt.GraphicsDevice [ ] graphicsDevices = graphicsEnvironment.getScreenDevices ( );
try
{
graphicsDevices [ 0 ].setFullScreenWindow ( applicationFrame );
}
finally
{
graphicsDevices [ 0 ].setFullScreenWindow ( applicationFrame );
}
}

public void shutDownComputer ( )
{
String shutdownCmd = "shutdown -s";
try
{
Process child = Runtime.getRuntime ( ).exec ( shutdownCmd );
}
catch ( Exception error ) { }
}

public void executeCommand ( String command )
{
try
{
Process child = Runtime.getRuntime ( ).exec ( command );
}
catch ( Exception error ) { }
}

public int getDirectoryCardinality ( String directory )
{
return new File ( directory ).list ( ).length;
}

//burrowed
public void saveScreen ( String fileName )
{
try
{
Robot robot = new Robot();

BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(screenShot, "PNG", new File(fileName));
}
catch ( Exception error )
{
}
}

public InputStream getInputStreamFromInput ( String scannerLine )
{
return new ByteArrayInputStream ( scannerLine.getBytes ( ) );
}

public int getArraySum ( int [ ] value )
{
int returnValue = 0;

for ( int i = 0; i < value.length; i ++ )
returnValue += value [ i ];

return returnValue;
}
}
```

A date creation class:

```

//Author(s): Jordan Micah Bennett
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class UNICODE_DateCreator
{
//declare time variable
private Date date = new Date ( ); //moth, day time
private UNICODE_ConveniencePack conveniencePack = new UNICODE_ConveniencePack ( );

public UNICODE_DateCreator ( )
{
}

//method to return day, year, and month
public String getDate ( ) //..this does not need to be in a loop, so use as separate function.
{
String day = "";
String month = "";

//determine day
switch ( date.getDay ( ) )
{
case 0 : day = "Sunday"; break; case 1 : day = "Monday"; break;  case 2 : day = "Tuesday"; break; case 3 : day = "Wednesday"; break; case 4 : day = "Thursday"; break; case 5 : day = "Friday"; break;  case 6 : day = "Saturday"; break;
}

//determine month
switch ( date.getMonth ( ) )
{
case 0 : month = "January"; break; case 1 : month = "February"; break; case 2 : month = "March"; break; case 3 : month = "April"; break; case  4: month = "May"; break; case 5 : month = "June"; break; case 6 : month = "July"; break; case 7 : month = "August"; break; case 8 : month = "September"; break; case 9 : month = "October"; break; case 10 : month = "November"; break; case 11 : month = "December"; break;
}

//year
Date date_year = new Date ( );
DateFormat year = new SimpleDateFormat ( "yyyy" );

//display derived date
return "DATE : " + day + " " + month + " " + date.getDate ( ) + " , " + year.format ( date_year );
}

public String getTime ( )
{
return date.getHours ( ) + ":" + date.getMinutes ( ) + ":" + date.getSeconds ( );
}

public int getHours ( )
{
return date.getHours ( );
}
public int getMinutes ( )
{
return date.getMinutes ( );
}
public int getSeconds ( )
{
return date.getSeconds ( );
}

public int [ ] getHoursDigits ( )
{
int [ ] returnValue = new int [ 2 ];

String hours = "" + getHours ( );

try
{
returnValue [ 0 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( hours, "", "", 2 ) [ 0 ] );
returnValue [ 1 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( hours, "", "", 2 ) [ 1 ] );
}
catch ( Exception error )
{
returnValue [ 0 ] = 0;
returnValue [ 1 ] = Integer.parseInt ( hours );
}

return returnValue;
}

public int [ ] getMinutesDigits ( )
{
int [ ] returnValue = new int [ 2 ];

String minutes = "" + getMinutes ( );

try
{
returnValue [ 0 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( minutes, "", "", 2 ) [ 0 ] );
returnValue [ 1 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( minutes, "", "", 2 ) [ 1 ] );
}
catch ( Exception error )
{
returnValue [ 0 ] = 0;
returnValue [ 1 ] = Integer.parseInt ( minutes );
}

return returnValue;
}

public int [ ] getSecondsDigits ( )
{
int [ ] returnValue = new int [ 2 ];

String seconds = "" + getSeconds ( );

try
{
returnValue [ 0 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( seconds, "", "", 2 ) [ 0 ] );
returnValue [ 1 ] = Integer.parseInt ( conveniencePack.getDelimitedArray ( seconds, "", "", 2 ) [ 1 ] );
}
catch ( Exception error )
{
returnValue [ 0 ] = 0;
returnValue [ 1 ] = Integer.parseInt ( seconds );
}

return returnValue;
}
}
```

The binary clock structure class:

```

//Author:Jordan Micah Bennett
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

public class UNICODE_BinaryClockStructure
{
//attributes
private Ellipse2D body = null;
private int state = 0;
private int decimalValue = 0;
private Color enabledStateColour = null, disabledStateColour = null, currentColour = null, targetBackgroundColour = null;

//constructor
public UNICODE_BinaryClockStructure ( int state, int decimalValue, Color enabledStateColour, Color disabledStateColour, Color targetBackgroundColour, int x, int y, int span )
{
this.state = state;
this.decimalValue = decimalValue;
this.enabledStateColour = enabledStateColour;
this.disabledStateColour = disabledStateColour;
this.targetBackgroundColour = targetBackgroundColour;
body = new Ellipse2D.Double ( x, y, span, span );
}

//methods
//accessors
public int getState ( )
{
return state;
}
public int getDecimalValue ( )
{
return decimalValue;
}
public int getSpan ( )
{
return ( int )  body.getWidth ( );
}
public Ellipse2D getBody ( )
{
return body;
}
public Color getEnabledStateColour ( )
{
return enabledStateColour;
}
public Color getDisabledStateColour ( )
{
return disabledStateColour;
}

//mutators
public void setState ( int value )
{
state = value;
}

//others
public void determineCurrentColour ( Graphics2D graphics2d )
{
switch ( state )
{
case -1: currentColour = targetBackgroundColour; break; //idle/Ignored
case 1: currentColour = enabledStateColour; break;
case 0: currentColour = disabledStateColour; break;
}
graphics2d.setColor ( currentColour );
}

public void draw ( Graphics2D graphics2d )
{
determineCurrentColour ( graphics2d );
graphics2d.fill ( body );
}
}
```

The binary clock structure class condensed into a simple element:

```

//Author:Jordan Micah Bennett
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;

public class UNICODE_ClockElement extends JPanel
{
//attributes
private UNICODE_BinaryClockStructure binaryClockStructure = null;

//constructor
public UNICODE_ClockElement ( int state, int decimalValue, Color enabledStateColour, Color disabledStateColour, Color clockElementBackgroundColour, int x, int y, int span )
{
this.binaryClockStructure = new UNICODE_BinaryClockStructure ( state, decimalValue, enabledStateColour, disabledStateColour, clockElementBackgroundColour, x, y, span );
setBackground ( clockElementBackgroundColour );
}

//paint component
public void paintComponent ( Graphics graphics )
{
super.paintComponent ( graphics );
Graphics2D graphics2d = ( Graphics2D ) graphics;

setSize ( new Dimension ( binaryClockStructure.getSpan ( ), binaryClockStructure.getSpan ( ) ) );

binaryClockStructure.draw ( graphics2d );
}

public void setState ( int value )
{
binaryClockStructure.setState ( value );
}
public int getState ( )
{
return binaryClockStructure.getState ( );
}
public int getDecimalValue ( )
{
return binaryClockStructure.getDecimalValue ( );
}
}
```

And finally, the actual binary clock, where the magic happens.

```

//Author:Jordan Micah Bennett
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JPanel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;
import javax.swing.Timer;
import javax.swing.BoxLayout;
import java.util.Hashtable;
import java.util.Dictionary;
import javax.swing.JFrame;

public class UNICODE_BinaryClock extends JPanel
{
//attributes
private JPanel clockBaseContainer = null;

private JPanel segmentsContainer = new JPanel ( );

//clock element components
private UNICODE_ClockElement [ ] clockElementHourSegmentsFirstColumn = new UNICODE_ClockElement [ 4 ];
private UNICODE_ClockElement [ ] clockElementHourSegmentsSecondColumn = new UNICODE_ClockElement [ 4 ];
private JPanel [ ] segmentContainersA = new JPanel [ 2 ];
private JPanel segmentContainersAContainer = new JPanel ( );

private UNICODE_ClockElement [ ] clockElementMinuteSegmentsFirstColumn = new UNICODE_ClockElement [ 4 ];
private UNICODE_ClockElement [ ] clockElementMinuteSegmentsSecondColumn = new UNICODE_ClockElement [ 4 ];
private JPanel [ ] segmentContainersB = new JPanel [ 2 ];
private JPanel segmentContainersBContainer = new JPanel ( );

private UNICODE_ClockElement [ ] clockElementSecondSegmentsFirstColumn = new UNICODE_ClockElement [ 4 ];
private UNICODE_ClockElement [ ] clockElementSecondSegmentsSecondColumn = new UNICODE_ClockElement [ 4 ];
private JPanel [ ] segmentContainersC = new JPanel [ 2 ];
private JPanel segmentContainersCContainer = new JPanel ( );

private Color clockElementBaseColour = null, clockBaseContainerColour = null;
private Color clockElementEnabledColour = null, clockElementDisabledColour = null;
private UNICODE_DateCreator dateCreator = new UNICODE_DateCreator ( );
private UNICODE_ConveniencePack conveniencePack = new UNICODE_ConveniencePack ( );

private Timer binaryClockTimer = null;

//consists of a dictionary of digit value keys, versus integer array of usable integers which will be used to enable relevant states as time expires
private Dictionary <Integer, int [ ]> binaryClockDigitalOutputVersusRequiredIndicesDictionary = null;

//establish alternative method to display time
private String defaultDateString = "";
private Color defaultDateStringColour = null;

//establish string to control whether binary mode or default mode may be enabled
private int clockElementSize = 0;
private int [ ] decimalValues = new int [ 4 ];

private int bufferHeight;

//constructor
public UNICODE_BinaryClock ( int bufferHeight, Color clockElementBaseColour, Color clockBaseContainerColour, Color clockElementEnabledColour, Color clockElementDisabledColour, int tickDelay, int clockElementSize, Color defaultDateStringColour )
{
//establish default time string requirments
this.defaultDateStringColour = defaultDateStringColour;
this.clockElementSize = clockElementSize;
this.bufferHeight = bufferHeight;

//setup dictionar

//establish timer
binaryClockTimer = new Timer ( tickDelay, new binaryClockActionListening ( ) );

//establish clockElementBaseColour
this.clockElementBaseColour = clockElementBaseColour;
this.clockBaseContainerColour = clockBaseContainerColour;
this.clockElementEnabledColour = clockElementEnabledColour;
this.clockElementDisabledColour = clockElementDisabledColour;

//establish clockElementBase

//establish decimal value list
decimalValues [ 0 ] = 1;
decimalValues [ 1 ] = 2;
decimalValues [ 2 ] = 4;
decimalValues [ 3 ] = 8;

//generate components
generateComponents ( );
}

public void resetActiveColour ( Color value )
{
clockElementEnabledColour = value;
}

public void cleanSurfaces ( )
{
//refresh inner-surface objects
for ( UNICODE_ClockElement element : clockElementHourSegmentsFirstColumn )
element.removeAll ( );
for ( UNICODE_ClockElement element : clockElementHourSegmentsSecondColumn )
element.removeAll ( );

for ( UNICODE_ClockElement element : clockElementMinuteSegmentsFirstColumn )
element.removeAll ( );
for ( UNICODE_ClockElement element : clockElementMinuteSegmentsSecondColumn )
element.removeAll ( );

for ( UNICODE_ClockElement element : clockElementSecondSegmentsFirstColumn )
element.removeAll ( );
for ( UNICODE_ClockElement element : clockElementSecondSegmentsSecondColumn )
element.removeAll ( );

//refresh segment containers
for ( JPanel panel : segmentContainersA )
panel.removeAll ( );
for ( JPanel panel : segmentContainersB )
panel.removeAll ( );
for ( JPanel panel : segmentContainersC )
panel.removeAll ( );

//refresh main container
segmentsContainer.removeAll ( );

//refresh frame context
remove ( segmentsContainer );
}

public void refreshSurfaces ( )
{
//refresh inner-surface objects
for ( UNICODE_ClockElement element : clockElementHourSegmentsFirstColumn )
element.repaint ( );
for ( UNICODE_ClockElement element : clockElementHourSegmentsSecondColumn )
element.repaint ( );

for ( UNICODE_ClockElement element : clockElementMinuteSegmentsFirstColumn )
element.repaint ( );
for ( UNICODE_ClockElement element : clockElementMinuteSegmentsSecondColumn )
element.repaint ( );

for ( UNICODE_ClockElement element : clockElementSecondSegmentsFirstColumn )
element.repaint ( );
for ( UNICODE_ClockElement element : clockElementSecondSegmentsSecondColumn )
element.repaint ( );

//refresh segment containers
for ( JPanel panel : segmentContainersA )
panel.repaint ( );
for ( JPanel panel : segmentContainersB )
panel.repaint ( );
for ( JPanel panel : segmentContainersC )
panel.repaint ( );

//refresh main container
segmentsContainer.repaint ( );

//refresh frame context
repaint ( );
}

public void resetColours ( Color value )
{
//reset colour
cleanSurfaces ( );
resetActiveColour ( value );
generateComponents ( );
refreshSurfaces ( );
}

public void generateComponents ( )
{
//subsidiary bases
//SEGMENT ZERO - HOURS
//ROW 0
for ( int i = 0; i < 4; i ++ )
clockElementHourSegmentsFirstColumn [ i ] = new UNICODE_ClockElement ( getHoursCreationState ( i ), decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

//ROW 1
for ( int i = 0; i < 4; i ++ )
clockElementHourSegmentsSecondColumn [ i ] = new UNICODE_ClockElement ( 0, decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

for ( int i = 0; i < 2; i ++ )
segmentContainersA [ i ] = new JPanel ( );

for ( int i = 3; i > -1; i -- )
{
segmentContainersA [ 0 ].add ( clockElementHourSegmentsFirstColumn [ i ] );
segmentContainersA [ 1 ].add ( clockElementHourSegmentsSecondColumn [ i ] );
}

for ( int i = 0; i < 2; i ++ )
{
segmentContainersA [ i ].setLayout ( new BoxLayout ( segmentContainersA [ i ], BoxLayout.Y_AXIS ) );
segmentContainersA [ i ].setBackground ( clockBaseContainerColour );
}

for ( int i = 0; i < 2; i ++ )
segmentContainersAContainer.add ( segmentContainersA [ i ] );

segmentContainersAContainer.setLayout ( new BoxLayout ( segmentContainersAContainer, BoxLayout.X_AXIS  ) );
segmentContainersAContainer.setBackground ( clockBaseContainerColour );

//SEGMENT ONE - MINUTES
//ROW 0
for ( int i = 0; i < 4; i ++ )
clockElementMinuteSegmentsFirstColumn [ i ] = new UNICODE_ClockElement ( getOtherCreationState ( i ), decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

//ROW 1
for ( int i = 0; i < 4; i ++ )
clockElementMinuteSegmentsSecondColumn [ i ] = new UNICODE_ClockElement ( 0, decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

for ( int i = 0; i < 2; i ++ )
segmentContainersB [ i ] = new JPanel ( );

for ( int i = 3; i > -1; i -- )
{
segmentContainersB [ 0 ].add ( clockElementMinuteSegmentsFirstColumn [ i ] );
segmentContainersB [ 1 ].add ( clockElementMinuteSegmentsSecondColumn [ i ] );
}

for ( int i = 0; i < 2; i ++ )
{
segmentContainersB [ i ].setLayout ( new BoxLayout ( segmentContainersB [ i ], BoxLayout.Y_AXIS ) );
segmentContainersB [ i ].setBackground ( clockBaseContainerColour );
}

for ( int i = 0; i < 2; i ++ )
segmentContainersBContainer.add ( segmentContainersB [ i ] );

segmentContainersBContainer.setLayout ( new BoxLayout ( segmentContainersBContainer, BoxLayout.X_AXIS  ) );
segmentContainersBContainer.setBackground ( clockBaseContainerColour );

//SEGMENT TWO - SECONDS
//ROW 0
for ( int i = 0; i < 4; i ++ )
clockElementSecondSegmentsFirstColumn [ i ] = new UNICODE_ClockElement ( getOtherCreationState ( i ), decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

//ROW 1
for ( int i = 0; i < 4; i ++ )
clockElementSecondSegmentsSecondColumn [ i ] = new UNICODE_ClockElement ( 0, decimalValues [ i ], this.clockElementEnabledColour, this.clockElementDisabledColour, this.clockElementBaseColour, 0, 0, clockElementSize );

for ( int i = 0; i < 2; i ++ )
segmentContainersC [ i ] = new JPanel ( );

for ( int i = 3; i > -1; i -- )
{
segmentContainersC [ 0 ].add ( clockElementSecondSegmentsFirstColumn [ i ] );
segmentContainersC [ 1 ].add ( clockElementSecondSegmentsSecondColumn [ i ] );
}

for ( int i = 0; i < 2; i ++ )
{
segmentContainersC [ i ].setLayout ( new BoxLayout ( segmentContainersC [ i ], BoxLayout.Y_AXIS ) );
segmentContainersC [ i ].setBackground ( clockBaseContainerColour );
}

for ( int i = 0; i < 2; i ++ )
segmentContainersCContainer.add ( segmentContainersC [ i ] );

segmentContainersCContainer.setLayout ( new BoxLayout ( segmentContainersCContainer, BoxLayout.X_AXIS  ) );
segmentContainersCContainer.setBackground ( clockBaseContainerColour );

//establish clockBaseContainer layout
segmentsContainer.setLayout ( new BoxLayout ( segmentsContainer, BoxLayout.X_AXIS ) );
segmentsContainer.setBackground ( clockBaseContainerColour );

//add clock base container to this panel

//initialise binaryClockDisplayComponent
binaryClockTimer.start ( );
}

//paint component
public void paintComponent ( Graphics graphics )
{
super.paintComponent ( graphics );
Graphics2D graphics2d = ( Graphics2D ) graphics;

//center it on frame
setLocation ( 0, bufferHeight / 2 - ( clockElementSize / 2 ) * 8 );
}

public String getElementsFromIntegerArray ( int [ ] integerArray )
{
String returnValue = "";

String delimiter = "";

for ( int i = 0; i < integerArray.length; i ++ )
{
if ( i == integerArray.length - 1 )
delimiter = "";
else
delimiter = ",";

returnValue += integerArray [ i ] + delimiter;
}

return returnValue;
}

public int getHoursCreationState ( int iterationIndex )
{
int returnValue = 0;

switch ( iterationIndex )
{
case 2: returnValue = -1; break;
case 3: returnValue = -1; break;
default: returnValue = 0; break;
}

return returnValue;
}

public int getOtherCreationState ( int iterationIndex )
{
int returnValue = 0;

switch ( iterationIndex )
{
case 3: returnValue = -1; break;
default: returnValue = 0; break;
}

return returnValue;
}

public Dictionary <Integer, int [ ]> getLoadedDictionary ( )
{
Dictionary <Integer, int [ ]> returnValue = new Hashtable <Integer, int [ ]> ( );

returnValue.put ( 0, new int [ ] { } );
returnValue.put ( 1, new int [ ] { 0 } );
returnValue.put ( 2, new int [ ] { 1 } );
returnValue.put ( 3, new int [ ] { 0, 1 } );
returnValue.put ( 4, new int [ ] { 2 } );
returnValue.put ( 5, new int [ ] { 0, 2 } );
returnValue.put ( 6, new int [ ] { 1, 2 } );
returnValue.put ( 7, new int [ ] { 0, 1, 2 } );
returnValue.put ( 8, new int [ ] { 3 } );
returnValue.put ( 9, new int [ ] { 0, 3 } );

return returnValue;
}

//conveniencePack
public void refreshColumn ( UNICODE_ClockElement [ ] clockElementCollection )
{
for ( int i = 0; i < clockElementCollection.length; i ++ )
if ( clockElementCollection [ i ].getState ( ) != -1 )
clockElementCollection [ i ].setState ( 0 );
}

public String evaluateColumn ( int digitValue, UNICODE_ClockElement [ ] clockElementCollection )
{
String returnValue = "";

if ( digitValue != 0 )
{
int [ ] targetIndices = binaryClockDigitalOutputVersusRequiredIndicesDictionary.get ( digitValue );

int targetIndicesTraversor = 0;
int cycleIndex = 0;
boolean cycleIndexEquivalenceEnquiry = ( cycleIndex == targetIndices [ targetIndicesTraversor ] );
int cycleIndexStep = 0;

//while the entire length of the collection has not yet been evaluated
while ( cycleIndex < clockElementCollection.length )
{
if ( !cycleIndexEquivalenceEnquiry )
{
//re-evaluate cycleIndexEquivalenceEnquiry, however increment cycleIndex by 1 to proceed cycling through clockElementCollection length
//first determine how the cycleIndex will be incremented
switch ( digitValue )
{
case 6: cycleIndexStep = cycleIndex + 1; break;
case 7: cycleIndexStep = cycleIndex + 1; break;
default: cycleIndexStep = cycleIndex += 1; break;
}
//then peform the actual re-evaluation.
//re-evaluation is another way of syaing I"m detemerming whether a match has been found, based on updated cycle index.
cycleIndexEquivalenceEnquiry = ( ( cycleIndexStep ) == targetIndices [ targetIndicesTraversor ] );

if ( cycleIndexEquivalenceEnquiry )
{
clockElementCollection [ targetIndices [ targetIndicesTraversor ] ].setState ( 1 );//set active wrt targetIndicesTraversor

if ( targetIndicesTraversor == targetIndices.length - 1 ) //is the last targetIndex yet reached?
cycleIndex = clockElementCollection.length; //if so end loop.
else
{
cycleIndex ++;
targetIndicesTraversor ++; //update targetIndicesTraversor to evaluate next targetIndex under next cycle
cycleIndexEquivalenceEnquiry = false; //reset cycleIndexEquivalenceEnquiry, so as to allow re-evaluation wrt to updated cycleIndex.
}
}
}
else if ( cycleIndexEquivalenceEnquiry )
{
clockElementCollection [ targetIndices [ targetIndicesTraversor ] ].setState ( 1 );//set active wrt targetIndicesTraversor

if ( targetIndicesTraversor == targetIndices.length - 1 ) //is the last targetIndex yet reached?
cycleIndex = clockElementCollection.length; //if so end loop.
else
{
targetIndicesTraversor ++; //update targetIndicesTraversor to evaluate next targetIndex under next cycle
cycleIndexEquivalenceEnquiry = false;
}
}
}
}

return returnValue;
}

private class binaryClockActionListening implements ActionListener
{
public void actionPerformed ( ActionEvent actionEvent )
{
//refresh columns
//refresh hours segment
//refresh first column
refreshColumn ( clockElementHourSegmentsFirstColumn );
//refresh second column
refreshColumn ( clockElementHourSegmentsSecondColumn );
//refresh minutes segment
//refresh first column
refreshColumn ( clockElementMinuteSegmentsFirstColumn );
//refresh second column
refreshColumn ( clockElementMinuteSegmentsSecondColumn );
//refresh seconds segment
//refresh first column
refreshColumn ( clockElementSecondSegmentsFirstColumn );
//refresh second column
refreshColumn ( clockElementSecondSegmentsSecondColumn );

//evaluate all columns wrt to java date/time via system time.
//evaluate hours segment
//evaluate first column
evaluateColumn ( new UNICODE_DateCreator ( ).getHoursDigits ( ) [ 0 ], clockElementHourSegmentsFirstColumn );
//evaluate second column
evaluateColumn ( new UNICODE_DateCreator ( ).getHoursDigits ( ) [ 1 ], clockElementHourSegmentsSecondColumn );
//evaluate minutes segment
//evaluate first column
evaluateColumn ( new UNICODE_DateCreator ( ).getMinutesDigits ( ) [ 0 ], clockElementMinuteSegmentsFirstColumn );
//evaluate second column
evaluateColumn ( new UNICODE_DateCreator ( ).getMinutesDigits ( ) [ 1 ], clockElementMinuteSegmentsSecondColumn );
//evaluate seconds segment
//evaluate first column
evaluateColumn ( new UNICODE_DateCreator ( ).getSecondsDigits ( ) [ 0 ], clockElementSecondSegmentsFirstColumn );
//evaluate second column
evaluateColumn ( new UNICODE_DateCreator ( ).getSecondsDigits ( ) [ 1 ], clockElementSecondSegmentsSecondColumn );
repaint ( );
}
}
}
```

And a bonus, a Java frame, with the binary clock already in use:

```

//~Author: Jordan Micah Bennett
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Color;

public class UniCodeBinaryClock_DisplayConsole
{
public static void main ( String [ ] argv )
{
//create buffr dimension vars
int bufferWidth = 200, bufferHeight = 200;

//create java frame
JFrame frame = new JFrame ( "binary clock sample" );

//set up close strategy, and setup dimension (size)
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
frame.setPreferredSize ( new Dimension ( bufferWidth, bufferHeight ) );

//create binary clock object
UNICODE_BinaryClock binaryClock = new UNICODE_BinaryClock ( bufferHeight, new  Color ( 238, 238, 238 ), new  Color ( 238, 238, 238 ), Color.red, Color.lightGray, 1, 8, Color.white );

//setup frame orientation (location)
frame.setLocation ( ( int ) ( java.awt.Toolkit.getDefaultToolkit ( ).getScreenSize ( ).getWidth ( )/2 - bufferWidth/2 ), ( int ) ( java.awt.Toolkit.getDefaultToolkit ( ).getScreenSize ( ).getHeight ( )/2 - bufferHeight/2 ) );

//complete frame setup
frame.setUndecorated ( true );
frame.getRootPane ( ).setWindowDecorationStyle ( 4 );
frame.pack ( );
frame.setVisible ( true );
}
}
```

When you run the frame, you should see:

• 0

I wish nothing for myself; I wish solely that this consumptive existence is realigned... Such is perhaps attainable with science an technology... If cosmological constants yielded an energy transference bounded universe, by modus ponens, it perhaps follows that such constants are affixable... This universe is but a program whose underlying construct is starkly outdated....

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download