60 seconds to Spring (1)

原文地址:http://gabriel.jarchitect.org/spring/index.html

60 sec to Spring [TOC]

ruler.gif

Bean Tutorial 1 - Hello World Bean

This tutorial show you how to call a Hello World Bean using Spring IoC.

Step 1: Create a HelloBean.java in src

org/jarchitect/spring/tutorial1/HelloBean.java

Step 2: Specify the HelloBean class in the bean.xml

bean.xml

   

Step 3: Create a Main.java in src

org/jarchitect/spring/tutorial1/Main.java

                                                 }

Step 4: Use an ANT script to build and execute the Main class. Just run ant from the command prompt will do the trick.

Below are the output from ANT.

         



 

Done.

[TOC]

阅读更多

请问(seconds - 15) / 60 * 2 * Math.PI;和2 * Math.PI*(seconds - 15) / 60有区别吗?

04-10

import java.awt.*;rnimport javax.swing.*;rnimport java.awt.event.*;rnimport java.util.*;rnimport javax.swing.Timer;rnimport java.awt.geom.*;rnrnpublic class TimerTest extends JFrame rnrn public static void main(String[] args) rn TimerTest timer = new TimerTest();rn timer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn timer.setVisible(true);rn rnrn public TimerTest() rn setTitle("定时器");rn setSize(450, 300);rn Container cp = getContentPane();rn cp.setLayout(new GridLayout(2, 3));rn cp.add(new TimerCanvas("America/Los_Angeles"));rn cp.add(new TimerCanvas("America/New_York"));rn cp.add(new TimerCanvas("America/Caracas"));rn cp.add(new TimerCanvas("Europe/Rome"));rn cp.add(new TimerCanvas("Africa/Cairo"));rn cp.add(new TimerCanvas("Asia/Taipei"));rnrn rnrnrnrnclass TimerCanvas extends JPanel rn public TimerCanvas(String tz) rn zone = tz;rn calendar = new GregorianCalendar(TimeZone.getTimeZone(tz));rn Timer t = new Timer(1000, new ActionListener() rn public void actionPerformed(ActionEvent event) rn calendar.setTime(new Date());rn repaint();rn rn );rn t.start();rn setSize(100, 120);rnrn rnrn public void paintComponent(Graphics g) rn super.paintComponent(g);rn Graphics2D g2 = (Graphics2D) g;rn g2.draw(new Ellipse2D.Double(0, 0, 100, 100));rnrn int seconds = calendar.get(Calendar.SECOND)rn + calendar.get(Calendar.HOUR) * 60 * 60rn + calendar.get(Calendar.MINUTE) * 60;rn double hourAngle = (seconds - 3 * 60 * 60) / (12 * 60 * 60) * 2rn * Math.PI;rn double minuteAngle = (seconds - 15 * 60) / (60 * 60) * 2 * Math.PI;rn double secondAngle = (seconds - 15) / 60 * 2 * Math.PI;rn g2.draw(new Line2D.Double(50, 50, 50 + 20 * Math.cos(hourAngle),rn 50 + 20 * Math.sin(hourAngle)));rn g2.draw(new Line2D.Double(50, 50, 50 + 30 * Math.cos(minuteAngle),rn 50 + 30 * Math.sin(minuteAngle)));rn g2.draw(new Line2D.Double(50, 50, 50 + 40 * Math.cos(secondAngle),rn 50 + 40 * Math.sin(secondAngle)));rn g2.drawString(zone, 0, 110);rn rnrn private GregorianCalendar calendar;rnrn private String zone;rnrnrn在此程序中将double hourAngle = (seconds - 3 * 60 * 60) / (12 * 60 * 60) * 2rn * Math.PI;rn double minuteAngle = (seconds - 15 * 60) / (60 * 60) * 2 * Math.PI;rn double secondAngle = (seconds - 15) / 60 * 2 * Math.PI;rn换成这double hourAngle = 2 * Math.PIrn * (seconds - 3 * 60 * 60) / (12 * 60 * 60);rn double minuteAngle = 2 * Math.PIrn * (seconds - 15 * 60) / (60 * 60);rn double secondAngle = 2 * Math.PIrn * (seconds - 15) / 60;rn就可以阿

没有更多推荐了,返回首页