Note that there are some explanatory texts on larger screens.

plurals
  1. POFlipping shape (not image)
    text
    copied!<p><strong>Solved:</strong> Thanks @MadProgrammer</p> <p>I replaced <code>g2.rotate(Math.toRadians(180.0));</code> by <code>g2.scale(1, -1);</code> thanks^^</p> <hr> <p>I wrote program to show Digital Clock with mirror (Vertical Flip)</p> <p>This is my code</p> <pre><code> import java.awt.*; import java.awt.font.GlyphVector; import javax.swing.*; import java.util.*; public class DigitalClock extends JFrame implements Runnable { /** * @author HASSAN */ Thread runner; // declare global objects Font clockFont; Shape mirror; public DigitalClock() { super("Digital Clock - Hassan Sharaf 12MCMB33"); setSize(600, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setResizable(false); // create window setLocationRelativeTo(null); clockFont = new Font("digifacewide", Font.BOLD, 100); // create font Container contentArea = getContentPane(); ClockPanel timeDisplay = new ClockPanel(); contentArea.add(timeDisplay); // add components setContentPane(contentArea); start(); // start thread running } public class ClockPanel extends JPanel { public void paintComponent(Graphics painter) { // super.paintComponent(painter); Graphics2D g2 = (Graphics2D) painter; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setFont(clockFont); // create clock components g2.setColor(Color.black); g2.drawString(timeNow(), 20, 140); GlyphVector v = clockFont.createGlyphVector(getFontMetrics(clockFont).getFontRenderContext(), timeNow()); mirror = v.getOutline(); g2.translate(553, 160); g2.rotate(Math.toRadians(180.0)); g2.fill(mirror); g2.draw(mirror); } } // get current time public String timeNow() { Calendar now = Calendar.getInstance(); int hrs = now.get(Calendar.HOUR_OF_DAY); int min = now.get(Calendar.MINUTE); int sec = now.get(Calendar.SECOND); String time = zero(hrs) + ":" + zero(min) + ":" + zero(sec); return time; } public String zero(int num) { String number = (num &lt; 10) ? ("0" + num) : ("" + num); return number; // Add leading zero if needed } public void start() { if (runner == null) { runner = new Thread(this); } runner.start(); // method to start thread } public void run() { while (runner == Thread.currentThread()) { repaint(); // define thread task try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Thread failed"); } } } // create main method public static void main(String[] args) { DigitalClock clock = new DigitalClock(); } } </code></pre> <p><strong>Problem:</strong> I used rotate() method, but actually I don't want rotate the clock I want flip it vertically <strong>Question:</strong> How can I flip the shape <strong>(not image)</strong>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload