Using java.math

Hey guys,
I've got yet another question !
I want to the math.floor to round my double numbers down.
I've declared "import java.math.*;" at the very start
but how do you use math.floot actually?
I've put
double number = 1.25
double roundednumber = math.floor(number);
but it cannot find symbol math...I did something wrrong...

Hey guys,
I've got yet another question !
I want to the math.floor to round my double numbers down.
I've declared "import java.math.*;" at the very start
but how do you use math.floot actually?
I've put
double number = 1.25
double roundednumber = math.floor(number);
but it cannot find symbol math...I did something
wrrong...As Jos already pointed out: it's with a capital M.
Note that the Math class is not in the java.math package but in the java.lang package which is automatically imported.
This is the java.math package:
http://java.sun.com/j2se/1.5.0/docs/api/java/math/package-summary.html
And this is the java.lang.Math class:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html

Similar Messages

  • Simple integer generation  using java math classes

    I want to generate a integer which should be combination of 2 integer and one int
    and anytime I call generate it should generate same value for same input and for different combinations it should generate different value.
    for example I passed to the service two integers 24, 25 and one int 76
    assume it generated 242576
    I restart jvm to the service pass the same values mentioned above it should return me same output 242576.
    I want to do this using some math functionality not using string concatinating ?Any suggestions on acheiving this? any help is greatly appreciated.
    miro

    How would you arrive at 242576 from 24, 25 and 76 when performing the operation by hand, on paper? What calculations would you need to perform?
    Your other requirements are standard properties of programming: unless you go out of your way to make it otherwise, methods/functions tend to produce the same output based on the same input.
    BTW, you won't need any math classes for this, just mathematical operators like +, -, *, / etc.

  • Using java math class  for power's SQ rt and rounding.

    Hey all
    ive attempted to use maths class to create a program a user can enter a number and then the output shows
    The number rounded to the nearest integer
    The Square root of the number
    and finaly the number to the power of 6
    So far i have the following code but im a bit thick to what im missing ....
    import java.util.*;
    public class Mathclass
         public static void main(String[] args)
         Scanner kybd = new Scanner(System.in);
         double num = kybd.nextInt(); // kybd is an instance of Scanner
         public static double ceil (double num);
         public static double sqrt (double num);
         public static double exp (double num);
    }}Please be kind i know the outputs arnt there yet but im getting 15 errors in javac
    Thankyou

    Javaman01 wrote:
    i can understand that you feel this way , i just have a lot of programs i need to complete for a portfolio tommorow , so i need all the help i can get.Well, then I guess you started too late. Talk to your teacher that you won't be able to get it done on your own. Start learning your course book or the basic tutorials I posted and try to do the assignments again. I really think you know too little to get this done.
    Javaman01 wrote:
    if you wish not to help the please dont comment as i fear this will put others of helping me when i need it most.I did help you! And you have nothing to say about me posting here or not. Just as I can't stop you from trying to get others to do your homework.
    Javaman01 wrote:
    thankyouYou're welcome.

  • Cannot use Java Mail in Oracle 8i

    I have loaded Sun's API Java Mail (and Java Activator) into
    an Oracle 8.1.5 server running on a Windows NT 4.0 server.
    I have also created a small Java-application that tries to
    send emails. The application is stored in database as a stored
    procedure.
    However, when I try to send a mail through my stored procedure
    I get the message:
    'ORA-01041 internal error. hostdef extension doesn't exist'
    followed by an end-of-channel error.
    It works fine when I run my Java-program stand-alone, without
    any database involved.
    I need some help with this one...
    Regards,
    Lars-Eric
    null

    I got the Java Embedding Activity working...,I used the following imports in my BPEL....
    <bpelx:exec import="java.util.logging.Logger"/>
    <bpelx:exec import="java.util.logging.Level"/>
    <bpelx:exec import="oracle.fabric.logging.LogFormatter"/>
    <bpelx:exec import="org.w3c.dom.*"/>
    <bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>
    <bpelx:exec import="java.util.*"/>
    <bpelx:exec import="java.lang.*"/>
    <bpelx:exec import="java.math.*"/>
    <bpelx:exec import="java.io.*"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
    Hope this helps anyone who have been struggling like me before...
    Thanks,
    N

  • Cast to a literal (ex. "java.math.BigDecimal")

    I have an array with 2 columns like:
    "java.math.BigDecimal", "2"
    "java.lang.String", "Test 01"
    "java.math.BigDecimal","120"
    "java.math.BigDecimal","148"
    "java.lang.String", "Test 02"
    Is there way to cast the second string to the correct object type, using the first string.
    Something like this:
    ("java.math.BigDecimal")("2")
    ("java.lang.String")("Test 01")
    thanks in advance,
    intovoid

    You could do this by reflection for classes which
    have a contructor which takes an single string
    parameter - which I believe all these classes do.
    Lot's of messy expections to field. The sequence
    would be something like:
    private static Object create(String[] columns) throws
    Exception {
    Class clazz = Class.forName(columns[0]);  // get
    the class
    Contstructor cons = clazz.getConstructor(new
    Class[]{String.class}); // get constructor from
    String
    return cons.newInstance(new Object[]{columns[1]});
    // construct object
    code]Except, the problem remains that the OP can still not cast the Object returned by newInstance() by using the String in columns[0] (even though the Object is a BigDecimal). Even if it could be cast "dynamically", what would it be cast into - you can not dynamically declare the variable type.
    The above method could work if all the possible objects returned implemented a common interface. Or maybe instanceof could be used to hard-code the cast to the possible objects.
    In the end, I think this type of code can lead to a brittle design.

  • Java.math package does not exist!!!

    hi java experts, i really desperately need some help. ihave been trying to compile a java program i have written that imports the java.math package as i am using the BigInteger class. I am using SUN ONE STUDIO ME 4 and have j2se SDk installed. when i try to build the program in the IDE, it gives me an error message saying the java.math package does not exist. i can't understand why. i think it's an IDE problem. i tried mounting the filesystem and i mounted almost a million times in diff ways but it still can't compile. i can't find the directory of the java.math to mount into. anyway i tried to compile it at the command prompt and it can compile but with errors... so i figure that i do have the java.math class on my system just that the IDE jsut can't recognise it. i am at my wits end and gonna go mad if someone doesn't please help me.
    adeline from singapore

    Cross-posted at http://forum.java.sun.com/thread.jsp?thread=293132&forum=54&message=1155073

  • Getting  Error: SCAC-50012 while using Java Embeding Activity

    Hi,
    I am using Jdeveloper 11.1.1.4.0 . I am using a Java Embedding Activity in my BPEL and when i compile the project, i got one error------Error: SCAC-50012
    The code i am using in Java Embedding activity is
    java.lang.String TraceLogMessage = null;
         java.lang.Boolean tracelogenabled;
    java.lang.String title = (java.lang.String)getVariableData("Title");
    java.lang.String instanceID = (java.lang.String)getVariableData("InstanceID");
    java.lang.String serviceName = (java.lang.String)getVariableData("ServiceName");
    tracelogenabled = oracle.apps.aia.core.eh.logging.AIALogger.isTraceLoggingEnabled("INFO","http://xmlns.oracle.com/ExecuteSalesOrderFulfillmentDeviceUpdateEBF");
    setVariableData("TraceLogEnabled", tracelogenabled);
    if (tracelogenabled.booleanValue())
    TraceLogMessage = "Starting " + serviceName + " Instance: " + instanceID + title; ;
    oracle.apps.aia.core.eh.logging.AIALogger.logTraceMessage("INFO", null ,TraceLogMessage);
    i have imported the following in bpel but there is no luck........
    <bpelx:exec import="java.util.logging.Logger"/>
    <bpelx:exec import="java.util.logging.Level"/>
    <bpelx:exec import="oracle.fabric.logging.LogFormatter"/>
    <bpelx:exec import="org.w3c.dom.*"/>
    <bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>
    <bpelx:exec import="java.util.*"/>
    <bpelx:exec import="java.lang.*"/>
    <bpelx:exec import="java.math.*"/>
    <bpelx:exec import="java.io.*"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
    Please help me with this......
    Thanks&Regards,
    suman

    Hi Lara,
    Thanks for the responce.......
    I checked the scac log file it contains the following code.
    ---------------------------------------------- scac logfile ----------------------------------------------------
    Mar 15, 2012 5:32:18 PM com.collaxa.cube.CubeLogger info
    INFO: validating "BPELProcess1.bpel" ...
    oracle.jrf.UnknownPlatformException: JRF is unable to determine the current application server platform.
         at oracle.jrf.ServerPlatformSupportFactory.getInstance(ServerPlatformSupportFactory.java:79)
         at oracle.integration.platform.blocks.WLSPlatformConfigurationProvider.<clinit>(WLSPlatformConfigurationProvider.java:44)
         at oracle.integration.platform.blocks.FabricConfigManager.<clinit>(FabricConfigManager.java:154)
         at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.loadXpathFunctions(FabricXPathFunctionResolver.java:282)
         at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.loadXPathConfigFile(FabricXPathFunctionResolver.java:156)
         at oracle.integration.platform.blocks.xpath.FabricXPathFunctionResolver.init(FabricXPathFunctionResolver.java:49)
         at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.loadFabricXpathFunctions(BPELXPathFunctionNameResolver.java:57)
         at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.<init>(BPELXPathFunctionNameResolver.java:48)
         at com.collaxa.cube.xml.xpath.BPELXPathFunctionNameResolver.<clinit>(BPELXPathFunctionNameResolver.java:44)
         at com.collaxa.cube.lang.compiler.bpel.XPathExprValidatorVisitor.<init>(XPathExprValidatorVisitor.java:122)
         at com.collaxa.cube.lang.compiler.bpel.AssignValidator.<init>(AssignValidator.java:89)
         at com.collaxa.cube.lang.compiler.bpel.BpelParser.<init>(BpelParser.java:452)
         at com.collaxa.cube.lang.compiler.bpel.BPELValidator.validate(BPELValidator.java:60)
         at com.collaxa.cube.lang.compiler.BPEL1Processor.validate(BPEL1Processor.java:329)
         at com.collaxa.cube.lang.compiler.BPEL1Processor.process(BPEL1Processor.java:153)
         at com.collaxa.cube.lang.compiler.CubeParserHelper.compile(CubeParserHelper.java:47)
         at oracle.fabric.bpel.bpelc.BPELComponentValidator.validate(BPELComponentValidator.java:40)
         at oracle.soa.scac.ValidateComposite.validateComponentTypeServicesReferences(ValidateComposite.java:1117)
         at oracle.soa.scac.ValidateComposite.doValidation(ValidateComposite.java:500)
         at oracle.soa.scac.ValidateComposite.run(ValidateComposite.java:150)
         at oracle.soa.scac.ValidateComposite.main(ValidateComposite.java:135)
    Mar 15, 2012 5:32:23 PM CubeProcessGenerator compile
    WARNING: classpath is: D:\Oracle\Middleware\jdeveloper\jdev\extensions\oracle.sca.modeler.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.mediator_11.1.1\mediator_client.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.mds_11.1.1\mdsrt.jar;;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\classes;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\classes;C:\JDeveloper\mywork\sampleApplication\JavaEmbed\SCA-INF\gen-classes;D:\Oracle\Middleware\oracle_common\modules\commonj.sdo_2.1.0.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.fabriccommon_11.1.1\fabric-common.jar;D:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpel1-1-xbeans.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-common.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpel_coherence_config.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-exts.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\thirdparty.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\bpm-analytics.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-thirdparty.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\wsif-binding.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\orabpel-validator.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\monitor-rt-xbean.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.bpel_11.1.1\oracle.soa.bpmn.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\user-patch.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.thirdparty.jar;D:\Oracle\Middleware\jdeveloper\uddi\lib\oracle.soa.uddi.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\bpm-infra.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\testfwk-xbeans.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-ext.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-infra-scheduler.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\xmlunit-1.1.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-infra-tools.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\soa-xpath-exts.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle-soa-client-api.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.wls.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-client.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime-ext-was.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime-ext-wls.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\oracle.soa.fabric.jar;D:\Oracle\Middleware\jdeveloper\soa\modules\oracle.soa.ext_11.1.1\classes;D:\Oracle\Middleware\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1\soa-infra-mgmt.jar
    Please help me how can i solve this issue.
    Thanks&Regards,
    Suman

  • Package java.math does not exist!!!

    hi java experts, i really desperately need some help. ihave been trying to compile a java program i have written that imports the java.math package as i am using the BigInteger class. I am using SUN ONE STUDIO ME 4 and have j2se SDk installed. when i try to build the program in the IDE, it gives me an error message saying the java.math package does not exist. i can't understand why. i think it's an IDE problem. i tried mounting the filesystem and i mounted almost a million times in diff ways but it still can't compile. i can't find the directory of the java.math to mount into. anyway i tried to compile it at the command prompt and it can compile but with errors... so i figure that i do have the java.math class on my system just that the IDE jsut can't recognise it. i am at my wits end and gonna go mad if someone doesn't please help me.
    adeline from singapore

    java.math package will be there in jdk_dir\jre\lib\rt.jar. You need to set the classpath variable in your IDE for this jar file. There must be some means to edit the IDE's classpath variable.
    i mounted almost a million times in diff ways but it still can't compileIf it takes one minute for each mount then total time you have taken = 10000000 minutes = 166666 hours = 6944 days = 19 years (roughly). Java was not there 19 years ago.
    Sudha

  • Cannot use "java:" prefix in Context.lookup()

    I have observed a NullPointer exception when the "java:" prefix
    is used during a JNDI lookup with WL 5.1.0 Service Pack 4 on WinNT.
    Context ctx = new InitialContext();
    Object obj = ctx.lookup("java:comp/env/ejb/BeanHome");
    The work-around of removing the "java:" prefix works fine:
    Object obj = ctx.lookup("comp/env/ejb/BeanHome");
    The "java:" prefix is suggested in the EJB 1.1 specification.
    Here is the exception's stack trace:
    java.lang.NullPointerException:
         at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:29)
         at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:117)
         at javax.naming.InitialContext.lookup(InitialContext.java:349)
         at com.foodcompliance.servlet.Library.getLibraryManager(Library.java)
         at com.foodcompliance.servlet.Library.doGet(Library.java, Compiled Code)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:124)
         at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:744)
         at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:692)
         at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
         at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:363)
         at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:263)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)

    I got the Java Embedding Activity working...,I used the following imports in my BPEL....
    <bpelx:exec import="java.util.logging.Logger"/>
    <bpelx:exec import="java.util.logging.Level"/>
    <bpelx:exec import="oracle.fabric.logging.LogFormatter"/>
    <bpelx:exec import="org.w3c.dom.*"/>
    <bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>
    <bpelx:exec import="java.util.*"/>
    <bpelx:exec import="java.lang.*"/>
    <bpelx:exec import="java.math.*"/>
    <bpelx:exec import="java.io.*"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
    Hope this helps anyone who have been struggling like me before...
    Thanks,
    N

  • Cannot use Java Embedding in Jdeveloper 11.4

    Hi,
    I am using Jdeveloper 11.1.1.4.0 . I am using a Java Embedding Activity in my BPEL and when i compile the project, the error which is coming is SCAC 50012. The same is working in 11.1.1.3.0 Jdeveloper Version.
    The code i am using in Java Embedding activity is
    Logger logger = Logger.getLogger("oracle.soa.Logger");
    LogFormatter.configFormatter(logger);     
    String var1 = ((oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input")).getFirstChild().getNodeValue();
    logger.info("Message from Logging level:Info"+var1 );
    Please help me with this...
    Thanks,
    N
    Edited by: Naresh on Jul 13, 2011 10:47 AM

    I got the Java Embedding Activity working...,I used the following imports in my BPEL....
    <bpelx:exec import="java.util.logging.Logger"/>
    <bpelx:exec import="java.util.logging.Level"/>
    <bpelx:exec import="oracle.fabric.logging.LogFormatter"/>
    <bpelx:exec import="org.w3c.dom.*"/>
    <bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>
    <bpelx:exec import="java.util.*"/>
    <bpelx:exec import="java.lang.*"/>
    <bpelx:exec import="java.math.*"/>
    <bpelx:exec import="java.io.*"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
    Hope this helps anyone who have been struggling like me before...
    Thanks,
    N

  • Access database using Java from HTML webpage

    Hi,
    I've got to create some online maths tests to be taken by students with their marks being stored in a database.
    I've wrote some simple java code which can add/remove and modify entries in a test mySQL database that I made. What I now need to do is be able to add entries to the database from a html page.
    The math tests will be java applets with the students having to interact according to questions, press submit and their score will be output. The score will then be entered into the database.
    The problem I'm having is that with an Applet their are all sorts of security issues (I'm having problems getting images to load in an Applet) so assume I'll face the same security issues when I try to access a database through an applet.
    So, could someone please help get started.
    Cheers

    MVC - I assume you mean model-view-control and not Marvel vs Capcom :)
    If so then does this mean I should completely seperate the user interface (the actual applets that will contain the test), the database (that will store the results) and the link between the two?
    is it possible to acheive this using Java, Java Applets, Java Script and the database (in my case mySQL) and could you give me some tips on how best to tackle the problem.
    Thanks

  • NUMBER - java.math.BigDecimal

    Dear JDBC writer,
    When I have done a query in my Java program on a table in an Oracle database with a NUMBER or NUMBER(4) or NUMBER(4,2) column,
    and I use the generic method ResultSet.getObject(int column), the method always returns a java.math.BigDecimal instance.
    1. In case of NUMBER(4) I had suspected a java.lang.Integer instance. In case of NUMBER I had suspected a java.lang.Double instance. Why did you return a java.math.BigDecimal instance?
    2. Was it your intention to do further calculations with the BigDecimal instance or should I check the precision and scale of the column and get the int or double out of the BigDecimal instance?

    Thanks for the tip about getNUMBER, that may help with some of my other problems, but I'm trying to get data out of oracle spatial geometry types, and both integers and floats are stored in arrays of numbers. If you do a getarray on these or even process them as a result set, you get bigdecimals. How could I do the equivalent of getNUMBER for an array type? This is a huge performance problem for Oracle spatial and java.

  • Alarm Clock using Java 2D

    Hey Guys,
    I have built an analog clock in java using swing and gregorian calender. Now my professor wants me to add an alarm functionality to it. Any ideas of how to implement this into the already existing code. The folllowing is the code i have written so far..everything works except i dont know how to implement the alarm functionality. Assistance needed ASAP, as its due by this wednesday!!
    /** Analog Clock using Java Graphics 2D Component */
    import java.awt.*;
    import java.awt.Graphics2D;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    /** Built on JPanel..Used class Timer for repeatedly executing
    the clocktimer thread/
    public class AnalogClock extends JPanel
    ImageIcon img;
    private GregorianCalendar m_calendar;
    private int[] x=new int[2];
    private int[] y=new int[2];
    private java.util.Timer clocktimer=new java.util.Timer();
    /**You could set the TimeZone for the clock here. I used the Dfault time
    zone from the user so that every time the program runs on different
    computers the correct time is displayed*/
    private TimeZone clockTimeZone=TimeZone.getDefault();
    //Constructor
    public AnalogClock()
    this.setPreferredSize(new Dimension(210,210));
    this.setMinimumSize(new Dimension(210,210));
    //schedules the clocktimer task to scan for every 1000ms=1sec
    clocktimer.schedule(new TickTimerTask(),0,1000);
    //The Clock Face instance method
    public void paint(Graphics g)
    g.setColor(Color.orange);
    g.fillRect(0,0,this.getWidth(),this.getHeight());
    drawCardinals((Graphics2D)g);
    drawHands((Graphics2D)g);
    //Endpoints of the Clock Hand
    void clockMinutes(int startRadius,int endRadius,double theta)
    theta-=Math.PI/2;
    x[0]=(int)(getWidth()/2+startRadius*Math.cos(theta));
    y[0]=(int)(getHeight()/2+startRadius*Math.sin(theta));
    x[1]=(int)(getWidth()/2+endRadius*Math.cos(theta));
    y[1]=(int)(getHeight()/2+endRadius*Math.sin(theta));
    //The Hours/Cardinals of the clock
    /** Set Stroke sets the thickness of the cardinals and hands*/
    void drawCardinals(Graphics2D g)
    g.setStroke(new BasicStroke(9));
    g.setColor(Color.black);
    for(double theta=0;theta<Math.PI*2;theta+=Math.PI/6)
    clockMinutes(100,100,theta);
    /**Draws a sequence of connected lines defined by arrays of x and
    *y coordinates. Each pair of (x, y) coordinates defines a point.
    *The figure is not closed if the first point
    differs from the last point./
    g.drawPolyline(x,y,2);
    //The Hand of the Clocks instance method
    public void drawHands(Graphics2D g)
    double h=2*Math.PI*(m_calendar.get(Calendar.HOUR));
    double m=2*Math.PI*(m_calendar.get(Calendar.MINUTE));
    double s=2*Math.PI*(m_calendar.get(Calendar.SECOND));
    g.setStroke(new BasicStroke(9));
    clockMinutes(0,55,h/12+m/(60*12));
    g.setColor(Color.red);
    g.drawPolyline(x,y,2);
    clockMinutes(0,70,m/60+s/(60*60));
    g.setColor(Color.blue);
    g.drawPolyline(x,y,2);
    clockMinutes(0,70,s/60);
    g.setColor(Color.black);
    g.drawPolyline(x,y,2);
    g.fillOval(getWidth()/2-8,getHeight()/2-8,16,16);
    //method to update/refresh the clock every second
    class TickTimerTask extends TimerTask
    public void run()
    m_calendar=(GregorianCalendar)GregorianCalendar.getInstance(clockTimeZone);
    repaint();
    The Main File is below:
    import javax.swing.JFrame;
    import java.awt.Toolkit;
    public class AnalogClockView extends JFrame
    public static void main(String[] args)
    JFrame frame = new JFrame();
    frame.setSize(300, 400);
    frame.setTitle("My Java Project Clock");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("Clock.gif"));
    AnalogClock m_AnalogClock=new AnalogClock();
    frame.add(m_AnalogClock);
    frame.setVisible(true);
    Edited by: sIrIUs_bLAcK on Aug 31, 2008 11:17 PM

    some items unrelated to your main question:
    *) When drawing in JPanels and other JComponents, you should override paintComponent, not paint. Also, the first method in this override should be super.paintComponent(g). This will refresh your screen and will eliminate the need for your having to fill the rectangle with a color on each iteration of paintComponent. You'll have to call setBackground(Color c) on your drawing JPanel somewhere in the initialization code though.
    *) If you're using a Timer with Swing apps, consider using a Swing Timer. It works well and has the added convenience of having all code in it's actionlistener called on the event dispatch thread, the main Swing thread.
    *) Finally, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}Edited by: Encephalopathic on Aug 31, 2008 5:29 PM

  • Why do u use JAVA ? :-)

    Hello All,
    Please tell me your reasons of using Java if you know in advance that your application will run under specific OS.
    Thanks

    Oh yeah, and it's a great language to teach folks object-oriented techniques. It helps get them in the mindset of things being objects that communicate through methods. That is, of course, unless you want to add two Integer instances together... :)
    Dan
    Being a Smalltalk developer, it's a much nicer
    language than C++ because it "uses" some of the same
    benefits that Smalltalk has had for 20+ years. It's
    pretty close to being object-oriented (still arguably
    object-based due to base types that aren't real
    objects) and there's a wide support base for
    developing under it. And, to echo a sentiment from
    another poster, there's a slew of free
    tools/frameworks that can be used to do some pretty
    slick stuff.
    Granted, I'll be a heck of a lot happier when/if they
    eliminate base types and go with all objects or at
    least beef-up the Number hierarchy to do math in an
    object-oriented manner (I can rant on that for days).
    Dan

  • @value tag dosen't work for java.math.BigInteger constants

    Is there anything I can do to get the Javadoc {@value} tag to document the value of BigInteger constants?
    I presume the issue applies to any object constants, but, BigInteger is all I need.
    Thanks for any advice.

    I apologize, I should have supplied more context....
    Here is my sample source
    package ...;
    import java.math.BigInteger;
    public class TestJavaDoc
    * TEST_STRING has value {@value}
    public static final String TEST_STRING = "IFQ Permit ";
    * TEST_BIG_INTEGER has value {@value}
    * Should also work like this {@value #TEST_BIG_INTEGER}
    * Constant ONE has a value {@value BigInteger#ONE}
    public static final BigInteger TEST_BIG_INTEGER = BigInteger.valueOf(1000);
    Here is the generated Javadoc, where you can see that @value works for a String, but fails for BigInteger....
    TEST_STRING
    public static final java.lang.String TEST_STRING
    TEST_STRING has value "IFQ Permit "
    TEST_BIG_INTEGER
    public static final java.math.BigInteger TEST_BIG_INTEGER
    TEST_BIG_INTEGER has value {@value}
    Should also work like this {@value}
    Constant ONE has a value {@value}
    Here is more context:
    javadoc -J-versionjava version "1.4.2_09"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
    Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
    excerpt from build.xml:
    <target name="larryDoc"
    description="Generates JavaDoc Business Rule classes">
    <tstamp>
    <format property="generation.time" pattern="MM/dd/yyyy hh:mm:ss aa"/>
    </tstamp>
    <javadoc
    destdir="./businessRules"
    author = "true"
    version = "true"
    use = "true"
    windowtitle = "Business Rules"
    additionalparam="-breakiterator">
    <fileset dir="../business/src" defaultexcludes="yes">
    <include name="org/psmfc/er/business/TestJavaDoc.java"/>
    </fileset>
    <classpath>
    <path>
    <pathelement path="IER/business/classes"/>
    </path>
    </classpath>
    <bottom>generated: ${generation.time}</bottom>
    </javadoc>
    </target>

Maybe you are looking for

  • Purchase req type after MRP Run

    Ca we control the type of Purchase req after MRP Run. Now for every material it is creating "NB" type purchase req. Can we control it material type or by mat number. We have 2-3 purchase req types in system for Material. Amit Shah

  • "the device is not connected. Please connect your Zen MicroPhoto to your computer" ?

    Hi I have just bought it today, and the installation went thru without any trouble. Then when I connected my mp3 player as the book says I for one cant install it (since there's no driver for it) and when I look in the 'Zen MicroPhoto Media Explorer'

  • Storage Bin in MM-set as mandatory field

    Hi experts, pls help me on how to set the storage bin field as Mandatory in MM creation. MARD-LGPBE is this possible to set by plant level or material type? need your expertise. thanks, Maia

  • Animation Playback Errors

    Hello, I am troubleshooting playback errors in Cap 2 exes that contains imported .swf and .avi files. Errors: The exe will play back correctly any number of times. Then, stops playing back correctly. I don't think this behavior begins to occur until

  • 802.1x bypassed?

    Hi everybody. I have  a question on 802.1x. h1-----------hub---------f1/1-SW-------Radius server.                      |                      h2 h1 is a legitimate user while h2 is not.  h1 powers up while h2 is off.  h1 uses 802.1x and gets authenti