EJB Programming Problem

I have a project:
create table contacts (id int(10) auto_increment,
user varchar(100),
contact_name(100),
primary key (id))
the session bean :
ContactBookBean{
public void addPersonalContact(java.lang.String username) {
String contactname=username;
try
Context ctx= new InitialContext();
Object objref=ctx.lookup("java:comp/env/ejb/contacts");
LocalcontactsHome localcontactshome =(LocalcontactsHome)PortableRemoteObject.narrow(objref,LocalcontactsHome.class);
localcontactshome.create(new Integer(0),username,contactname);
}catch(Exception e){
throw new EJBException(e);
the cmp entity bean contactsBean{
public java.lang.Integer ejbCreate(java.lang.Integer id, java.lang.String user, java.lang.String contactName) throws javax.ejb.CreateException {
setId(id);
setUser(user);
setContactName(contactName);
return null;
the test client
Context ctx = new InitialContext();
ContactBookHome home=(ContactBookHome)PortableRemoteObject.narrow(ctx.lookup("ContactBook"),ContactBookHome.class);
ContactBook test=home.create();
test.addPersonalContact("[email protected]");
I want insert a record into the database.The deployment is no problem.
but when i run the client the IDE throws Exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: nested exception is: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.ejb.EJBException: nested exception is: java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near '"contacts" WHERE "id" = 0 ' at line 1;
IDE:Sun forte for java
Database:Mysql
OS:Sun Solaris
Appserver:RI in forte
I do not know how to deal with the variable "id"
that is :auto_increment pri_key(id) .
Help is appreciated ,thanks.

Your EJBCreate method is specifing an id, when your database is auto assigning the index. That is what is causing your SQLException. Either do not specify the id in the method signature, or turn off auto assignment in the database.
tj...

Similar Messages

  • Java Programming Problem

    Hi all,
    I was looking for this java programming problem which had to do with a large building and there was some gallons of water involved in it too somehow and we had to figure out the height of the buiding using java. This problem is also in one of the java books and I really need to find out all details about this problem and the solution. NEED HELP!!
    Thanks
    mac

    Yes, it will. The water will drain from the bottom of
    the tank until the pressure from the water inside the
    tank equals the pressure from the pipe. In other
    words, without a pump, the water will drain out until
    there is the same amount of water in the tank as in
    the pipe The water pressure depends on the depth of the water, not the volume. So once the depth of the water inside the pipe reaches the same depth as the water inside the tank it will stop flowing. This will never be above the height of the tank.
    I found this applet which demonstrates our problem. If you run it you can drag the guy up to the top, when water in his hose reaches the level of the water in the tank it will stop flowing out.

  • Programming problem

    Subject:
    programming problem
    Date:
    Sun, 10 Mar 2002 19:48:34 +0800
    From:
    LibraryPublicStation <[email protected]>
    Organization:
    Hong Kong University of Science and Technology
    Newsgroups:
    hkust.cs.class.201
    Hi, I have some problems on the following code:
    The code has no compiling error. but
    Why I can't get the RGB value of my image since I can get the width and
    height of the image.
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.Graphics.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.*;
    import java.awt.color.*;
    import com.sun.image.codec.jpeg.*;
    import java.awt.geom.*;
    public class Sun
    public static void main(String args[])
    double[][] database_graph=new double[0][900];
    // put the image in a row with 900 column
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image1 = new ImageIcon("imges.jpg").getImage();//load the image to
    image1
    BufferedImage buffer;//Buffer the image to get the RGB value
    buffer = new BufferedImage(image1.getWidth(null),image1.getHeight(null),
    BufferedImage.TYPE_INT_ARGB);
    ColorModel a=buffer.getColorModel();
    System.out.println(a);
    for(int j=0;j<buffer.getWidth();j++)
    for(int k=0;k<buffer.getHeight();k++)
    int rgb=buffer.getRGB(j,k);//get the red,green,blue value of the graph
    int red = ((rgb&0xff0000)>>16);
    int green = ((rgb&0xff00)>>8);
    int blue = rgb&0xff;
    database_graph[0][buffer.getHeight()*j+k] = (red + green + blue)/3;
    System.out.println(database_graph[0][buffer.getHeight()*j+k]+" "+red+"
    "+green+" "+blue);
    } // change back to gray scale

    Try this :
    ImageIcon icon = new ImageIcon("imges.jpg");
    Image image1 = icon.getImage();
    BufferedImage buffer = new BufferedImage(icon.getIconWidth(),icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    ...But I think, in your problem, you want to get the image in a BuffererdImage ?
    ImageIcon icon = new ImageIcon("imges.jpg");
    BufferedImage buffer= (BufferedImage)icon.getImage();
    ...Denis

  • Coldfusion server problem or programming problem?

    Hello experts,
    I have been experiencing problems when accessing this website using Mac (and Parallels/WinXP).
    http://tinyurl.com/3yh3d8l
    Because there is no problem when using Windows PC, the programmer suggested that it might be a CF server problem, but one of my IT said it's programming issue (basically he said the web programmer is wrong). I have very limited access to PC at work but I need the data from that website. I'd like to give input to the webprogrammer but I don't know what to say. Could you please give me some suggestions? Thank you.

    hi Adam,
    Just tested in Mac, the site works in FireFox. But Safari won't load it at all. Progress bar keep spinning but screen doesn't change.
    So is this something to do with the programming problem or Safari is being picky? I can use FireFox during presentation but I'd like the option to be able to use Safari (iPad?).

  • Cretical programming problem

    dear sirs, i work with forms 6i
    i have programming problem and i want to solve it
    the problem is
    i have table contain the following fields
    AREA_CODE NOT NULL NUMBER(8)
    AREA_NAME NOT NULL VARCHAR2(30)
    EAREA_NAME VARCHAR2(30)
    UP_AREA_CODE NUMBER(8)
    AREA_TYPE NUMBER(1)
    AREA_LEVEL NUMBER(15)
    transfer_fees number(15,3)
    i want to get the value of transfer_fees, depend on the area code which i want, but if transfer_fees is null i should get the other transfer_fees of the up_area_code as the up level of area code, and if also null then get the value of transfer_fees of the up level of area code and so on.
    please help me urgently
    Yasser

    Hi yasser
    it's not precise for me , It needs a lot of details but according to the existing information
    Now we have 3 options
    Option1 : Get the transfer_fees according to AREA_CODE -- i don't know how not clear for me
    Option 2 : IF transfer_fees IS NULL then get it's value from up_area_code (then i am assuming that up_area_code has a value currently during the user input so all we have is to think that we can get it's value from a simple assign statement in WHEN-VALIDATE-ITEM trigger of transfer_fees item as ...
    IF :transfer_fees IS NULL THEN
    :transfer_fees  :=:up_area_code;
    END IF;and so on...
    Hope this helps...
    Regards,
    Amatu Allah

  • OSystem Program Problem Detected Window, asks if I want to report this, then it asks for my Password ? is this ok ?

    I'm new to Ubuntu & Linuz OS. I've started to see a pop-up window that says: System Program Problem Detected- Do you want to report the problem. When I click yes, I'm asked to enter my password to access problem reports of system programs. Should I be asked for my password ???

    I am fairly new to Ubuntu, but that does not sound unexpected. Ubuntu tends to have everyone use a limited account that needs to ask for a password before carrying out operations like installing software.

  • The Naming problem in my first ejb program.

    Dear experts,
    I am new to Enterprise applications.
    I am ,now, in my first step in developinf Enterprise Java bean.
    I use Sun System Application Server.
    The following s my very first code:
    Hello.java (Remote interface)
    import java.rmi.*;
    import javax.ejb.*;
    public interface Hello extends EJBObject{
         public void displayMessage() throws RemoteException;
    HelloHome.java (Home interface)
    import java.rmi.*;
    import javax.ejb.*;
    public interface HelloHome extends EJBHome{
         public Hello create() throws RemoteException,CreateException;
    HelloBean.java (Bean Implementation class)
    import java.rmi.*;
    import javax.ejb.*;
    public class HelloBean implements SessionBean{
         public void displayMessage(){
              System.out.println("Success..Success..SLK won atlast");
         public void ejbCreate(){
         public void ejbRemove(){
         public void ejbActivate(){
         public void ejbPassivate(){
         public void setSessionContext(SessionContext ct){
    I did go thro the following steps:
    1.I save all these files inside c:\MyEjb folder.
    2.First I compile the following files with javac complier
         Hello.java,HelloHome.java and HelloBean.java
    3.I open deploytool and created a Application HelloApplication.It gives me HelloApplication.ear file inside c:\MyEjb folder.
    4.I created a bean jar into the HelloApplication.The bean jar created is Hello.jar.
    5.Then I deploy HelloApplication with out checking/selecting the Return Client jar check box.
    6.After the application is deployed, I select, from the tree view,LocalHost 4848.
    I select HelloApplication from the deployed applications list, and click the Click Jar...button.It returns HelloApplicationClient.jar into c:\MyEjb folder.
    Here goes my Client java file:
    HelloClient.java
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    import java.util.*;
    public class HelloClient{
         public static void main(String s[]){
              try{
                   Properties prop = new Properties();
                   prop.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
                   prop.put(javax.naming.Context.PROVIDER_URL,"file:c:\\");
                   Context ctx = new InitialContext(prop);
                   HelloHome hHome = (HelloHome)ctx.lookup("Hello");
                   Hello hObj = hHome.create();
                   hObj.displayMessage();
              }catch(Exception e){
                   e.printStackTrace();
    This also is in C:\MyEjb folder.
    Now I compile HelloClient.java.
    Then I tried to run HelloClient using java HelloClient
    It just says javax.naming.NameNotFoundException:Hello
    Why is this so? Does Sun App server uses any other naming service than FileSystem (fscontext) like CORBA Naming service COS Naming?If so I can download COS Naming provider and use that in my client code.
    Is this correct way to run my client code? or should I go thro File->New->Application Client...etc and use appclient utility?
    I tried that too and run using the command appclient -client HelloAppClient.jar -mainclass HelloClient
    Again I get the same exception,javax.naming.NameNotFoundException:Hello.
    I checked the JNDI Name for my HelloBean and its correctly set as 'Hello'.
    Why is this error? Should I have any special folder structure to run EJB?
    Help me resolve this.
    Thanx in advance
    unique

    Try rewriting your Hello client like this:
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    import java.util.*;
    public class HelloClient
        public static void main(String s[])
            try
                Context initial = new InitialContext();
                Content myEnv   = (Context)initial.lookup("java:comp/env");
                Object o        = myEnv.lookup("ejb/Hello");
                HelloHome hHome = (HelloHome)PortableRemoteObject.narrow(o, HelloHome.class);
                Hello greeter   = hHome.create();
                greeter.displayMessage();
            catch(Exception e)
                e.printStackTrace();
    }See if that's better.

  • EJB + CORBA problems

    Hi there,
    I've got some code (EJB) which connect
    me to OLAPService on my 9i Oracle server. I deployed it to Oracle AS which
    is istalled on another machine. Then I wrote client application which has to
    connect to OAS and invoke EJB method to connect to OLAPService.
    The connection to EJB was successfully established (of course through a
    CORBA). But when EJB was trying to connect to Oracle9i I got such error :
    javax.naming.NameNotFoundException:
    sess_iiop://<server_ip>:<port>:<sid>/etc/OLAPServer/OLAPServer not found
    I think it something wrong with my OAS enviroment. I have tried to do my best , but still nothing .... ( I am sure that everything else is OK, because I tried to make connection through
    JDBC to relational database and it worked fine).
    When I'm starting EJB's code as client application everything is OK. The
    connection to OLAPService is established every time. When I modyfied code
    for EJB (commenting code responsible for preparing InitailContextEnviroment
    and connecting to OLAPService) everything was OK. So :
    1) I can connect and invoke EJB's method deployed to OAS,
    2) I can connect to Oracle9i OLAPService and use OLAPAPI methods,
    3) I can't do it when I try to connect to OLAPService through the OAS (where
    is EJB)
    client_application (java) ===CORBA===> OAS ( EJB with OLAPAPI) ==CORBA==>
    OLAPService
    This is the EJB's method code ( when it is calling as client application it
    works!!!!):
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import org.omg.CORBA.Object;
    import oracle.aurora.jndi.sess_iiop.ServiceCtx;
    import oracle.express.connection.Connection;
    import oracle.express.connection.ConnectionManager;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.*;
    public String Polaczenie()
    String serviceURL="sess_iiop://<server_ip>:<port>:<sid>";
    String objectName="/etc/OLAPServer/OLAPServer";
    Hashtable env=new Hashtable();
    env.put(Context.URL_PKG_PREFIXES,"oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL,<user>);
    env.put(Context.SECURITY_CREDENTIALS,<password>);
    env.put(Context.SECURITY_AUTHENTICATION,ServiceCtx.NON_SSL_LOGIN);
    try
    Context ic=new InitialContext(env);
    org.omg.CORBA.Object
    ServiceStub=(org.omg.CORBA.Object)(ic.lookup(serviceURL+objectName));
    Properties connParams = new Properties();
    connParams.put("UserID",<user>);
    connParams.put("Password",<password>);
    ConnectionManager cm=ConnectionManager.init();
    Connection conn=
    cm.connect((org.omg.CORBA.Object)ServiceStub,connParams);
    conn.close();
    catch(Exception e)
    return "\nError:" + e + "\n";
    return "\nIt works\n";
    This is client's code:
    public static void main(String[] args)
    try {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "ormi://sasza/SerwerEjb");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "oracle");
    Context context = new
    com.evermind.server.rmi.RMIInitialContextFactory().getInitialContext(env);
    Object homeObject = context.lookup("<myEJBName>");
    SerwerEjbHome home = (SerwerEjbHome)
    PortableRemoteObject.narrow(homeObject, pakiet.SerwerEjbHome.class);
    SerwerEjb remote = home.create();
    System.out.println(remote.Polaczenie()); <------------------ there is
    error !!!!!!!!!!!!!!!!!! ------------------>
    catch(Exception e)
    System.err.println("Error: " + e + ":::" + e.getMessage());
    Any idea ??
    Thank you in advance.

    "Taesun, An" <[email protected]> writes:
    Thanks for your concern !Its my code - I should be concerned :)
    I have successfuly tested the sample program that you attached.
    and I have some more questions.Great!
    Q1) Can I use idl files generated by weblogic.ejbc on the other ORB like as
    orbix, etc..?Yes. But the problem is that Orbix is known to have problems with the
    codeset that we send out. For silversword we are doing a GIOP 1.2
    implementation a by-product of which will be that we have to do some
    form of codeset negotiation, so hopefully these issues will be sorted
    in the near future.
    And I know that the Client.cpp program you sent differs from original source
    code in the respects which is including TradeResultFactory and
    TradeResultImpl classes.
    Q2) If so, Do i have to implement the above classes for all of call by value
    parameters or return type ?You have to write some C++ code for any valuetypes that you use. This
    basically means any non-primitive object that is not a remote
    interface and implements serializable.
    I wanna know for the needed classes how to easily get generated or the other
    solutions.I attach the entity bean example I cooked up which shows you how you
    can use C++ macros to take away some of this pain. Note that you cannot make the finder method work with 6.0SP2. This will be fixed in 6.1
    [generic_idl_entity.zip]
    I got error message following as, when i used "-idlFactories" of
    weblogic.ejbc option to generate Factory definition.
    Usage: java weblogic.rmic [options] <classes>...
    option descriptions ,.,........
    option descriptions ,.,........
    ERROR: Error from ejbc: Unrecognized option or flag, -idlFactories
    ERROR: ejbc found errors
    make: *** [ejbc] Error 1Hmm, you are right. It looks like the option didn't get inverted in
    rmic. The attached class file should fix this.
    [IDLGeneratorOptions.class]
    andy

  • Forms Service verification program problem

    I have a java verification program that is run from a HPUX server cron job to check
    the status of my 9.0.2.12.2 Oracle 9iAS Forms Services running on a
    Windows 2000 server. The program determines if the Forms Services
    restarted after a cold, off-hours backup by retrieving and reading
    base.htm.
    I have 3 windows servers with "identical" configurations of 9iAS Forms
    Services. The java verification program works when running against the dev and
    test Forms servers but not against the production Forms server. It
    did work against the production Forms server until I upgraded to
    9.0.2.12.2 a few months ago. The only way to reproduce the problem
    against the test Forms server is to rename base.htm so the program
    can't find it. default.env,forms90.conf,formsweb.cfg all appear to be
    identical. Paths and other environmental variables are identical on
    the windows Forms servers. The java program fails or succeeds
    consistently on 3 different HPUX servers both in cron and from the
    command line.
    The error message is: java.io.IOException: Server returned HTTP
    response code: 500 for URL:
    http://productionserver:7778/forms90/f90servlet
    Java is 1.3.1 on all environments.
    import java.io.*;
    import java.net.*;
    public class auRLTest
    public auRLTest()
    try {
    System.out.println("Starting...");
    URL url = new URL("http://productionserver:7778/forms90/f90servlet");
    System.out.println("Opening URL connection ("+url+")");
    URLConnection uc = url.openConnection ();
    System.out.println("Connecting to URL");
    uc.connect();
    System.out.println("Opening input stream.");
    BufferedReader in = new BufferedReader(
    new InputStreamReader( uc.getInputStream() ) );
    System.out.println("Reading file...");
    System.out.println("==========================================================================");
    String inputLine = in.readLine();
    while (inputLine != null)
    System.out.println(inputLine);
    inputLine = in.readLine();
    System.out.println("==========================================================================");
    System.out.println("Closing file.");
    in.close();
    System.out.println("Production Form Server is UP");
    catch( java.net.ConnectException connectException ) {
    System.out.println("***PRODUCTION FORM SERVER IS DOWN***.");
    catch( Exception exception ) {
    System.out.println(exception);
    public static void main(String[] args)
    auRLTest uRLTest = new auRLTest();
    Accessing "http://productionserver:7778/forms90/f90servlet" from IE works fine.
    Any clues or ideas are appreciated.
    Thanks

    I went through the same thing. Look at Appendix II "Case Study" at http://rootshell.be/~yong321/freeware/ckweb.html. Basically, the forms servlet needs some more HTTP headers you didn't pass.
    Yong Huang

  • Trying to open iTunes I got a error message of msvcr80.dll can not be found. I thought that it was an iTunes program problem. I tried reloading iTunes and then got an error message of a program is trying to acces a library file incorrectly. How can I reso

    When trying to open ITunes, I got an error message of msvcr80.dll can not be found.
    Assuming that it was an iTunes file, I reinstalled iTunes.
    Trying to open again, I got an error message of an appication is trying to open a library file incorrectly.
    How do I resolve this problem.
    Neither my PC with Vista nor my my laptop with windows 7 will work?
    Thanks

    Hello Msvcr80.dll,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iTunes 11.1.4 for Windows: Unable to install or open
    http://support.apple.com/kb/TS5376
    Check for .dll files
    Go to C:\Program Files (x86)\iTunes and C:\Program Files\iTunes and look for .dll files.
    If you find QTMovie.DLL, or any other .dll files, move them to the desktop.
    Reboot your computer.
    Note: Depending on your operating system, you may only have one of the listed paths.
    Uninstall and reinstall iTunes
    Uninstall iTunes and all of its related components.
    Reboot your computer. If you can't uninstall a piece of Apple software, try using the Microsoft Program Install and Uninstall Utility.
    Re-download and reinstall iTunes 11.1.4.
    Best of luck,
    Mario

  • EJB classpath problem when refering a DAO in library jar file

    Hi
    When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
    When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
    Thanks in Advance
    Best Regards
    Venugopal Balu

    Hi
    When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
    When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
    Thanks in Advance
    Best Regards
    Venugopal Balu

  • PAYMENT PROGRAM PROBLEM

    When i create a payment proposal today with posting date in the future and the items that have to be paid are in foreign currency the payment run program (that executed in the future date) create postings with exchange rate the rate of proposal creation date and not the posting date.
    Is there any solution to this problem?
    Version 4.6C
    Thanks in advance
    Elias

    Elias
    There are loads of SAP Notes about this.  You'll have to search for the specific one for your system.
    try http://service.sap.com/notes

  • Beginner with a programming problem

    I am getting quite frustrated trying to figure out how to proceed with a Java program I've been assigned. I'm hoping that my problem is not too amorphous to warrant assistance.
    The program is an exercise in Swing and creating GUI's, and at this stage, I only need to create an array of dice objects which can paint themselves on a JPanel. The instructor has given us two files -- one extending JPanel and containing a main method to test the classes, and another which represents a die.
    Some issues are
    1) I don't know where to call repaint.
    2) When the overridden paintComponent method is called, it wipes out
    the background color on my panel, which I set in the constructor.
    3) I got null pointer exceptions when I ran the instructor 's main method... I moved the setVisible up in the chain and they went away (Though he stated not to alter the main method, I don't know enough about Java Graphics to know if it's his mistake or mine)
    4) I'd just like to see some something appear.
    I should add that I rewrote this whole thing in one file (without using an array) and was able to get the graphics to paint.
    Sorry for posting copious amounts of code, but hopefully it will clear up what I'm trying to do. If anyone could just give me some pointers in the right direction, I would greatly appreciate it. Thank you for your time.
    //      File:  DicePanel.java
    public class DicePanel extends JPanel
      private int number_of_dice = 0;
      private DiceDrawn [] dice; 
      /** The x,y coordinates where the first die is drawn */
      private int xCoordinate = 5; //default
      private int yCoordinate = 5; //default
      /** Constructor with default properties */
      public DicePanel()
        this.setSize(getPreferredSize());
        this.setBackground(Color.blue);
        // set size and color
      /*  Set the Dice array  */
      public void setDice(DiceDrawn[] d)
      }// end setDice
      /** Return xCoordinate */
      public int getXCoordinate()
        return xCoordinate;
      /** Set a new xCoordinator */
      public void setXCoordinate(int x)
         xCoordinate = x;
      /** Return yCoordinator */
      public int getYCoordinate()
        return yCoordinate;
      /** Set a new yCoordinator */
      public void setYCoordinate(int y)
         yCoordinate = y;
      /** Paint the Dice Panel */
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        for (int i = 0; i < dice.length; i++ )
          dice.drawDie(g, xCoordinate, yCoordinate);
    setXCoordinate(getXCoordinate() + 41);
    // draw each die using default start coordinates,
    // moving right each time
    /** Override get method for preferredSize */
    public Dimension getPreferredSize()
    return new Dimension(200, 50);
    // the main method to test DicePanel and DiceDrawn
    // do not change this method.
    public static void main(String [] args)
    JFrame f = new JFrame();
    // f.setVisible(true);
    f.setTitle("Draw Dice");
    f.setSize(500,400);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = f.getContentPane();
    // show 6 dice initially
    DiceDrawn [] dice = new DiceDrawn [6];
    for(int i = 0; i < dice.length; i++)
    dice[i] = new DiceDrawn(i+1);
    DicePanel dicePanel = new DicePanel();
    dicePanel.setDice(dice);
    System.out.println(dice.length);
    cp.add(dicePanel, BorderLayout.NORTH);
    f.setVisible(true);
    // show only one die for the rest of the program
    dice = new DiceDrawn [1];
    System.out.println("Dice Drawn Class Test");
    int i = Io.readInt("Enter an integer between 1 and 6");
    while( i > 0 )
    dice[0] = new DiceDrawn(i);
    dice[0].setSelected( i%2 == 0 ? true : false);
    dicePanel.setDice(dice);
    i = Io.readInt("Enter an integer between 1 and 6");
    System.exit(0);
    // File: DiceDrawn.java
    public class DiceDrawn
    private final int SIZE = 36;
    private final int QUARTER = SIZE/4;
    private int face; // face value
    private boolean selected; // pressed = true
    public DiceDrawn( int f)
    setFace(f);
    setSelected(true);
    }// end DiceDrawn
    public void setSelected( boolean s )
    selected = s;
    public boolean isSelected()
    return selected;
    public void setFace(int i)
    face = i;
    public int getFace()
    return face;
    // Draw a die starting at the given coordinates
    public void drawDie(Graphics g, int xcoor, int ycoor)
    g.setColor(Color.WHITE);
    g.fillRect(xcoor,ycoor, SIZE, SIZE);
    g.setColor(Color.BLACK);
    switch(face)
    case 1:
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 2:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    break;
    case 3:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 4:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    break;
    case 5:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(2*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    break;
    case 6:
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + QUARTER, SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+(3*QUARTER), (ycoor-4)+(3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+(2*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ QUARTER, (ycoor-4) + (3*QUARTER), SIZE/8, SIZE/8);
    g.fillOval((xcoor-4)+ (3*QUARTER), (ycoor-4)+ QUARTER, SIZE/8, SIZE/8);
    break;
    // draw a die using a rectangle of 36 by 36 pixels
    // at the coordinates given.
    // use a switch statement to draw the appropriate face.
    }// end DrawDie
    }// end DiceDrawn

    Once you get beyond your initial problems, you'll find that there is another problem. When it displays the dice corresponding to the numbers you select, the x coordinate eventually becomes greater than the frame width. You need to make a change to the paintComponent method so it looks like:
      /** Paint the Dice Panel */
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        for (int i = 0; i < dice.length; i++ )
          dice.drawDie(g, xCoordinate, yCoordinate);
    if(dice.length > 1)
    setXCoordinate(getXCoordinate() + 41);
    // draw each die using default start coordinates,
    // moving right each time
    Note that I have added an if above the setXCoordinate so that it will only add to the X coordinate when it is displaying the 6 dice initially. It won't add anything when it is displaying the single dice.

  • EJB Persistence problem [Data modified outside EJB]

    Hello,
    There is an EJB in the system which corresponds to a db table, say it "AppBean", and a corresponding session bean AppSession which provides insert/remove/query service. There is another program, a webapp which might runs on another server, also makes modifications to that table.
    But the EJB seems to be totally unaware of data changes made by others ... Is there a simple mechanism that would allow notification to the EJB to ask it to reload data from DB? JMS or MDB seems to be too complicated ...
    Thanks in advance.
    layman

    Hello,
    Thanks for your reply first.
    Do you mean that the webapp shall call the EJB's
    ejbLoad method in remote interface? or is there anyway
    to set a "validation" flag, as we do to Session State?Well, I actually mean that shall the webapp call the EJB's ejbLoad through it's local interface(ejb-local-ref in web.xml)? Isn't there some more elegant way to achieve this? A Java guru told me that JMS might be an "easy" way, but I know almost nothing about that.
    tHANK YOU.
    layman

  • EJB deployment problem --New remote interface class files are not loaded

    Hi, I face a problem while deploying an ear file in oc4j. I basically get some problems like the method in the remote interface is not implemented in the EJB class. But the implementation is actually available in the EJB class.
    We get this problem when we actually change the signature of the EJB remote methods. The new methods are not referenced by oc4j. Only the old version of remote interface is referenced by oc4j. But the latest version of EJB class is taken. I am using 9.0.3 version of the oc4j. Could you pls help me regarding this problem ?
    Regards
    Solomon

    I have found the solution :-)
    You must add to the ejbCreate() method of the bean class throws javax.ejb.CreateException

Maybe you are looking for

  • Audio too loud on my MacBook Air!

    So, I just purchased my MacBook Air from Best Buy (as an Open Item since there was an awesome markdown plus coupon markdown on top of that, and 18 months financing is pretty cool too).  My problem is that the sound is extremely loud on this system, e

  • HT4759 How can I get a the OS 10.5 cd sent to me I am still on OS 10.4 and my Mac will support the software

    Please Help, I just bought my IPhone 4s and set up icloud account, however my mac is still on OS 10.4 and I saw a thread that indicated that new 4s owners on icloud can get a free copy of the Upgrade cd for os 10.5. I can't even find how to buy the c

  • Slimbox not working with Spry Dataset

    Hi there, I'm trying to populate a page with Spry Dataset and use Slimbox2 to show a set of 4 images when a thumbnail is clicked. The original webpage WITHOUT Spry Dataset is here: http://shadowmuseum.com/portfolio/p-web.html Currently it works with

  • Displaying images from database

    Hi, I am creating a real estate site, and I need a thumbnail and full size image to display. I'd like to store the images in respective folders under the Images folder on the server, and store the file name in the database. I can't get the images to

  • Account assignment category in bapi_pr_create.

    Hi All,     While using account assignment category F in PRITEM table of BAPI_PR_CREATE and marking appropriate flag = X in  PRITEMX    table requsition is creating but also an error message is coming "enter G/L account" although i am passing it .