Java spaceshooter design

Hey all,
i've been making a spaceshooter in java, but now i'm having design problems. my code is apparantly inefficient and lags like crazy on certain comps, but works fine on good comps. i've experimented with threading, but dont know an efficient way to thread. So far i have a thread to update drawing, a thread to updte movement, and a thread to check 4 all collisions. i also have a bunch of random threads that certain objects create, but thats not that big of a deal. also i'm using particle effects to create a shot, but thats the one thats causing the greatest lag as it hsato loop through to draw each tiny piece. Anyway i'm confused right now on how to make an efficient design so i'm asking for ideas and help on how to create a design. plz help all u can and plz dont flame me =(

hmmm aiight. my code is somewhat confusing...wud anyone mind telling me how they wud do it? neway here's my code:
//code from SimpleEnemy.java  
EnemyShotPiece p=new EnemyShotPiece((int)Math.round(x), (int)Math.round(y));
pieces.add(p);  //pieces is a vector of EnemyShotPiece
int length=pieces.size();
for(int i=0; i<length; i++)
     if(pieces.get(i).radius()<=0)
          pieces.remove(i);
          i-=1;
     length=pieces.size();
//out.println((" "+pieces.size()));
for(EnemyShotPiece ep:pieces)
     ep.move();
     ep.draw(g);
public class EnemyShotPiece extends MovingObject
     double radius;
     int step=0;
     public EnemyShotPiece(int row, int col)
          super(row, col);
          //this.direction=direction;
          //this.speed=speed;
          //out.println(direction*(180.0/Math.PI));
          radius=10;
          //player=p;
     public void draw(Graphics g)
          //move();
          //out.println(row.get()+" "+col.get()+" "+radius);
          //g.drawArc(row.get(), col.get(), (int)Math.round(radius), (int)Math.round(radius), 0, 360);
          Graphics2D gg=(Graphics2D)g;
          //Color coll=gg.getColor();
          //gg.setColor(new Color(random.nextInt(256),random.nextInt(256),random.nextInt(256)));     
          Paint p=gg.getPaint();
          final GradientPaint gp=new GradientPaint(3, 3, Color.orange, width()/2.0f, height()/2.0f, Color.red, true);
          gg.setPaint(gp);          
          Ellipse2D e=new Ellipse2D.Double(row.get()+radius/2, col.get(), radius, radius);
          gg.fill(e);
          //gg.setPaint(Color.green);
          //gg.setStroke(new BasicStroke());
          //gg.draw(e);
          //gg.setPaint(gp);
          gg.draw(e);
          //e.setFrame()
          //gg.setColor(Color.ORANGE);
          //gg.drawOval((int)Math.round(row.get()+radius/2), (int)Math.round(col.get()), (int)Math.ceil(radius), (int)Math.ceil(radius));
          //gg.fillOval((int)Math.round(row.get()+radius/2), (int)Math.round(col.get()), (int)Math.ceil(radius), (int)Math.ceil(radius));
          //gg.setColor(coll);
          gg.setPaint(p);
          //g.fillOval(row.get(), col.get(), (int)Math.round(radius), (int)Math.round(radius));
     public void setImage()
     public int radius()
          return (int)Math.round(radius);
     public void move() //object doesnt move itself, only radius gets decremented
          radius-=.5;
}sorry if the code is knda funky, i had a lot of test statements in there.

Similar Messages

  • Java EE design advice for a re-designed DB app

    I'm currently tasked with rewriting a legacy DB app in Java. The original was written in Delphi. It worked great for a number of years, but the powers that be have recently decided to redesign and rewrite it in Java. Basically I just have the same set of business requirements as the original did.
    Overall, the app is a desktop GUI application that helps track contents of a natural history museum collection. The collection contains a bunch of specimens (dead animals) collected all over the globe at various times over the last 200 years. Multiple users (1 - 10 uesrs) will have to have access to the data at the same time. I also have to provide a nice Swing GUI for it.
    Here's my question: Is this the type of app that lends itself to a Java EE design? I'm imagining using a Java EE app server that connects to the DB. The app server would provide DB access, producing entity beans, as well as managing a number of session beans (EJBs) that implement the business logic (security, user management/session management). I would also have a Swing GUI that would connect to the beans remotely. This sounds like it would help me keep a good disconnect between the UI layer (Swing), the business logic (EJBs), and the data layer (entity beans accessed using the Java Persistance API). Does this sound reasonable? I'm a veteran Swing developer, but not a seasoned Java EE developer/designer.
    Also, if I use this architecture, I can imagine one issue that I might run into (I'm sure there are many others). I can imagine that I would want to retrieve the entity beans (lets say mypackage.MyPersonBean) through some call to an EJB, and then use the bean in some rendered Swing component. What happens when the Swing component needs to access the results of MyPersonBean.getAddresses() if the addresses are lazy loaded?
    As you can probably tell, I really have more than one design question here. Help/comments about any of this is greatly appreciated.

    I was thinking the same thing, but don't have a
    successful experience to validate my gut feelings.
    Here's my only suggestion (which dubwai could
    hopefully confirm or correct): write your entity
    classes/data model classes with no knowledge of
    lazy-loading etc. Then subclass them, overriding
    just the getChildren() type of methods and build the
    lazy-loading knowledge into the subclass.More or less, yes. Don't over-think it, though. If you define your basic data 'types' as interfaces, you don't need to get into complex type hierarchies or multiple versions of the types unless that becomes necessary and if it does, the changes should not affect the presentation layer.
    Since you are on-board with this and I think you are completely following, there is a technique for the lazy loading that you can use here.
    In the case where it's a one-to-one relationship, you can do the lazy-loading by creating a simple wrapper class for the child object. This class will have a reference to either null or a filled in Object. This is a little more OO because the Object is taking care of itself. Whether this abstraction is useful to you, you will have to decide.
    In the case of a one-to-many relationship, you can create a custom Collection (List or Set) that manages the stub loading. If you make a generic abstract version and subclass it for the different child types, you might be able to reuse a lot of the data retrieval code. You can do the same thing with the wrapper too.
    I will caution you to try to keep it as simple as you can without painting yourself into a corner. Only do things that you are going to use now and write things so they can be expanded upon later. Reducing coupling is a core technique for that.
    When the
    GUI asks for an object in the getData() call, hand
    them a subclass object, but don't let them know it.
    In other words, have the method "public DataClass
    getData()" return a SubDataClass object. The caller
    will only know that they received a DataClass
    object, but lazy-loading awareness will be built
    into it. This way, the lazy-loading stuff is
    completely transparent to the caller but you still
    have simple data classes that can be used outside of
    a lazy-loading context.Yes this is the idea, but don't write the other versions until you need them.
    It's also possible to use
    this method if you need to add transparent
    lazy-loading to classes that you aren't the author
    of. (Only classes that have been tagged 'final' or
    have 'final' public methods would be beyond this
    method's reach.)Yes, you can use the wrapper approach above but if the author of that class made a lot of unecessary assumptions you might have trouble.
    This approach allows for some enhancements, too.You
    can create a thread that retrieves the children of
    Foo (e.g. bars) incrementally after the Foo is
    returned to the caller. Often you can load the
    bars
    in the time it takes the user to click around to
    the
    point where they are needed or at least be partly
    done. This will make the app seem very fast to the
    user because they get the Foo very quickly (because
    you didn't load the chidren) and then the bars
    really
    quickly (because you loaded them during user
    'think-time').
    I love this idea. I'm hoping to code this into my
    GUI app soon.I would advise that you get the main lazy-loading working without this (keep in mind when writing the code) and do it once you are sure you will finish on time.

  • Java is designed to have a look and feel equivalent to????

    Java is a programming language designed to have a look and feel equivalent to:
    a. VB
    b. C++
    c. Cobol
    d. NotesScript
    Cheers!

    If you mean look and feel from a language perspective, Java was heavily influenced by C++.
    Since this is a multiple choice question quoted verbatim from either a textbook or your homework, I assume that you aren't really interested in any more information than that.

  • Java/OO Design question.  Please help!

     

    Brian,
    I'd say your better off trying the
    weblogic.developer.interest.ejb newsgroup
    or alternatively try the discussion forums in
    www.theserverside.com
    or
    http://forum.java.sun.com/
    For what its worth I'd return an empty array rather than an exception as I associate
    exceptions with real errors whereas a search that happens to return nothing is a
    valid result.
    Cheers,
    mairt
    "Brian Snyder" <[email protected]> wrote:
    >
    I'm certain this is not the best forum for my question, but I didn't any
    other
    that seemed obvious.
    I have a design issue/ OO question. Our system has the very common requirement
    of searching. We have build a session EJB which actually performs the search
    and returns a collection of Value Objects back to the client. My question
    is
    this: If the search EJB finds no matching records, what is the correct
    strategy
    for dealing with it?
    1) Throw an application exception, such as "NoDataFound", which the client
    can
    catch and handle appropriately
    2) Simply return a null collection. In which case, the client will have
    to check
    for null, and redirect program appropriately.
    3) Simple return type, such as boolean, for the method -- indicating success
    or
    failure (meaning no records found).
    4) Something entirely different. If so, what?
    Your thoughts on this subject would be greatly appreciated!
    Thanks!
    Brian

  • Using NetBeans Java ME Designer for List

    I'm using the Java ME screen Designer in NetBeans. I'd like to create a simple list from which users can select one option. I know how to write code to do it, but how do I do it through the screen designer?

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import javax.xml.ws.BindingProvider;
    import weblogic.wsee.security.unt.ClientUNTCredentialProvider;
    import weblogic.xml.crypto.wss.WSSecurityContext;
    import weblogic.xml.crypto.wss.provider.CredentialProvider;
    you can add username for weblogic client using
    // Create list of credential providers
    List credProviders = new ArrayList();
    // Create user name token provider
    ClientUNTCredentialProvider unt = new ClientUNTCredentialProvider("weblogic", "weblogic");
    credProviders.add(unt);
    credProviders.add(cp);
    // Finally add the credential providers to the request context
    Map<string, object=""> requestContext = ((BindingProvider)brokerService).getRequestContext();
    requestContext.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);

  • Comparing performance of different Java code designs - benchmarking

    Here's the problem:
    How do I run the java compiler (preferably Sun's javac) without getting any compile time optimization?
    I'd like to be able to compile a number of different programs to java bytecode - without having any optimization done by the compiler.
    The metric I want to use on the design of these programs is the "total number of bytecode instructions executed".
    The designs I want to compare can be reduced to "straight-line programs" with no conditionals or loops so I can learn a lot just by looking at the bytecodes emitted the compiler.
    Any pointers or help greatly appreciated.
    Cheers,
    Dafydd

    CORBA is supported by Windows machines (Windows XP/2000 as I know of it) and other APIs may be bought or included in some enterprise applications.
    RMI and CORBA are about as fast as each other. RMI-IIOP is slower then RMI and CORBA, however, it can sometimes go a little faster depending on deployment and environment.

  • Java enum design issue

    Just want to know any suggestion or is there any problem in the following class:
    public class VoltageLevel implements Serializable {
    public final int HIGH;
    public final int MED;
    public final int LOW;
    public VoltageLevel(int high, int med, int low) {
    HIGH = high;
    MED = med;
    LOW = low;
    The client will request for this class from RMI server, that's why it implements Serializable. Is there any problem with the design? Thanks.

    In future, please format your code before posting. For more info see:
    http://forum.java.sun.com/faq.jsp#format
    Then before posting, preview it.
    I know your code is short, thus easy to read, but its a good habbit to get into. The easier you make it for people to examine your code, the easier it'll be for them to find your problem.
    Now to your issue, the (now formatted) code:
    public class VoltageLevel implements Serializable {
        public final int HIGH;
        public final int MED;
        public final int LOW;
        public VoltageLevel(int high, int med, int low) {
            HIGH = high;
            MED = med;
            LOW = low;
    }This code does not implement an enum pattern that I know of. Why?
    1. HIGH, MED and LOW are all instance variable, i.e. associated with a particular VoltageLevel instance. With enums, the enum members are declared stated.
    2. You can construct multiple instances of VoltageLevel, and give the instances different values for HIGH, MED and LOW.
    3. ... there are several other reasons why.
    Maybe you are trying to something a little different, like create "families of enums", where each enum is represented by an instance of VoltageLevel. But this doesn't make sense to me. With your current definition, all three enum elements can take on the same value, thus aren't distinct, thus aren't an enum.
    For an example of integer based enums, check out
    http://java.sun.com/products/jdk/1.2/docs/api/java/awt/Scrollbar.html
    More modern approaches to enums use other techniquies the "type safe enum". An introduction to this approach can be found at:
    http://www.javaworld.com/javaworld/javatips/jw-javatip27.html
    However, it needs extra work to be Serialisable. But it can be done. This approach also has shortcomings that you should understand - if you deal with multiple classloaders, then you have issues. Otherwise, you're ok. But its worth knowing the bounds of applicability of the approach.
    Maybe if you could tell us a little more about how you intend to use this "enum", more specific guidance could be provided. Sample (relevant and formatted) code is always welcome - not on the serialisation side, but on the usage side - creating them, checking their values.

  • Java programme design

    hi there!
    i've created a java programme and i want to do a class diagram. by making a design of the classes i realised that for example, a class is being called by 2 other classes and it calls 2 ither classes itself. is this normal or it means it's badly designed??
    thanks :)

    cause in most of the class diagrams i have seen (i guess i have only seen diagrams of relatively simple programs) classes don't call many classes and are not being called by many other classes. in case my english doesn't make sense, class diagrams i've seen are simpler so i thought this might be a software problem..
    is it normal classes calling a lot of other classes and being called by many other classes too??

  • Java Bean Design

    Hello All,
    My problem is.. i have a JSP page in which i have a set of JobID, trainId and Crew.
    I can have a multiple rows of jobid, trainid and crew as shown below.
    I have to design a java bean for this JSP. One way is to have a get and set methods of all the fields of the JSP. But if i go with this approach there will be so many get and set methods defined for the same type of JobID.
    Is it possible to make a object for each row.
    if yes then please let me know how to go about it.
    JobID TrainId Crew pickup dropOff
    JobIDOne TrainIdOne CrewOne pickupOne dropOffOne
    please help me out....
    thanks and regards,
    rajesh

    you can look as this set of JobID, trainId and Crew as table's content
    so you needn't write all of set and get method
    just use table's api to operate.wish that's do it

  • Welcome.java - Microsoft Design Environment Opens Problem

    I tried the Welcome.java and got it to compile. The problem is when I launch it from the command prompt it open up in the Microsoft Design Environment , is there some way to prevent this? I can't launch it from the MDE either.
    thanks

    How do you launch it? What command do you use?
    Try doing it directly ie c:\java14\bin\java myClass
    I would take a look at your "path" environment variable to see which app is getting invoked. Particularly the windows\system32 folder.

  • Java Mapping Design Question

    Hi All,
    I have a Java mapping requrement for which I would like some suggestions.
    I have 3 variables:
         1) price
         2) price factor
         3) pricing condition
    There is already quite a bit of logic determining these.
    The new requirement is that if the price has a precision greater than 2 (eg 1.234 but not 1.23) then:
         1) set price = price * 10
         2) set price factor = 10
         3) set pricing condition = "ZMPE"
    Since it is unclear to me that there is an easy way to modify the current logic, I would rather try to take the current output for these 3 variables and override their values in the way described above. (I did try modifying the current logic but I have found it gave me problems.)
    So is there a simple way that I can take the current values and override them in the way described. For instance can I do this with a single User Defined Function.
    Thanks in advance.
    Cheers
    Gerard

    Hi Gerard - Please check the below screenshot.. (just change the type to result so that it'll be your output parameter.)
    edited : removed "remove context"

  • Database trigger in java and design

    Hi Experts,
    I have develop a system which query table after every three second and get new records and do processing, i expect lot of people suggest to use database trigger option, but i have following constraint.
    I am using Oracle 10g which is available on remote site and i have only access of 1521 port. This database is used by other departments also and we are give one user and i can only use JDBC for all my work.
    Please suggest any good alternatives or i stick with database polling?
    Regards,
    imran

    emmi@java wrote:
    Hi malcolmmc,
    Thanks for your reply but i have only 1521 port available and as i know JMS use different port for communications.If you talk to your systems people it may not be a restriction. Depends what you're allowed to put on the server. Typically the JMS client stuff on the database would connect to a central message broker, which might be at your end. The server may have wider access to ports on your machine than the other way arround.
    >
    Second if i have to do DB polling, is it good to run while loop with Thread.sleep?
    Or java.util.Timer().
    Do close your Statement objects while waiting though, don't tie up resources in the server.

  • Java System design Question

    Hi,
    I am new programmer and have been assigned the task of replacing an old system with a new one . The old system was done using Access 97 VBA. Both the backend(database) and the frontend ( in Access VBA). It is basically a database system which, retrives information, does computation and all that.
    Now we plan to change it with a server running linux , mysql database on the same server. I was thinking of doing the whole thing in Java . There will be like 45 people working on the system at the same time , some on the web .. which i plan to use JSP. I want most of the things to look the same so that people using it will not have too much trouble becasue they are used to the old system.
    I just need to know if this a good idea ..
    I would be very glad if someone could help me with this .. I don't want to make a blunder here ..
    Thanks,
    sdsouza

    "kinda cross posted"??? It was, and then you cross the cross post with cross posted complaints about cross posting. Cross posting really bothers you don't it? Well, see, I don't think you'll ever stop it, unless you rewrite the forums to be more intelligent about postings. So I wouldn't worry about it... give an answer or don't. (I gave one in the other post...)

  • Help with Java Applet Design

    Hi,
    I'm a uni student and I've had some programming experience in Java, although sadly a bit lacking in the area of Java Applets.
    Recently I've being involved in a project where some tests are ran a number of times and a Data Aquisition System is used to transfer the number of cycles the test have currently done onto the computer, in a .csv file.
    What I would like to do is to make this count available in a web browser LIVE.
    I've come up with an idea, which is to write a Java Applet to read this file and output the correct count value in a textbox or what ever, however I am having a bit of difficulty making this update live.
    Should I have some sort of script inside the webpage source that re-
    runs the applet at regular intervals? If then how would that be possible?
    Or should I have the applet re-read the file at regular intervals and repaint it-self? If then there will be problems with timers and possible execution threads (which I don't quite understand yet)?
    One thing I want to be careful of is that this file to be read is updated by the DAQ system at random times, so whatever solution is implemented, I wouldn't want the file to be corrupted (e.g. if the file is read and written at the same time).
    Thanks for any help

    Read data from file at regular specified intervals,
    display data in an applet.
    U can use java.util.Timer and TimerTask and schedule the task.
    for applets to read file, you may have have to sign the applet.
    public class ReadApplet{
    private Timer timer;
    private TimerTask tt;
    private JTextField tf;
    public void init(){
    tf=new JTextField(15);
    timer=new Timer();
    tt = new TimerTask(){
    public void run(){
    try{
    BufferedReader fr=new BufferedReader(new FileReader(datafile));
    String data = br.readLine();
    int num = Integer.parseInt( data);
    tf.setText("" + num);
    }catch(Exception e) {}
    timer.schedule( tt, 0, interval);
    - create a jar file containing the class file
    - generate a key using keytool -genkey
    - sign the applet jar with jarsigner -signedjar using your key
    -include applet code in html file
    <applet code="Yourapplet.class" ARCHIVE="your signed jar" width="" height=""></applet>
    It should work

  • Good Java GUI Designer... & UML Eclipse Plugin...

    Hi,
    Im starting my final year project in september & while I have some free time I wanted to get prepared and set up my development environment.
    Im going to be using Eclipse for the IDE which is fine.
    But I need a GUI designer, so I can throw a GUI together quickly so I can get a prototype out for December.
    But I have searched High and Low for one and threre does not seem to be a decent (free) one about Jigloo seems to have problems on my mac and does not seems to be that good.
    Any suggestions?
    Also can anyone recommend and good UML plugin for eclipse?
    Message was edited by:
    ChrisUK

    Why not use Netbeans? I don't think you will find a better GUI builders than Matisse.
    I have used Jigloo, it is okay but I would rather build my GUI in Netbeans and then import my code to Eclipse.
    I have never used any UML plug-ins for Eclipse but I have used Poseidon which is free for non-commercial use and a pretty cool UML designer.
    http://www.gentleware.com/uml-software-community-edition.html
    http://www.netbeans.org/kb/41/flash-matisse.html

Maybe you are looking for