栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

我该如何打勾?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

我该如何打勾?

这个例子]非常好用…

public class TestClock {    public static void main(String[] args) {        new TestClock();    }    public TestClock() {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     try {         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());     } catch (ClassNotFoundException ex) {     } catch (InstantiationException ex) {     } catch (IllegalAccessException ex) {     } catch (UnsupportedLookAndFeelException ex) {     }     Jframe frame = new Jframe();     frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);     frame.setLayout(new BorderLayout());     frame.add(new ClockPane());     frame.pack();     frame.setLocationRelativeTo(null);     frame.setVisible(true); }        });    }    protected class ClockPane extends JPanel {        public ClockPane() { Timer timer = new Timer(1000, new ActionListener() {     @Override     public void actionPerformed(ActionEvent e) {         repaint();     } }); timer.setRepeats(true); timer.setCoalesce(false); timer.start();        }        @Override        public Dimension getPreferredSize() { return new Dimension(200, 200);        }        protected Point getPointTo(float angle) { int x = Math.round(getWidth() / 2); int y = Math.round(getHeight() / 2); double rads = Math.toRadians(angle); // This is an arbitrary amount, you will need to correct for this // I'm working of a width of 200 pixels, so that makes the radius // 100... int radius = 100; // Calculate the outter point of the line int xPosy = Math.round((float) (x + Math.cos(rads) * radius)); int yPosy = Math.round((float) (y - Math.sin(rads) * radius)); return new Point(xPosy, yPosy);        }        @Override        protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); Calendar cal = Calendar.getInstance(); int seconds = cal.get(Calendar.SECOND); float angle = -(360f * (seconds / 60f)); angle += 90; // Correct for 0 being out to the right instead of up Point p = getPointTo(angle); int x = getWidth() / 2; int y = getHeight() / 2; g2d.drawLine(x, y, p.x, p.y); FontMetrics fm = g2d.getFontMetrics(); String text = Integer.toString(seconds); g2d.drawString(text, getWidth() - fm.stringWidth(text), getHeight() - fm.getHeight() + fm.getAscent()); g2d.dispose();        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/440780.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号