Help with findByDateRange method in CMP enity bean

Hello,
I am trying to deploy my entity beans to WebLogic 7, runnning on a Sun Solaris
box. The application connects to an Oracle 9i database. I am having problems with
2 queries in my ejb-jar.xml file which correspond to 2 finder methods. These finder
methods take two java.util.Date parameters. I have read that EJB QL does not support
dates or date literals in its WHERE clause and one has to use long values of these
dates. I tried various combinations but haven't been able get the query to work.
Here is an excerpt from my ejb-jar.xml file
<query>
<query-method>
<method-name>findBySalesOrderID</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(c) FROM Equipment c
WHERE c.salesOrderID = ?1
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findEquipmentByStagingDateRange</method-name>
<method-params>
<method-param>java.util.Date</method-param>
<method-param>java.util.Date</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[
SELECT OBJECT(c) FROM Equipment c
WHERE c.equipReqStageDate >= ?1 AND c.equipReqStageDate <= ?2
]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-params>
<method-param>java.util.Date</method-param>
<method-param>java.util.Date</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[
SELECT OBJECT(c) FROM Equipment c
WHERE c.equipReqShipDate >= ?1 AND c.equipReqShipDate <= ?2
]]>
</ejb-ql>
</query>
Do I have to change the method parameters to java.lana.Long or to 'long' literal
from java.util.Date?
Here is the finder method signature in the home interface
public java.util.Collection findEquipmentByStagingDateRange(java.util.Date begDate,
java.util.Date engDate) throws javax.ejb.FinderException, java.rmi.RemoteException;
public java.util.Collection findEquipmentByShippingDateRange(java.util.Date begDate,
java.util.Date engDate) throws javax.ejb.FinderException, java.rmi.RemoteException;
Do I have to pass in Dates or java.lang.Longs or 'long' literals?
Any help is really appreciated. Thanks.
[question.txt]

Did you try java.sql.Date?
/k
"John Carson" <[email protected]> wrote in message
news:[email protected]...
>
Hello,
I am trying to deploy my entity beans to WebLogic 7, runnning on a SunSolaris
box. The application connects to an Oracle 9i database. I am havingproblems with
2 queries in my ejb-jar.xml file which correspond to 2 finder methods.These finder
methods take two java.util.Date parameters. I have read that EJB QL doesnot support
dates or date literals in its WHERE clause and one has to use long valuesof these
dates. I tried various combinations but haven't been able get the query towork.
Here is an excerpt from my ejb-jar.xml file
<query>
<query-method>
<method-name>findBySalesOrderID</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(c) FROM Equipment c
WHERE c.salesOrderID = ?1
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findEquipmentByStagingDateRange</method-name>
<method-params>
<method-param>java.util.Date</method-param>
<method-param>java.util.Date</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[
SELECT OBJECT(c) FROM Equipment c
WHERE c.equipReqStageDate >= ?1 AND c.equipReqStageDate <= ?2
]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-params>
<method-param>java.util.Date</method-param>
<method-param>java.util.Date</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[
SELECT OBJECT(c) FROM Equipment c
WHERE c.equipReqShipDate >= ?1 AND c.equipReqShipDate <= ?2
]]>
</ejb-ql>
</query>
Do I have to change the method parameters to java.lana.Long or to 'long'literal
from java.util.Date?
Here is the finder method signature in the home interface
public java.util.Collection findEquipmentByStagingDateRange(java.util.DatebegDate,
java.util.Date engDate) throws javax.ejb.FinderException,java.rmi.RemoteException;
>
public java.util.CollectionfindEquipmentByShippingDateRange(java.util.Date begDate,
java.util.Date engDate) throws javax.ejb.FinderException,java.rmi.RemoteException;
>
Do I have to pass in Dates or java.lang.Longs or 'long' literals?
Any help is really appreciated. Thanks.

Similar Messages

  • Need help with Sound Methods

    Hi, I am new to java and need help with sound methods.
    q: create a new method that will halve the volume of the positive values and double the volume of the negative values.
    Message was edited by:
    Apaula30

    duplicate message #2

  • Problem with findAll method in CMP

    I have successfully deployed the CMP entity bean and am testing the findAll method
    when I reaslised that the result returned to the collection is limited to 100
    records, although I have 150 records in the database.
    When I restarted the WLS and ran the test again, the first time I ran findAll,
    it returned 150 records. But when I ran it a second time, it was limited to 100
    again. It seems that the findAll method only works on the first time after I restart
    the WLS.
    Any idea what could be wrong? I am using WLS6.1 and the EJBQL is as follows:
    FROM UnitsEBean var
    Any help would be appreciated. Thanks.
    Chris

    The setting for max heap size is dependent on how your application behaves.
    If you create alot of small temporary objects and you use a large heap size
    such as 512mb then when the full garbage collection runs in the JVM your
    application is completely suspended while GC runs. In practice I have seen
    this take upwards of 15 seconds or more at 512MB. If you have this problem
    you also likely have memory leaks (implicit references to onbjects left
    around) so that the GC does not free up this memory. In practice I have
    experienced better results by running more weblogic instances with smaller
    JVMs than running few weblogic instances with large JVMs.
    The sun Java site has alot of useful documentation on tuning the JVM.
    Francis Sommers
    "Cameron Purdy" <[email protected]> wrote in message
    news:3c1a8284$[email protected]..
    Up your max beans in cache to 10000.
    Peace,
    Cameron Purdy
    Tangosol Inc.
    Tangosol Coherence: Clustered Coherent Cache for J2EE
    Information at http://www.tangosol.com/
    "Chris Yeo" <[email protected]> wrote in message
    news:3c19e569$[email protected]..
    I have successfully deployed the CMP entity bean and am testing thefindAll method
    when I reaslised that the result returned to the collection is limited
    to
    100
    records, although I have 150 records in the database.
    When I restarted the WLS and ran the test again, the first time I ranfindAll,
    it returned 150 records. But when I ran it a second time, it was limitedto 100
    again. It seems that the findAll method only works on the first time
    after
    I restart
    the WLS.
    Any idea what could be wrong? I am using WLS6.1 and the EJBQL is asfollows:
    FROM UnitsEBean var
    Any help would be appreciated. Thanks.
    Chris

  • Help with Login Form (JSP DB Java Beans Session Tracking)

    Hi, I need some help with my login form.
    The design of my authetication system is as follows.
    1. Login.jsp sends login details to validation.jsp.
    2. Validation.jsp queries a DB against the parameters received.
    3. If the query result is good, I retrieve some information (login id, name, etc.) from the DB and store it into a Java Bean.
    4. The bean itself is referenced with the current session.
    5. Once all that's done, validation.jsp forwards to main.jsp.
    6. As a means to maintain state, I prefer to use url encoding instead of cookies for obvious reasons.I need some help from step 3 onwards please! Some code snippets will do as well!
    If you think this approach is not a good practice, pls let me know and advice on better practices!
    Thanks a lot!

    Alright,here is an example for you.
    Assume a case where you don't want to give access to any JSP View/HTML Page/Servlet/Backing Bean unless user logging system and let assume you are creating a View Object with the name.
    checkout an example (Assuming the filter is being applied to a pattern * which means when a resource is been accessed by webapplication using APP_URL the filter would be called)
    public doFilter(ServletRequest req,ServletResponse res,FilterChain chain){
         if(req instanceof HttpServletRequest){
                HttpServletRequest request = (HttpServletRequest) req;
                HttpSession session = request.getSession();
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                String method = request.getMethod();
                String auth_type  = request.getAuthType();
                if(session.getAttribute("useInfoBean") != null)
                    request.getRequestDispatcher("/dashBoard").forward(req,res);
                else{
                        if(username != null && password != null && method.equaIsgnoreCase("POST") && (auth_type.equalsIgnoreCase("FORM_AUTH") ||  auth_type.equalsIgnoreCase("CLIENT_CERT_AUTH")) )
                             chain.doFilter(req,res);
                        else 
                          request.getRequestDispatcher("/Login.jsp").forward(req,res);
    }If carefully look at the code the autherization is given only if either user is already logged in or making an attempt to login in secured way.
    to know more insights about where these can used and how these can be used and how ?? the below links might help you.
    http://javaboutique.internet.com/tutorials/Servlet_Filters/
    http://e-docs.bea.com/wls/docs92/dvspisec/servlet.html
    http://livedocs.adobe.com/jrun/4/Programmers_Guide/filters3.htm
    http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html
    http://www.servlets.com/soapbox/filters.html
    http://www.onjava.com/pub/a/onjava/2001/05/10/servlet_filters.html
    and coming back to DAO Pattern hope the below link might help you.
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    http://java.sun.com/blueprints/patterns/DAO.html
    http://www.javapractices.com/Topic66.cjp
    http://www.ibm.com/developerworks/java/library/j-dao/
    http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-dao.html
    On the whole(:D) it is always a good practice to get back to Core Java/J2EE Patterns.and know answers to the question Why are they used & How do i implement them and where do i use it ??
    http://www.fluffycat.com/java-design-patterns/
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html
    http://www.cmcrossroads.com/bradapp/javapats.html
    Hope that might help :)
    REGARDS,
    RaHuL

  • Help with EJB 3.0 MEssage Driver Bean Wizard in NetBeans 5.5 preview

    I am using NetBeans 5.5 preview with sun apps server 9.0 .
    But I am not able to write message driver beans .
    Can anybody help in this regards
    ^^ Unni

    Russ thanks for checking back. I did try the prefernce manager but no luck there. I ended up downloarding promaintance as a trail and ran thier error code analysis. http://www.digitalrebellion.com/promaintenance/
    So I found that the reason it wouldn't open was that there was a missing framework. I don't know much about frameworks but I do know that when I ran digital rebelions fcp uninstaller it removed this framework. When I reinstalled fcp studio this framework was not reinstalled, even after running all of the proap updates. Consequently I found that my aperature program was affected by this framework as well and wouldn't open. I ended up having to copy the framework off of a another computer and pasting it into the appropriate folder on my Mac Pro.
    Viola, compressor now will launch at least and so will apperture. The problem still remains though that I can not ad custom destinations in Compressor with out it crashing. Another thing is that compressor will only quit if I forced quit it. I have tried uninstalling and reintalling FCP studio 4 times now with the same results. After that frameworks fiasco I am a little hesitant to mess with it any more for fear of messing up any other application.
    pretty bummed on my set up right now.
    -jon

  • Need Urgent Help with static methods!!!!

    If I have a static method to which a variable is being passed...for example
    static String doSomething(String str)
    //..doSomething with str and return
    If the method is invoked a second time by a separate entity when it is already in use by one entity(!!!not entity beans) .... will this lead to the second invocation overwriting str while the method is already in use and thus corrupting the variable that the method was passed from the first entity?

    It's also a common misunderstanding about parameters. The method does not receive a variable as its parameter, it receives a reference to an object. And inside the method, the parameter acts just the same as a local variable would. So if two threads call the method (static or not), each thread has its own copy of the parameter.

  • Help with payment methods

    When I go to log into my account, or download an app it says I need to log in and update my payment method. I log back in, and go to input my credit card details. It says that this method is invalid, please choose a different one. I then go to input a different credit cards details, and it still says its invalid. It even won't let me delete these details as the credit card type does not match the credit card information. I then thought to make a new account, and seeing you have to provide a billing method I used the same credit card that failed the first time with my other account. It then says that you need to contact ITunes support to validate this account and it won't let me.
    With the first account it wont let me do anything! Download apps, purchase them, or even update them! Please help!

    Are you aware of any problem with a previous purchase ? If not then you can try contacting iTunes Support via this link and see if they can help : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    What payment method do you currently have on your account, and have you been into your account and checked the details ? If it's a debit card then I don't think that they are still accepted as a valid payment method - they are not listed on this page and there have been a number of posts recently about them being declined
    If it's a credit card then is it registered to exactly the same name and address (including format and spacing etc) that you have on your iTunes account, it was issued by a bank in your country and you are currently in that country ?

  • Help with static method issue.

    Hi everyone,
    There's a recent thread on the forum along a similar vein as this one but I hope mine doesn't cause as much annoyance! My homework assignment involves implementing three interfaces provided by my professor in order to create weighted, undirected graphs. The classes I have to implement are Node, Edge and Graph. Here are the Edge and Node interfaces for reference; they weren't too hard to implement:
    public interface Edge {
         public Edge createEdge(String name, int ID, float weight);
         public Node getStartNode();
         public void setStartNode(Node n);
         public Node getEndNode();
         public void setEndNode(Node n);
         public String getName();
         public int getID();
         public float getWeight();
         public String toString();
    public interface Node {
         public Node createNode(String name, int ID, float weight);
         public Node[] getNeighbours();
         public Edge[] getEdges();
         public void addEdge(Edge e);
         public void removeEdge(Edge e);
         public String getName();
         public int getID();
         public float getWeight();
         public String toString();
    }Now, one of the graphs I should be aiming to create is this one ( [http://i35.tinypic.com/2iqn62d.gif|http://i35.tinypic.com/2iqn62d.gif] ) so I apologize for the code I'm about to show and its length. It's the Graph class:
    import java.util.ArrayList;
    public class Graph {
         public static void main(String [] args) {
              // Create all nodes
              int i = 1;
              Node food = new Node();
              food.createNode("Food", i, 0);
              i++;
              Node healthy = new Node();
              healthy.createNode("Healthy", i, 4f);
              i++;
              Node neutral = new Node();
              neutral.createNode("Neutral", i, 0);
              i++;
              Node unhealthy = new Node();
              unhealthy.createNode("Unhealthy", i, -4f);
              i++;
              Node orange = new Node();
              orange.createNode("Orange", i, 6f);
              i++;
              Node cabbage = new Node();
              unhealthy.createNode("Cabbage", i, 3f);
              i++;
              Node riceCake = new Node();
              unhealthy.createNode("Rice cake", i, 2f);
              i++;
              Node chocolate = new Node();
              unhealthy.createNode("Chocolate", i, -2f);
              i++;
              Node bacon = new Node();
              unhealthy.createNode("Bacon", i, -4f);
              i++;
              Node xmasPud = new Node();
              unhealthy.createNode("Christmas Pudding", i, -8f);
              i++;
              // Create all edges
              int n = 1;
              Edge food1 = new Edge();
              food1.createEdge("to healthy", i, -4.0f);
              food1.setStartNode(food);
              food1.setEndNode(healthy);
              n++;
              Edge food2 = new Edge();
              food2.createEdge("to neutral", i, 0);
              food2.setStartNode(food);
              food2.setEndNode(neutral);
              n++;
              Edge food3 = new Edge();
              food3.createEdge("to unhealthy", i, -4f);
              food3.setStartNode(food);
              food3.setEndNode(unhealthy);
              n++;
              Edge healthy1 = new Edge();
              healthy1.createEdge("to orange", i, 4f);
              healthy1.setStartNode(healthy);
              healthy1.setEndNode(orange);
              n++;
              Edge healthy2 = new Edge();
              healthy2.createEdge("to cabbage", i, 2f);
              healthy2.setStartNode(healthy);
              healthy2.setEndNode(cabbage);
              n++;
              Edge neutral1 = new Edge();
              neutral1.createEdge("to rice cake", i, 2f);
              neutral1.setStartNode(neutral);
              neutral1.setEndNode(riceCake);
              n++;
              Edge unhealthy1 = new Edge();
              unhealthy1.createEdge("to chocolate", i, -2f);
              unhealthy1.setStartNode(unhealthy);
              unhealthy1.setEndNode(chocolate);
              n++;
              Edge unhealthy2 = new Edge();
              unhealthy2.createEdge("to bacon", i, -4f);
              unhealthy2.setStartNode(unhealthy);
              unhealthy2.setEndNode(bacon);
              n++;
              Edge unhealthy3 = new Edge();
              unhealthy3.createEdge("to Christmas pudding", i, -8f);
              unhealthy3.setStartNode(unhealthy);
              unhealthy3.setEndNode(xmasPud);
              n++;
              // Assign edges to edgeList
              food.edgeList.add(food1);
              food.edgeList.add(food2);
              food.edgeList.add(food3);
              // Add node to nodeList
              nodeList.add(food);
              healthy.edgeList.add(healthy1);
              healthy.edgeList.add(healthy2);
              nodeList.add(healthy);
              neutral.edgeList.add(neutral1);
              nodeList.add(neutral);
              unhealthy.edgeList.add(unhealthy1);
              unhealthy.edgeList.add(unhealthy2);
              unhealthy.edgeList.add(unhealthy3);
              nodeList.add(unhealthy);
              // Now convert to arrays
              Node[] nodeArray = new Node; // Nodes
              nodeList.toArray(nodeArray);
              Edge[] edgeArray = new Edge[n]; // Edges
              food.edgeList.toArray(edgeArray);
              healthy.edgeList.toArray(edgeArray);
              unhealthy.edgeList.toArray(edgeArray);
              // Now turn it all into a graph
              createGraph("Food", 1, nodeArray, edgeArray, food); // doesn't work!
         public Graph createGraph(String name, int ID, Node[] nodes, Edge[] edges,
                   Node root) {
              graphName = name;
              graphID = ID;
              graphNodes = nodes;
              graphEdges = edges;
              graphRoot = root;
              return null;
         public String getName() {
              return graphName;
         public Edge[] getEdges() {
              return graphEdges;
         public void addEdge(Edge e) {
         public Edge getEdge(String name, int ID) {
              return null;
         public void removeEdge(Edge e) {
         public Node[] getNodes() {
              return graphNodes;
         public void addNode(Node n) {
              nodeList.add(n);
         public Node getNode(String name, int ID) {
              int ni = nodeList.indexOf(name);
              Node rNode = nodeList.get(ni);
              return rNode;
         public void removeNode(Node n) {
              nodeList.remove(n);
         public void setRoot(Node n) {
              graphRoot = n;
         public Node getRoot() {
              return graphRoot;
         private String graphName;
         private int graphID;
         private Node[] graphNodes;
         private Edge[] graphEdges;
         private Node graphRoot;
         private static ArrayList<Node> nodeList = new ArrayList<Node>();
    }The problem I have is that I don't know how to get around the fact that I'm making a static reference to the non-static method *createGraph*. I'd really appreciate your help. Thanks for your time!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    GiselleT wrote:
    public interface Edge {
         public Edge createEdge(String name, int ID, float weight);
    I want to kick your professor right in the grapes for this bit of idiocy. It's at the source of your problems.
    This looks very fishy and very bad. I wouldn't expect an Edge to create another Edge. Likewise for Node and Graph. You might have static factory methods in these classes, but by defining it in the interfaces, these methods have to be non-static. This leads to such ridiculous code as you have like this:
    Edge uselessEdge = new Edge();
    Edge actualEdge = uselessEdge.createEdge("abc", 1, 2.34);It's not your fault that it's useless. That's the way you have to do it with that senseless requirement.
    The problem I have is that I don't know how to get around the fact that I'm making a static reference to the non-static method createGraph.
    Static reference in non-static context errors are always addressed the same way: Either make the member in question static (usually the wrong choice) or create an instance.
    In this case, you need to do like you did with Edge, and create a useless dummy Graph whose only purpose is to create other Graphs:
    Graph graph = uselessGraph();
    Graph actualGraph = uselessGraph.createGraph(...);Then, inside the createGraph method, you'll create a Graph with new and do thatGraph.name = name; and so on for each of the parameters/members.
    Really, though, this is just an awful, awful approach though. Are you sure your prof really requires Edge to have a non-static createEdge method, and so on?

  • Please help with this method

    im creating a little animation of pacman, just an animation of it moving buy its self. im using the java elements package so this is all being shown in a drawing window.
    ive made it move fine and go round the window abit eating dots but the code is a mess, and i know i could change some of the main part into a few simple methods and have tried but it seems to stop moving when i try
    below is part of the code, the first three blocks are when its moving sideways with its mouth in three different states, and the bottom three blocks are it moving down with its mouth in three states again.
    Arc pacarc = new Arc();
    while (startmv++<stopmv)
    pac1x += 4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,pacsize1,pacsize2,pacmouth1,pacangle1);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    pac1x += 4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,pacsize1,pacsize2,pacmouth2,pacangle2);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    pac1x += 4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,pacsize1,pacsize2,pacmouth3,pacangle3);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    while (startdwn++<stopdwn)
    pac1y +=4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,50,50,pacdwn1,pacdwnang1);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    pac1y +=4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,50,50,pacdwn2,pacdwnang2);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    pac1y +=4;
    d.setForeground(Color.yellow);
    pacarc = new Arc(pac1x,pac1y,50,50,pacdwn3,pacdwnang3);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    so for the first part i tried putting this into a method and running the program but where i had used the method the pacman shape just stayed still. any help please guys?
    this is the code for the method i tried (this is just for thefirst state of the pacmans mouth while moving sideways)
    public static void pacmve(int pactestx, int pactesty, int pacsizetest1, int pacsizetest2, int pacmouthtest, int pacangletest)
    pactestx += 4;
    Arc pacarc = new Arc();
    d.setForeground(Color.yellow);
    pacarc = new Arc(pactestx,pactesty,pacsizetest1,pacsizetest2,pacmouthtest,pacangletest);
    d.fill(pacarc);
    d.setForeground(Color.black);
    waitNSeconds(1);
    d.fill(pacarc);
    this is the loop i where i was trying to use the method
    while (startmv++<stopmv)
    pacmve(20,20,50,50,45,270);
    Edited by: jeffsimmo85 on Nov 22, 2007 1:18 AM

    When you post a code on a public forum, the code must be:
    1)Properly formatted using code tags.
    2)Generally compilable and runnable for us casual forum viewers.
    3)Reproducible of your problems when we run it.

  • Help with a method

    The following method is supposed to Return an array of integers representing all of the unoccupied rooms which has the required number of double and single beds. The length of the resulting array is the same as the number of matching rooms (which may be 0 if there are no rooms of the required size available).
    The following outline was given to me to complete allong with a few comments from my tutor.
        public int[] getEmptyRooms (int doubleBeds, int singleBeds) {
            // Return an array of integers representing all of the unoccupied rooms
            // which has the required number of double and single beds. The length of
            // the resulting array is the same as the number of matching rooms
            // (which may be 0 if there are no rooms of the required size available).
            // At the very least you need to change the following statement
            // ge - don't change this statemnt
            int numEmpty = 0;
             * ge
             * yu have still to attempt this
             * you need to use a loop to go through all the rooms and see if
             * they are not occupied and have the required no of double and single beds
             * then increase numEmpty by 1
            // At the very least you need to change the following statement
            //ge - this statement looks ok
            int[] rooms = new int[numEmpty];
             * however, you will now nee to loop through all the rooms
             * and if it meets the same test as previously
             * then add i to the rooms array
            // At the very least you need to change the following statement 
            return rooms;
        }I have done the following but to say the least it deosnt return what is required.
    public int[] getEmptyRooms (int doubleBeds, int singleBeds) {
            // Return an array of integers representing all of the unoccupied rooms
            // which has the required number of double and single beds. The length of
            // the resulting array is the same as the number of matching rooms
            // (which may be 0 if there are no rooms of the required size available).
            int numEmpty = 0;
            for(int i = 0; i < theRooms.length; i++)
                if(!theRooms.isOccupied() && theRooms[i].hasRequiredBeds(doubleBeds, singleBeds))
    numEmpty++;
    int[] rooms = new int[numEmpty];
    for(int i = 0; i < theRooms.length; i++)
    if(!theRooms[i].isOccupied() && theRooms[i].hasRequiredBeds(doubleBeds, singleBeds))
    i++
    return rooms;
    I really need to get this sorted out soon as i need to submit it tomorrow and i cant seem to see what is wrong (partially because im not great at java).
    So any help what so ever will be greatly appreciated

    The following is returned when i try and run the hotel appilcation
    [l@e33af5
    and that is when the following code is used
        public int[] getEmptyRooms (int doubleBeds, int singleBeds) {
            // Return an array of integers representing all of the unoccupied rooms
            // which has the required number of double and single beds. The length of
            // the resulting array is the same as the number of matching rooms
            // (which may be 0 if there are no rooms of the required size available).
            int numEmpty = 0;
            for(int i = 0; i < theRooms.length; i++)
                if(!theRooms.isOccupied() && theRooms[i].hasRequiredBeds(doubleBeds, singleBeds))
    numEmpty++;
    int[] rooms = new int[numEmpty];
    int x = 0;
    for(int i = 0; i < theRooms.length; i++)
    if(!theRooms[i].isOccupied() && theRooms[i].hasRequiredBeds(doubleBeds, singleBeds))
    rooms[x] = 0;
    x++;
    return rooms;

  • Help with the method copyPixels

    Hello good day!
    I need a force in  a scheme that I am doing with a combobox that I created to select a  font of a text. I would like to display the text to the source, but do  not want to imply load all sources that I am offering 30, then a  solution that I thought it would be feasible to use an image with these  sources, then in that case all that needs to be done would be to carry this image that has about 30kb which would be a process not so  slow.
    For this did the following: I created the image in my library  as a movie clip and then used two BitmapData and a bitmap to display the  image as follows:
        var bmp: Bitmap;
        / / Lista_fonte  is my image of the sources
        var list: = new  lista_fonte lista_fonte ();
        / / Create a  BitmapData from the list instantiated
        var bmd:  BitmapData = new BitmapData (lista.width, lista.height, true);
        / / Create a BitmapData less for the item from combobox
        var bmdtemp:  BitmapData = new BitmapData (lista.width, 20, true);
    And then I go  with a paragraph of the sources and use the copyPixels to copy part of  the image:
        for (var i: int = 0; i <30; i) (
            bmdtemp.copyPixels (bmd, new Rectangle (0,0, lista.width, 20),  new Point (0, 20 * i));
            bmp = new  Bitmap (bmdtemp);
            addChild (bmp);
    Above would look like this,  but I have two problems:
    1 The picture is transparent with the  background and create the BitmapData I allow there is an overhead  transparency, but the picture shows a white background!
    2 are just  copying the image at position 0.0 in the case is with any combo of the  first source image only.
    I hope that was clear, please help me now  to break the head at a time on it and I read in some forums and some  discusões around and nothing.

    wannabehacker wrote:
    But my actual question remained unanswered. Would you please take a look at the method if you have some time and explain to me how the method is converting the IP to decimal.
    public class CharTest {
        public static void main(String[] args) {
            int b = '0';
            System.out.println(b);
    }This prints out 48. What do you think the significance of that is, and what do you think would happen if I did
    int c = '8' - '0';
    System.out.println(c);

  • Help with itemStateChanged method

    I have created an applet which diplays a combobox,three buton being play, stop and loop. The program runs but only plays the first two sound files and not the rest. I thin it has something to do with my itemStateChanged() method.
    Any help id be very grateful......
    Heres the programme
    // Java Core Packages
    import java.applet.Applet;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    //Java extension packages
    import javax.swing.*;
    * Loads and Plays audio clips with
    * the addition of a loop function
    * @author L_Tambiah
    * @version 01
    public class LoadAudioAndPlay extends JApplet
    private AudioClip sound1, sound2, sound3, sound4, sound5, sound6, currentSound;
    private JButton playSound, loopSound, stopSound;
    private JComboBox chooseSound;
    //load the image when the applet begins executing
    public void init()
    Container container = getContentPane();
    container.setLayout( new FlowLayout() );
    String choices[] = { "Bottle", "Flute", "Space music", "Trippy",
    "dandb", "garage"};
    chooseSound = new JComboBox( choices );
    chooseSound.addItemListener(
    new ItemListener()
    //stop sound and change to sound to users selection
    public void itemStateChanged( ItemEvent e )
    currentSound.stop();
    currentSound = chooseSound.getSelectedIndex() == 0 ?
    sound1 : sound5;
    }// end anonymous inner class
    );// end addItemListener method call
    container.add( chooseSound );
    //set up button event handler and buttons
    ButtonHandler handler = new ButtonHandler();
    playSound = new JButton( "Play" );
    playSound.addActionListener( handler );
    container.add( playSound );
    loopSound = new JButton( "Loop" );
    loopSound.addActionListener( handler );
    container.add( loopSound );
    stopSound = new JButton( "Stop" );
    stopSound.addActionListener( handler );
    container.add( stopSound );
    //load sounds and set currentSound
    sound1 = getAudioClip( getDocumentBase(), "bottle.wav" );
    sound2 = getAudioClip( getDocumentBase(), "flute.aif" );
    sound3 = getAudioClip( getDocumentBase(), "spacemusic.au" );
    sound4 = getAudioClip( getDocumentBase(), "trippy.mid" );
    sound5 = getAudioClip( getDocumentBase(), "dandb.wav" );
    sound6 = getAudioClip( getDocumentBase(), "garage.wav" );
    currentSound = sound1;
    } //end method init
    //stop the sound when the user switches web pages
    public void stop()
    currentSound.stop();
    //private inner class to handle button events
    private class ButtonHandler implements ActionListener {
    //process play, loop and stop button events
    public void actionPerformed( ActionEvent actionEvent )
    if ( actionEvent.getSource() == playSound )
    currentSound.play();
    else if ( actionEvent.getSource() == loopSound )
    currentSound.loop();
    else if ( actionEvent.getSource() == stopSound )
    currentSound.stop();
    L.Tambiah
    E0261830

      AudioClip[] clips = {
        sound1, sound2, sound3, sound4, sound5, sound6
      public void itemStateChanged(ItemEvent e) {
        if(e.getStateChange() == ItemEvent.SELECTED) {
          currentSound.stop();
          currentSound = clips[chooseSound.getSelectedIndex()];
      } For more information:
    http://java.sun.com/docs/books/tutorial/uiswing/events/itemlistener.html

  • Help with a method for battleships

    Hi, I am doing a battleships applet, so far things are going well, except for the fact that I am using two methods of input for my ships, the first one is manual input, the user types in the textfields to place the ship, the second one is by using random number generators to place the ship and define if they are to be place horizontally and vertically. Here is my method for the PC placement. My question is how to write a method, which doesn`t allow the ships to overlap in any way?
    {int a = (int) (Math.random()*2);
                   rowindex[0] = 1 + (int) (Math.random() * 11);
                   colindex[0] = 1 + (int) (Math.random() * 11);
                   showship[1] = true;
                   if(a==1){
                   orientation[1] = true;
                   for(int i = 0;i<bsholder.length;i++){
                   bsholder[i] = (colindex[0]+i);
                   System.out.println(bsholder);
                   System.out.println();
                   else {
                   orientation[1] = false;
                   for (int i=0; i<bsholder.length;i++){
                   bsholder[i] = (rowindex[0]+i);
                   System.out.println(bsholder[i]);
              System.out.println();
                   int b = (int) (Math.random()*2);
                   rowindex[1] = 1 + (int) (Math.random() * 12);
                   colindex[1] = 1 + (int) (Math.random() * 12);
                   showship[2] = true;
                   if (b==1){
                   orientation[2] = false;
                   for (int i=0; i<cruisholder.length;i++){
                   cruisholder[i] = (rowindex[1]+i);
                   System.out.println(cruisholder[i]);
                   System.out.println();
                   else {
                   orientation[2] = true;
                   for (int i=0; i<cruisholder.length;i++){
                   cruisholder[i] = (colindex[1]+i);
                   System.out.println(cruisholder[i]);
                   System.out.println();
                   int c = (int) (Math.random()*2);
                   rowindex[2] = 1 + (int) (Math.random() * 13);
                   colindex[2] = 1 + (int) (Math.random() * 13);
                   showship[3] = true;
                   if (c==1)orientation[3] = true;
                   else orientation[3] = false;
                   rowindex[3] = 1 + (int) (Math.random() * 14);
                   colindex[3] = 1 + (int) (Math.random() * 14);
                   showship[4] = true;
    rowindex and colindex are the arrays I use for the graphical representation of the ships on the board. orientation is a boolean array used to define the horizontal or vertical placement. bsholder and cruisholder are arrays to store the coordinates of the ships. I am currently not using one for 2square ship and 1square ship because this is just a test programm.I am using the System.out.println is not going to be included in the end version. Please help me, I ve been stuck on it for days. I have tried all sorts of for loops includen the "enchanced for" loop but still no luck. Many thanks in advance.

    mpenoushliev wrote:
    Wow, thanks a lot I will try it out, only one last question, should the holder for the ship (the array that has the location of the ship be a 2D array or could I use a standard array and combine that with either the row or col to track the ship. (That is what I am doing now). Once again thank you very much for the help.I wrote a battleship game a few weeks ago for fun, and I created a Board class that has a 2D array of Cells. The Cell class holds a reference to 1 ShipElement, which is a single piece of a whole Ship. The Ship class has a List of ShipElements, and is used to keep track of when whole ships are sunk, etc. The Board class is responsible for placing ships, and it iterates over the Cells. The Cell class has methods that tell you if it has a ShipElement or just Water, and you can use the size of the Board to check you haven't gone over the edge. Hope it helps!

  • Help with some methods !! Please..

    Hi !!
    My University teacher gave me an exercize where he askes to calculate the minimum,medium and maximum cubic capacities in an ArrayList<Cars> carList .
    I didn't find problems to make a new method for searching the minum and maximum cubic capacities,but I could not think a way to make the method for the Average cubic capacity value.
    For the min and max searches I wrote down :
    public Car searchForMinCubicCapacityValue()
    Car car= carList.get(0);
    for(Car aCar : carList)
    if(aCar.getCubicCapacity() <= car.getCubicCapacity())
    minimumCar = aCar; (where minimumCar is an Instance Variable)
    return minimumCar;
    The same is for the method searchForMaxCubicCapacityValue() but I put >= indeed and I have used the Instance Variable maximumCar.
    How could I write down the method searchForAverageCubicCapacityValue() ?
    I really need your help please !...
    I have to know for next week test ! In this test I'll have to write down a class with these same methods and others !
    Thanks in advance !

    Sorry ! I'll change the name of my 3 methods !
    I would calculate by hand an average just adding up
    the cubic capacities and then dividing the result of
    this addition by the total number of cars.Right.
    But I have tried to write down this one in the method
    for an Average cubic capacity but I get the same
    result of the maximum cubic capacity.Well, then the Java you wrote doesn't do what you described above. If you show the code, someone can help you find your error.
    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. (http://forum.java.sun.com/help.jspa?sec=formatting) It makes it much easier to read.
    But I know that
    there is an average value in my ArrayList !Of course there is. Any collection of values has an average.
    I think this thing happens because the result of the
    division is a number that doesn't exist in my
    ArrayList.The average may very well not be a numbre in the list. If the list contains only 0 and 100, the average is 50, which is not in the list.

  • Need help with drawLine method

    Hello,
    I've been having trouble with a recent programming assignment and the prof isn't being very helpful. I need to call the drawLine method to plot a line between (0,0) and two coordinates entered by the user; is there a way to do this without a JPanel? Here are the specs:
    I've already done Part 1., just posting it to give a complete representation of the assignment.
    Part 1. Implement a ComplexNumber class to represent complex numbers (z = a + bi).
    1) Instance variables:
    private int real; /* real part */
    private int imag; /* imaginary part */
    2) Constructor:
    public ComplexNumber ( int realVal, int imagVal )
    { /* initialize real to realVal and imag to imagVal */ }
    3) Get/Set functions:
    public int getReal ( )
    { /* returns the real part */ }
    public int getImag ( )
    { /* returns the imaginary part */ }
    public void setReal ( int realVal )
    { /* sets real to realVal */ }
    public void setImag ( int imagVal )
    { /* sets imag to imagVal */ }
    Part 2. Implement a ComplexNumberPlot class (with a main method) that gets complex
    numbers from the user and plots them. The user will be prompted a complex number until
    he/she enters 0. The numbers will be input from the keyboard (System.in) and displayed
    in the plot as they are entered. Assume that the user will enter the numbers in blank
    separated format. For example, if the user wants to enter three complex numbers: 3 + 4i,
    5 + 12i, and 15 + 17i, the input sequence will be:
    3 4
    5 12
    15 17
    0 0
    To plot a complex number, you need to draw a line between (0,0) and (real, imag) using
    the drawLine method.
    Name your classes as ComplexNumber and ComplexNumberPlot.
    For simplicity, you can assume that the complex numbers input by the user fall
    into the first quadrant of the complex plane, i.e. both real and imaginary values
    are positive.
    Thanks for any help!

    Ok I've made some progress, here is what I've got.
    public class ComplexNumber
    private int real;
    private int imag;
    public ComplexNumber (int realVal, int imagVal)
    real = realVal;
    imag = imagVal;
    public int getReal()
    return real;
    public int getImag()
    return imag;
    public void setReal(int realVal)
    real = realVal;
    public void setImag(int imagVal)
    imag = imagVal;
    import java.util.Scanner;
    import java.awt.*;
    import javax.swing.*;
    public class ComplexNumberPlot
    public static void main (String [] args)
    ComplexNumber num = new ComplexNumber (1,0);
    Scanner scan = new Scanner (System.in);
    System.out.println("Enter a complex number(s):");
    num.setReal(scan.nextInt());
    num.setImag(scan.nextInt());
    while (num.getReal() + num.getImag() != 0)
    num.setReal(scan.nextInt());
    num.setImag(scan.nextInt());
    System.out.println();
    JFrame frame = new JFrame ("ComplexNumberPlot");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    ComplexPanel panel = new ComplexPanel();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    class ComplexPanel extends JPanel
    public ComplexPanel()
    setPreferredSize (new Dimension(150,150));
    public void PaintComponent (Graphics page)
    super.paintComponent(page);
    page.drawLine(0,0,100,100);
    However
    1) The JPanel pops up but no line is drawn.
    2) I am not sure how to get the variables I'm scanning for to work in the drawLine method
    Thanks for all your help so far.

Maybe you are looking for

  • Issue with Date showing Null in interactive report

    I created an interactive report for a customer and was confused to see blanks or more specifically dashes where there should be dates in one of the fields. I knew this field should have data so I did some testing and this is what I have found: The sq

  • HT204053 How can I change my iCloud email?

    Someone set up my iCloud email and put their name but now I want to change it to where it say my name.

  • J2ME Wireless Toolkit 2.5

    Hi all, I would like to ask if this new veresion (J2ME Wireless toolkit 2.5) supports ArrayList. I have developed a program with ArrayList , is it possible to run it in this new version without problems. Thanks

  • Whats wrong with my php script?

    Hi, I'm (slowly) learning php and am having trouble getting this script to work. It is meant to redirect to paygol once the user clicks a button but for some reason it's not redirecting and just sits on a page telling the user they will be redirected

  • Rebuild Mail

    I hit the rebuild button in Mail because I was getting the "need to download from server" message and all my mail disappeared? How do I get it back?