GoXR3Plus GoXR3Plus - 1 year ago 79
Java Question

Reflecting text in java

I am trying to make a digital clock in this way:

As shown in the image 1 i want the clock to be reflected.

enter image description here

What i have tried:
I tried using java (Graphics2D)g by rotating the string and the using substring but i got this problem:

enter image description here

My code for this:

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Calendar;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class DigitalClock extends JPanel {

JLabel label = new JLabel();
int c = 0;
Font font = null;
JFrame frame = new JFrame();

public DigitalClock(){




//Paint Method
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D)g;

//The background

//Show Time
g2d.setFont(new Font(g.getFont().toString(),10,15));
g2d.drawString(timeNow(),100, 25);

//Show time Reflected
g2d.drawString(timeNowRot(timeNow()),45, 20);


//Change time Value with this Thread
public void DigitalThread(){

new Thread(new Runnable(){
public void run(){

boolean flag=true;
try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}



//Return time
public String timeNow(){

return zero(Calendar.getInstance().get(Calendar.HOUR_OF_DAY))+":"+

//Return time reflected
public String timeNowRot(String time){

return time.substring(time.length()-1,time.length())+time.substring(time.length()-2,time.length()-1)+":";

//Add Zero if value<10
public String zero(int num){
if(num<10) return "0"+num;
else return ""+num;


I can achieve this by using java 2d? is there a method to rotate a string again vertically so i have not this problem thanks..

Answer Source

Actually i found the answer based n your answers thanks all:

It is and irony but the next day after the question i had a lesson at university about that...

Info about scaling:

 g2d.scale(1,-1);  /*scale  by y axes(Flipping vertical
                                    flip here (scale(-1,1) ) |   here it was
                                                    _ _ _ _ _|_ _ _ _ _
                                   flip here (scale(-1,-1) ) |   fliped here( scale(1,-1) )

I also added some more effect so the clock be more realistic like:

 g2d.setPaint(new GradientPaint(0,-15,color,0,-50,Color.BLACK));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download