Application or Applet?

Hello, I'm in the works of developing a MMORPG in java.
My quest is would it be better to write it as an Application or Applet?
I know writing it as an application I will be able to save, and do other things without the troubles of the *security stuff in java. While if I make it an applet I may have troubles with security...
Though then again I will be using a java server/sql. So I wont have to worry about that to much, however, if I have the game available for offline and online then there may be problems.
Anyways was wondering what everyones opinions are on this matter?
Thanks
-Shaun Strickland

Hmm, should have worded that diffrently. After posting I realized they have diffrent categories =)...

Similar Messages

  • Managing Connections in a desktop Application or Applet

    Wondering how people usually manage connections in a fairly large GUI application (or Applet).
    I'm used to using a Connection Pool with Servlets.
    Is this worth using with an Application or is it ok to create a Connection at startup and use it throughout the whole execution?
    Is it ok then to pass references to this Connection to other classes in the application?
    Any tips, experiences, guidelines would be appreciated.
    Thanks.
    Derek

    Hi
    I'm assuming that you are using a J2EE Application Server that implements datasource pooling if you have the ability to use Pooled Connection with your servlet (if not, then you must have created your own connection pool?).
    Basically, if you have an Applet, then there is no reason to change your current way of working...simply let a servlet in your container handle the database stuff, then return the results to the Applet.
    For desktop standalone applications, things are a bit different. You will probably have to implement your own pool. Best practices...hmm...not an expert but I would have thought it best to open the connection, do the SQL stuff, then close it straight away, and in doing so release the connection back to the pool for another application to use (assuming you have a pool). If you are thinking about opening a connection for every application and holding these indefinitely, then you will eventually run into trouble. How many connections can your database handle???
    Hope that helps

  • Start application from applet

    Hi there!
    I have to start an application from applet (is not my idea, i HAVE to do it). That menas (i think) i have a little problem with the java "sand box". How can i make my program run out of it? Signed Applets? Are there also other possibiliys? Can i make as "privat person" signed Applets?
    Thank's

    This is SAX-parser for XML processing. The XML-files are local saved, also the applet and the application. The Parser application seems to start, but (sic!) there is no output, even though the application is OK...

  • Building applications with applets

    Hi,
    I want to modify my applet so it can be used to build an application. From within the applet, I need a way to tell if I'm running as an applet in a browser or as an application ( I need to do this, so I dont go making URLConnections, etc when I'm running as an application ).
    I'm also limited to JDK 1.1.x.
    thanks in advance,
    rob

    If an applet is being run as an application, the main method will have to be called. This method will never be called when run as an applet.
    Generally, when wrapping an applet in a application, the window creation functions are also handled in main. It would be relatively easy to set a flag when instantiating the applet (say as an instance variable on the applet itself) to let it know if it was running as an applet or as an application
    Jason

  • Intranet:application or applet???

    Hey All
    I have an application...is it possible to make that application available to everyone in the intranet??? or do i have to convert into applet so that it is run thru an html file????

    my application is a simple one...allows the user to choose an option and then opens a text file with the user selected option in it, where user is allowed enter data and the text file is sent to concerned person thru email...
    now to run this application thru home page of our company intranet should this b converted into applet?? i tried to run this application from an applet..but the opening text file and sending email part of the application didn't work....
    or should i go with java web start????
    thanx
    bharthi

  • Run application or applet on any windows machine

    OK, here is my question. If I write a application using swing, and then build the application into jars, can I take that app and run it on any computer, or does any computer I run it on need the jdk installed on it. The reason I am asking this, is a am writing some simple software using swing as a GUI. I want other user's to be able just to copy this app from a disk, set it on their computer and run it. Will this work, are will it work if I use applets. Please let me know.

    what do you mean by make a webservice app or use webstart/jnlp

  • Works in application, not applet, why

    connection = new Socket(
    InetAddress.getByName("mailbox.oneonta.edu"), 25);
    this line works in my application but i get a java.security.AccessControlException when i try to use the code in an applet. can anyone help?

    I think there is more then enough great documentation on this very site to help you out. Explaining things like how to sign an applet, or a jar, that are docuemented so your little sister can do it is a waste of time. I'm not being rude at all, I'm trying to get you to use the resources of this site. The java tutorials is a great place to start.

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • Converting application to applet.... please Help

    This program shown works fine in appletveiwer however will not work with I.E. nor Netscape. I do have the java plugins for both and using a netscape version over 6.0. I made the program usint jdk1.3. Can anyone please help me out?
    java code
    // TabbedPaneFlags.java: Use tabbed pane to select figures
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TabbedPaneFlags extends javax.swing.JApplet
    // Create a tabbed pane to hold figure panels
    private JTabbedPane jtpFigures = new JTabbedPane();
    // Load Images
    private JLabel lblUSA = new JLabel(new ImageIcon("USA.gif"));
    private JLabel lblUK = new JLabel(new ImageIcon("uk.gif"));
    private JLabel lblGER = new JLabel(new ImageIcon("germany.gif"));
    private JLabel lblCAN = new JLabel(new ImageIcon("canada.gif"));
    private JLabel lblCHI = new JLabel(new ImageIcon("china.gif"));
    private JLabel lblIND = new JLabel(new ImageIcon("india.gif"));
    // Main method
    //public static void main(String[] args)
    // TabbedPaneFlags frame = new TabbedPaneFlags();
    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // frame.setSize(450, 350);
    // frame.setVisible(true);
    // Constructor
    // public TabbedPaneFlags()
    public void init()
    // setTitle("Tabbed Pane Demo");
    jtpFigures.add(lblUSA,"USA");
    jtpFigures.add(lblUK,"UK");
    jtpFigures.add(lblGER,"Germany");
    jtpFigures.add(lblCAN,"Canada");
    jtpFigures.add(lblCHI,"China");
    jtpFigures.add(lblIND,"India");
    // Place tabbed pane
    this.getContentPane().add(jtpFigures, BorderLayout.CENTER);
    html code
    <html>
    <head>
    <title>AppletMenuDemo</title>
    </head>
    <body>
    <applet
    code = "TabbedPaneFlags.class"
    width = 450
    height = 350
    alt="You must have a JDK 1.2-enabled browser to view the applet">
    </applet>
    </body>
    </html>

    You should try the html converter so that the browsers are forced to invoke their plugin... or prompt the user to download one.
    To turn an applet into an application is easy. You act like the browser. You make a frame, construct the applet, and put the applet in the frame, (They are components) ... Then just call the init() method. Then add a window listener to call the stop() method when the frame gets closed.
    Application to an applet is a bit harder. You need to figure out what needs to be in the init method. Depending on what the application does you can also run into security issues.

  • Help on moving of image across screen(java application,not applet)

    I've searched the entire internet and everything I've found is on java applets and I'm an alien to the differences between an applet and an application.
    This is actually for a java game I'm creating using Eclipse's visual editor and I'm failing miserably.
    What I'm trying to do is to find some java source code that enables me to start an image automatically moving across the screen that only stops when I click on it. I did find some applet codes but when I tried converting it to application code a load of errors popped out.
    Thanks for the help if there's any! I'm getting desperate here because the game's due this friday and I'm stuck at this stage for who knows how long.

    Here is one of the codes I found ,it's not mine but I'm trying to edit it into a java application instead of an applet...Sort of like: ' public class MovingLabels extends JFrame ' or some code that I can copy and paste into another java program.
    * Swing version.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MovingLabels extends JApplet
    implements ActionListener {
    int frameNumber = -1;
    Timer timer;
    boolean frozen = false;
    JLayeredPane layeredPane;
    JLabel bgLabel, fgLabel;
    int fgHeight, fgWidth;
    int bgHeight, bgWidth;
    static String fgFile = "wow.gif";
    static String bgFile = "Spring.jpg";
    //Invoked only when run as an applet.
    public void init() {
    Image bgImage = getImage(getCodeBase(), bgFile);
    Image fgImage = getImage(getCodeBase(), fgFile);
    buildUI(getContentPane(), bgImage, fgImage);
    void buildUI(Container container, Image bgImage, Image fgImage) {
    final ImageIcon bgIcon = new ImageIcon(bgImage);
    final ImageIcon fgIcon = new ImageIcon(fgImage);
    bgWidth = bgIcon.getIconWidth();
    bgHeight = bgIcon.getIconHeight();
    fgWidth = fgIcon.getIconWidth();
    fgHeight = fgIcon.getIconHeight();
    //Set up a timer that calls this object's action handler
    timer = new Timer(100, this); //delay = 100 ms
    timer.setInitialDelay(0);
    timer.setCoalesce(true);
    //Create a label to display the background image.
    bgLabel = new JLabel(bgIcon);
    bgLabel.setOpaque(true);
    bgLabel.setBounds(0, 0, bgWidth, bgHeight);
    //Create a label to display the foreground image.
    fgLabel = new JLabel(fgIcon);
    fgLabel.setBounds(-fgWidth, -fgHeight, fgWidth, fgHeight);
    //Create the layered pane to hold the labels.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(
    new Dimension(bgWidth, bgHeight));
    layeredPane.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (frozen) {
    frozen = false;
    startAnimation();
    } else {
    frozen = true;
    stopAnimation();
    layeredPane.add(bgLabel, new Integer(0)); //low layer
    layeredPane.add(fgLabel, new Integer(1)); //high layer
    container.add(layeredPane, BorderLayout.CENTER);
    //Invoked by the applet browser only.
    public void start() {
    startAnimation();
    //Invoked by the applet browser only.
    public void stop() {
    stopAnimation();
    public synchronized void startAnimation() {
    if (frozen) {
    //Do nothing. The user has requested that we
    //stop changing the image.
    } else {
    //Start animating!
    if (!timer.isRunning()) {
    timer.start();
    public synchronized void stopAnimation() {
    //Stop the animating thread.
    if (timer.isRunning()) {
    timer.stop();
    public void actionPerformed(ActionEvent e) {
    //Advance animation frame.
    frameNumber++;
    //Display it.
    fgLabel.setLocation(
    ((frameNumber*5)
    % (fgWidth + bgWidth))
    - fgWidth,
    (bgHeight - fgHeight)/2);
    //Invoked only when run as an application.
    public static void main(String[] args) {
    Image bgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.bgFile);
    Image fgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.fgFile);
    final MovingLabels movingLabels = new MovingLabels();
    JFrame f = new JFrame("MovingLabels");
    f.addWindowListener(new WindowAdapter() {
    public void windowIconified(WindowEvent e) {
    movingLabels.stopAnimation();
    public void windowDeiconified(WindowEvent e) {
    movingLabels.startAnimation();
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    movingLabels.buildUI(f.getContentPane(), bgImage, fgImage);
    f.setSize(500, 125);
    f.setVisible(true);
    movingLabels.startAnimation();
    }

  • Application and Applet

    Is it possable to run one program that reads in values threw a normal java application and then calls on an applet to display something?

    It sounds like you haven't grasped the fact that you can write a straight Swing application with a full graphics interface which isn't an Applet (I must admit that when, somewhere back in the age of the dinosaurs, I first started to read about Java I was confused by the emphasis on applets, which are really not very useful).
    Such an application has a main() method as usual, but all that the main() usually does it to create an object which extends JFrame and call setVisible(true) on it. From that point all the action is in response to user generated events on the window.

  • Run application from applet

    is it possible to run an application from an applet? is so how can i go about doing this?

    hey may be the use of Runtime can help u solve ur
    prblm....
    Runtime.exec("Application name");luck,
    jayNope. You should know some basic things before trying to give answers.
    If (unsigned/untrusted) applets could just run any other app, imagine the chaos when someone hits a rogue website containing an applet that executes something like "format c:"
    You want to run an external program on the client's machine from an applet? You can't, thank heavens. You need to rethink your design.

  • Java card application and applet

    Hi
    I' am developing a java card application which has three applets (1-ID, 2-Purse, 3-Library). I mean the same card should be use for personal ID, purse, and as library card. Using eclipse I first have to create a new project.
    File-New-New project-java card project. Then in the package Explorer view right click src then New-other-java card Applet. My question is because my java card application has more than one applet how do I add the other two. Should I add the other two by clicking src again or just add them under the same source code belonging to the java card Applet created at the beginning.

    you mean by again doing right click src then New-other-java card Applet.

  • Errors running converted application (from applet)

    I've converted some codes (applet) into an application. When I run the application, I can see the GUI, but the application reports error as follows:
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at swarmCanvas.paint(Swarm.java:192)
         at sun.awt.RepaintArea.paint(RepaintArea.java:298)
         at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
         at java.awt.Component.dispatchEventImpl(Component.java:2663)
         at java.awt.Component.dispatchEvent(Component.java:2497)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
    What I see is only the GUI less the animation that occurs when it was an applet. Could anyone offer me any suggestions or help? Thanks a lot.

    Here's my codes, many thanks:
    * Swarm.class
    * This is the major class of the swarm animation. The Swarm class is
    * responsible for initialising and coordinating the Flock, swarmCanvas,
    * and swarmPanel classes.
    * @see Flock.class
    * @see Bird.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 20 September 1997
    import java.awt.*;
    public class Swarm extends java.applet.Applet implements Runnable {
    Thread animator; // animation thread
    swarmCanvas arena; // display canvas
    swarmPanel controls; // control panel
    static int NUMBLUE = 15, NUMRED = 5, MAXPOP = 20;
    static double SPEED = 5.0;
    static int TURN = 15, MINDIST = 30, MAXDIST = 60;
    boolean paused = false;
    public void init() { // initialise applet components
    arena = new swarmCanvas();
    controls = new swarmPanel(NUMBLUE, NUMRED, MAXPOP);
    setLayout(new BorderLayout());
    add("Center", arena); // add canvas to applet at 'Center'
    add("South", controls); // add panel to applet at 'South'
    arena.requestFocus();
    public void start() { // start thread when applet starts
    if (animator == null) {
    animator = new Thread(this);
    animator.start();
    public void stop() { // stop thread when applet stops
    if (animator != null) {
    animator.stop();
    animator = null;
    public void run() {
    boolean flocking = false;
    while (true) {
    if (!flocking && arena.unpacked) { // once canvas component is unpacked
    Bird.setBoundaries(arena.w, arena.h); // set swarm boundaries
    arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
    flocking = true;
    } else if (flocking) {
    Bird.setBoundaries(arena.w, arena.h);
    if (!paused)
    arena.flock.move(); // animate the flock
    arena.repaint(); // update display
    try {
    Thread.sleep(20); // interval between steps
    } catch (InterruptedException e) {}
    public boolean handleEvent(Event ev) { // check for control panel actions
    if (ev.id == Event.ACTION_EVENT && ev.target == controls.reset) {
    resetApplet(); // reset button pressed in controls
    return true;
    if (ev.id == Event.ACTION_EVENT && ev.target == controls.pause) {
    paused = !paused; // toggle paused status
    controls.pause.setLabel((paused) ? "Continue" : "Pause");
    return true;
    if (ev.target == controls.sbRed) {
    if (ev.id == Event.SCROLL_LINE_UP)
    arena.flock.removeBird(Color.red); // remove a red Bird from flock
    else if (ev.id == Event.SCROLL_LINE_DOWN)
    arena.flock.addBird(new Bird(Color.red)); // add a red Bird
    return true;
    if (ev.target == controls.sbBlue) {
    if (ev.id == Event.SCROLL_LINE_UP)
    arena.flock.removeBird(Color.blue); // remove a blue Bird from flock
    else if (ev.id == Event.SCROLL_LINE_DOWN)
    arena.flock.addBird(new Bird(Color.blue)); // add a blue Bird
    return true;
    return super.handleEvent(ev); // pass on unprocessed events
    public boolean keyDown(Event e, int x) { // check for key press
    boolean shiftKeyDown = ((e.modifiers & Event.SHIFT_MASK) != 0);
    if (shiftKeyDown) {
    if (x == Event.DOWN) Flock.minDISTANCE -= 5; // less separation
    if (x == Event.UP) Flock.minDISTANCE += 5; // more separation
    if (x == Event.LEFT) Flock.maxDISTANCE -= 5; // lower detection
    if (x == Event.RIGHT) Flock.maxDISTANCE += 5; // higher detection
    Barrier.minRANGE = Flock.minDISTANCE;
    Barrier.maxRANGE = Flock.maxDISTANCE;
    } else {
    if (x == Event.DOWN) Bird.maxSPEED -= 1.0; // slower
    if (x == Event.UP) Bird.maxSPEED += 1.0; // faster
    if (x == Event.LEFT) Bird.maxTURN -= 5; // less turning
    if (x == Event.RIGHT) Bird.maxTURN += 5; // more turning
    return true; // all key events handled
    public void resetApplet() {
    arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
    controls.sbBlue.setValue(NUMBLUE); // initialise scrollbars
    controls.sbRed.setValue(NUMRED);
    * swarmPanel.class
    * A Panel holding two scrollbars and two buttons for controlling the
    * Swarm applet.
    * @see Swarm.class
    * @author Duncan Crombie
    * @version 2.01, 20 September 1997
    class swarmPanel extends Panel { // class defines applet control panel
    Button reset, pause;
    Scrollbar sbBlue = new Scrollbar(Scrollbar.HORIZONTAL);
    Scrollbar sbRed = new Scrollbar(Scrollbar.HORIZONTAL);
    Label label1, label2;
    * The construction method creates and adds control panel components
    swarmPanel(int numRed, int numBlue, int maxBoid) {
    setLayout(new GridLayout(2, 3)); // define 2 x 3 grid layout for controls
    label1 = new Label("Blue #");
    label1.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label1);
    label2 = new Label("Red #");
    label2.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label2);
    reset = new Button("Reset"); add(reset);
    sbBlue.setValues(numRed, 1, 0, maxBoid);
    add(sbBlue);
    sbRed.setValues(numBlue, 1, 0, maxBoid);
    add(sbRed);
    pause = new Button("Pause");
    add(pause);
    * swarmCanvas.class
    * A Canvas for displaying the Flock and Swarm parameters.
    * @see Swarm.class
    * @author Duncan Crombie
    * @version 2.01, 20 September 1997
    class swarmCanvas extends Canvas {
    Flock flock;
    Image offScrImg;
    boolean unpacked = false;
    int w, h;
    /* Double buffered graphics */
    public void update(Graphics g) {
    if (offScrImg == null || offScrImg.getWidth(this) != w || offScrImg.getHeight(this) != h)
    offScrImg = createImage(w, h);
    Graphics og = offScrImg.getGraphics();
    paint(og);
    g.drawImage(offScrImg, 0, 0, this);
    og.dispose();
    public void paint(Graphics g) {
    Dimension d = this.preferredSize();
    if (!unpacked) {
    this.w = d.width;
    this.h = d.height;
    unpacked = true;
    g.setColor(Color.white);
    g.fillRect(0, 0, w, h); // draw white background
    g.setColor(Color.black); // set font and write applet parameters
    g.setFont(new Font("Dialog", Font.PLAIN, 10));
    g.drawString("Bird Speed: " + Bird.maxSPEED, 10, 15);
    g.drawString("Bird Turning: " + Bird.maxTURN, 10, 30);
    g.drawString("Minimum Distance: " + Flock.minDISTANCE, 10, 45);
    g.drawString("Maximum Distance: " + Flock.maxDISTANCE, 10, 60);
    flock.display(g); // draw Flock members
    if (this.w != d.width || this.h != d.height)
    unpacked = false;
    public boolean mouseDown(Event ev, int x, int y) {
    int radius = Barrier.maxRANGE;
    boolean top, bottom;
    flock.addBird(new Barrier(x, y)); // place Barrier at click coordinates
    top = (y < radius);
    bottom = (y > h-radius);
    if (x < radius) { // if left
    flock.addBird(new Barrier(w + x, y));
    if (top) flock.addBird(new Barrier(w + x, h + y));
    else if (bottom) flock.addBird(new Barrier(w + x, y - h));
    } else if (x > w-radius) { // if right
    flock.addBird(new Barrier(x - w, y));
    if (top) flock.addBird(new Barrier(x - w, h + y));
    else if (bottom) flock.addBird(new Barrier(x - w, y - h));
    if (top) flock.addBird(new Barrier(x, h + y));
    else if (bottom) flock.addBird(new Barrier(x, y - h));
    return true;
    ===================================================================
    * Bird.class
    * This class defines the appearance and behaviour of a Bird object.
    * @see Swarm.class
    * @see Flock.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 21 September 1997
    import java.awt.*;
    class Bird {
    int iX, iY, iTheta;
    Color cFeathers;
    static int arenaWIDTH, arenaHEIGHT; // canvas dimensions
    static double maxSPEED; // speed of Bird
    static int maxTURN; // maximum turn in degrees
    Bird(int x, int y, int theta, Color feath) {
    iX = x;
    iY = y;
    iTheta = theta;
    cFeathers = feath;
    Bird(Color feath) {
    this((int)(Math.random() * arenaWIDTH),
    (int)(Math.random() * arenaHEIGHT),
    (int)(Math.random() * 360),
    feath);
    public void move(int iHeading) {
    int iChange = 0;
    int left = (iHeading - iTheta + 360) % 360;
    int right = (iTheta - iHeading + 360) % 360;
    if (left < right)
    iChange = Math.min(maxTURN, left);
    else
    iChange = -Math.min(maxTURN, right);
    iTheta = (iTheta + iChange + 360) % 360;
    iX += (int)(maxSPEED * Math.cos(iTheta * Math.PI/180)) + arenaWIDTH;
    iX %= arenaWIDTH;
    iY -= (int)(maxSPEED * Math.sin(iTheta * Math.PI/180)) - arenaHEIGHT;
    iY %= arenaHEIGHT;
    public void display(Graphics g) { // draw Bird as a filled arc
    g.setColor(this.cFeathers);
    g.fillArc(iX - 12, iY - 12, 24, 24, iTheta + 180 - 15, 30);
    public int getDistance(Bird bOther) {
    int dX = bOther.getPosition().x-iX;
    int dY = bOther.getPosition().y-iY;
    return (int)Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));
    static void setBoundaries(int w, int h) {
    arenaWIDTH = w;
    arenaHEIGHT = h;
    public int getTheta() {
    return iTheta;
    public Point getPosition() {
    return new Point(iX, iY);
    public Color getFeathers() {
    return cFeathers;
    =================================================================
    * Flock.class
    * This class creates and coordinates the movement of a flock of Birds.
    * @see Swarm.class
    * @see Bird.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 21 September 1997
    import java.util.Vector;
    import java.awt.*;
    class Flock { // implement swarming algorithm on flock of birds
    private Vector vBirds;
    static int minDISTANCE, maxDISTANCE;
    Flock(int nBlue, int nRed, double speed, int turn, int minDist, int maxDist) {
    vBirds = new Vector(5, 5);
    for (int i=0; i < nBlue + nRed; i++)
    addBird(new Bird((i < nBlue) ? Color.blue : Color.red));
    Bird.maxSPEED = speed;
    Bird.maxTURN = turn;
    Barrier.minRANGE = minDISTANCE = minDist;
    Barrier.maxRANGE = maxDISTANCE = maxDist;
    public void addBird(Bird bird) { // add Bird to vector
    vBirds.addElement(bird);
    synchronized void removeBird(Color col) { // remove Bird from vector
    for (int i=0; i < vBirds.size(); i++) { // loop through vector of Birds
    Bird bTemp = (Bird)vBirds.elementAt(i);
    if (bTemp.getFeathers() == col) { // search for Bird of given colour
    vBirds.removeElementAt(i); // if found, remove Bird..
    break; // ..and stop searching
    * The move function simply tells each Bird in the Vector vBirds to move
    * according to the resultant Point of generalHeading.
    synchronized public void move() {
    for (int i=0; i < vBirds.size(); i++) {
    Bird bTemp = (Bird)vBirds.elementAt(i);
    bTemp.move(generalHeading(bTemp));
    * The display function simply draws each Bird in the Vector vBirds at its
    * current position.
    public void display(Graphics g) { // display each Bird in flock
    for (int i=0; i < vBirds.size(); i++) {
    Bird bTemp = (Bird)vBirds.elementAt(i);
    bTemp.display(g);
    public Point sumPoints(Point p1, double w1, Point p2, double w2) {
    return new Point((int)(w1*p1.x + w2*p2.x), (int)(w1*p1.y + w2*p2.y));
    public double sizeOfPoint(Point p) {
    return Math.sqrt(Math.pow(p.x, 2) + Math.pow(p.y, 2));
    public Point normalisePoint(Point p, double n) {
    if (sizeOfPoint(p) == 0.0) return p;
    else {
    double weight = n / sizeOfPoint(p);
    return new Point((int)(p.x * weight), (int)(p.y * weight));
    * The generalHeading function determines the point a Bird will turn towards
    * in the next timestep. The Bird b checks for all Birds (other than self)
    * that fall within the detection range. If the Bird is of a different colour
    * or closer than the separation distance then they are repulsed else the
    * Birds are attracted according to the flocking algorithm.
    private int generalHeading(Bird b) {
    if (b instanceof Barrier) return 0;
    Point pTarget = new Point(0, 0);
    int numBirds = 0; // total of Birds to average
    for (int i=0; i < vBirds.size(); i++) { // for each Bird in array
    Bird bTemp = (Bird)vBirds.elementAt(i); // retrieve element i
    int distance = b.getDistance(bTemp); // get distance to Bird
    if (!b.equals(bTemp) && distance > 0 && distance <= maxDISTANCE) {
    * If the neighbour is a sibling the algorithm tells the boid to align its
    * direction with the other Bird. If the distance between them differs from
    * minDISTANCE then a weighted forces is applied to move it towards that
    * distance. This force is stronger when the boids are very close or towards
    * the limit of detection.
    if (b.getFeathers().equals(bTemp.getFeathers())) { // if same colour
    Point pAlign = new Point((int)(100 * Math.cos(bTemp.getTheta() * Math.PI/180)), (int)(-100 * Math.sin(bTemp.getTheta() * Math.PI/180)));
    pAlign = normalisePoint(pAlign, 100); // alignment weight is 100
    boolean tooClose = (distance < minDISTANCE);
    double weight = 200.0;
    if (tooClose) weight *= Math.pow(1 - (double)distance/minDISTANCE, 2);
    else weight *= - Math.pow((double)(distance-minDISTANCE) / (maxDISTANCE-minDISTANCE), 2);
    Point pAttract = sumPoints(bTemp.getPosition(), -1.0, b.getPosition(), 1.0);
    pAttract = normalisePoint(pAttract, weight); // weight is variable
    Point pDist = sumPoints(pAlign, 1.0, pAttract, 1.0);
    pDist = normalisePoint(pDist, 100); // final weight is 100
    pTarget = sumPoints(pTarget, 1.0, pDist, 1.0);
    * In repulsion the target point moves away from the other Bird with a force
    * that is weighted according to a distance squared rule.
    else { // repulsion
    Point pDist = sumPoints(b.getPosition(), 1.0, bTemp.getPosition(), -1.0);
    pDist = normalisePoint(pDist, 1000);
    double weight = Math.pow((1 - (double)distance/maxDISTANCE), 2);
    pTarget = sumPoints(pTarget, 1.0, pDist, weight); // weight is variable
    numBirds++;
    if (numBirds == 0) return b.getTheta();
    else // average target points and add to position
    pTarget = sumPoints(b.getPosition(), 1.0, pTarget, 1/(double)numBirds);
    int targetTheta = (int)(180/Math.PI * Math.atan2(b.getPosition().y - pTarget.y, pTarget.x - b.getPosition().x));
    return (targetTheta + 360) % 360; // angle for Bird to steer towards
    ======================================================================
    * Barrier.class
    * This class creates and coordinates the movement of a flock of Birds.
    * @see Swarm.class
    * @see Flock.class
    * @see Bird.class
    * @author Duncan Crombie
    * @version 2.01, 21 September 1997
    import java.awt.*;
    class Barrier extends Bird {
    static int minRANGE, maxRANGE;
    Barrier(int x, int y) {
    super(x, y, 0, Color.black); // position Barrier and define color as black
    public void move(int dummy) {
    // do nothing
    public void display(Graphics g) { // paint Barrier
    g.setColor(Color.black);
    g.fillOval(this.iX-5, this.iY-5, 10, 10);
    g.setColor(Color.gray); // paint separation circle
    g.drawOval(this.iX-minRANGE, this.iY-minRANGE, 2*minRANGE, 2*minRANGE);
    g.setColor(Color.lightGray); // paint detection circle
    g.drawOval(this.iX-maxRANGE, this.iY-maxRANGE, 2*maxRANGE, 2*maxRANGE);
    =====================================================================
    import java.awt.*;
    import java.awt.event.*;
    public class SwarmFrame extends Frame implements ActionListener {
    public SwarmFrame() {
    super("Flocking Bird");
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu fileMenu = new Menu("File");
    mb.add(fileMenu);
    MenuItem exitMenuItem = new MenuItem("Exit");
    fileMenu.add(exitMenuItem);
    exitMenuItem.addActionListener(this);
    Swarm swarmApplet = new Swarm();
    add(swarmApplet, BorderLayout.CENTER);
    swarmApplet.init();
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() instanceof MenuItem) {
    String menuLabel = ((MenuItem) evt.getSource()).getLabel();
    if(menuLabel.equals("Exit")) {
    dispose();
    System.exit(0);
    =====================================================================
    import java.awt.*;
    public class SwarmApplication {
    public static void main(String[] args) {
    Frame frame = new SwarmFrame();
    frame.setBounds(10, 10, 600, 400);
    frame.setVisible(true);

  • How can i make from a GUI application an Applet ?

    Hello, i have a gui appliction and i want to make an applet
    how can i do that, i read an article (i need to put away method main and write method init (must be same as a constructer , but my constructor is only public Grafika() ) but it doest help....
    Can you help me.. ?
    import javax.swing.JFrame;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.JPanel;
    import java.awt.*;
    import javax.swing.*;
    public class Grafika{
         JPanel canvas;
         public static boolean pause = true;
         public static int algoritmus = 0;
         public static String[] algoritmy={"V�ber Algoritmu","QuickSort","BubbleSort"};
         public static long sleeper = 600;       
         public void borders(JPanel canvas,int[] cisla,int left,int right){
              Graphics g = canvas.getGraphics();
              for(int i=0;i<cisla.length;i++){               
                   if(cisla==cisla[left]){
                        g.setColor(Color.lightGray);
                        g.drawLine(10, 20+i*4, 500,20+i*4 );
                   if(cisla[i]==cisla[right]){
                        g.setColor(Color.lightGray);
                        g.drawLine(10, 20+i*4+1, 500,20+i*4+1 );
                   else {
                        g.setColor(Color.white);
                        g.drawLine(10, 20+i*4-1, 500,20+i*4-1 );
              g.dispose();
              //repaint();          
         public void drawIt(JPanel canvas,int[] cisla,int pivot){
              Graphics g = canvas.getGraphics();
              for(int i=0;i<cisla.length;i++){     
                   if(cisla[i]==pivot){
                        g.setColor(Color.green);
                   else {
                        g.setColor(Color.red);
                   g.fillRect(10, 20+i*4, cisla[i], 2);
                   g.setColor(Color.white);
                   g.fillRect(9+cisla[i]+1,20+ i*4, 1000, 2);
              g.dispose();
              //repaint();          
              public static void main(String[] Args){
              JFrame f = new JFrame("Triediace Algoritmy");     
              JPanel canvas = new JPanel();
              canvas.setBackground(Color.white);
              JButton sort = new JButton("Faster");
              JButton cancel = new JButton("Slower");
              sort.addActionListener(new ButtonListener());
              cancel.addActionListener(new ButtonListener());
              JComboBox algChooser = new JComboBox(algoritmy);
              algChooser.addActionListener(new ComboListener());
              JPanel controlPanel = new JPanel(new FlowLayout());
              controlPanel.add(algChooser);
              controlPanel.add(sort);
              controlPanel.add(cancel);
              canvas.setPreferredSize(new Dimension(200,200));
              // canvas.setBorder(BorderFactory.createLineBorder(Color.black));
              JPanel contentPane = new JPanel(new BorderLayout());
              // contentPane.setBounds(1, 1, 200, 200);
              contentPane.add(canvas,BorderLayout.CENTER);
              contentPane.add(controlPanel,BorderLayout.PAGE_END);
              // contentPane.setBorder(BorderFactory.createLineBorder(Color.red));
         f.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
         System.exit(0);
         f.add(contentPane);
         f.pack();
         f.setSize(800,375);
         f.setVisible(true);
         int[] cisla = fillArray(70);
    while (algoritmus == 0){
    try{
         Thread.sleep(1);
    }catch(InterruptedException ie){}
    if (algoritmus == 1){
    QuickSort qs = new QuickSort(canvas);
    qs.sort(cisla);
    if (algoritmus == 2){
    BubbleSort bs = new BubbleSort(canvas);
    bs.sort(cisla);
         public static int[] fillArray(int numbers){
              int temp=0;
              int[] arrayOfNumbers= new int[numbers];
              for (int i=0;i<numbers;i++){
                   arrayOfNumbers[i] = i;
              for (int i=0;i<numbers;i++){
                   Random generator = new Random();
                   int left =generator.nextInt(numbers);
                   int right =generator.nextInt(numbers);
                   temp=arrayOfNumbers[left];
                   arrayOfNumbers[left]=arrayOfNumbers[right];
                   arrayOfNumbers[right]=temp;
              return arrayOfNumbers;
    Thank you very much                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    //  <applet code="GrafikaApplet" width="400" height="400"></applet>
    //  use: >appletviewer GrafikaApplet.java
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    import javax.swing.*;
    public class GrafikaApplet extends JApplet {
        String[] algoritmy={"V�ber Algoritmu","QuickSort","BubbleSort"};
        int algoritmus = 0;
        boolean running = false;
        GrafikaPanel canvas;
        int[] cisla;
        public void init() {
            cisla = fillArray(70);
            canvas = new GrafikaPanel(cisla);
            canvas.setPreferredSize(new Dimension(200,200));
           resize(800,375);
            Container cp = getContentPane();
            cp.add(canvas, BorderLayout.CENTER);
            cp.add(getControlPanel(), BorderLayout.PAGE_END);
        private int[] fillArray(int numbers){
            Random generator = new Random();
            int temp=0;
            int[] arrayOfNumbers= new int[numbers];
            for (int i=0;i<numbers;i++){
                arrayOfNumbers[i] = i;
            for (int i=0;i<numbers;i++){
                int left = generator.nextInt(numbers);
                int right = generator.nextInt(numbers);
                temp=arrayOfNumbers[left];
                arrayOfNumbers[left]=arrayOfNumbers[right];
                arrayOfNumbers[right]=temp;
            return arrayOfNumbers;
        private void startAnimation() {
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    switch(algoritmus) {
                        case 1:
                            new QuickSort2(canvas).sort(cisla);
                    running = false;
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                if(!running) {
                    running = true;
                    algoritmus = 1;
                    startAnimation();
        private JPanel getControlPanel(){
            JButton sort = new JButton("Faster");
            JButton cancel = new JButton("Slower");
            ButtonListener bl = new ButtonListener();
            sort.addActionListener(bl);
            cancel.addActionListener(bl);
            JComboBox algChooser = new JComboBox(algoritmy);
    //        algChooser.addActionListener(new ComboListener());
            JPanel controlPanel = new JPanel(new FlowLayout());
            System.out.println("default layout for JPanel = " +
                                new JPanel().getLayout().getClass().getName());
            controlPanel.add(algChooser);
            controlPanel.add(sort);
            controlPanel.add(cancel);
            return controlPanel;
    class GrafikaPanel extends JPanel {
       int[] cisla;
       int left;
       int right;
       int pivot;
        public GrafikaPanel(int[] cisla) {
            this.cisla = cisla;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            for(int i=0;i<cisla.length;i++){               
                if(cisla==cisla[left]){
    g.setColor(Color.lightGray);
    g.drawLine(10, 20+i*4, 500,20+i*4 );
    if(cisla[i]==cisla[right]){
    g.setColor(Color.lightGray);
    g.drawLine(10, 20+i*4+1, 500,20+i*4+1 );
    else {
    g.setColor(Color.white);
    g.drawLine(10, 20+i*4-1, 500,20+i*4-1 );
    for(int i=0;i<cisla.length;i++){     
    if(cisla[i]==pivot){
    g.setColor(Color.green);
    else {
    g.setColor(Color.red);
    g.fillRect(10, 20+i*4, cisla[i], 2);
    g.setColor(Color.white);
    g.fillRect(9+cisla[i]+1,20+ i*4, 1000, 2);
    public void drawIt(int[] cisla, int pivot){
    this.cisla = cisla;
    this.pivot = pivot;
    repaint();
    class QuickSort2{
    GrafikaPanel component;
    public QuickSort2(GrafikaPanel gp){
    component = gp;
    public void sort (int[] vstupnePole) {
    QSort(vstupnePole,0,vstupnePole.length-1);
    public void QSort(int[] array,int zac,int kon){
    int i = zac;
    int j = kon;
    int pivot = array[(i+j)/2];
    while(i<=j){
    try {
    Thread.sleep(100);
    component.drawIt(array,pivot);          
    }catch(InterruptedException ie){break;}
    while(pivot<array[j]){j--;}
    while(pivot>array[i]){i++;}
    if (i<=j){
    int temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    i++;
    j--;
    if (zac<j){QSort(array,zac,j);}
    if (i<kon){QSort(array,i,kon);}

Maybe you are looking for

  • How do I convert my iTunes Match library to MP3?

    I have several thousand AAC files that I created by importing part of my CD collection to iTunes Match. Because these files were created from my own CDs, rather than purchased as digital downloads, there is no DRM issue. However, I want to be able to

  • Report Writer Interface RGGD1300

    Has anyone used this report to alter GR55 output?  I need to take the configured output and further define selection criteria (filter that can't be done in variables/formula due to the set definition) and move some rows into different sections.  When

  • Version check of JRE in app

    Hi, I want my application(not web-based or whatever) to know which version of JRE the client is using. The thing is, I know it's with System.getProperty("java.version"), but I want to compare it with another version string in the application. The use

  • Is it possible to create items (textitem) dinamically in runtime?

    is it possible?

  • Testing for Insert after ApplyMRU runs

    Apex 4.0, Tabular forms. I have 2 tabular forms. First is a master. Second is a detail. On separate pages. I would like to automatically redirect to the detail if a new record is inserted on the master. I thought maybe I could test #MRI_COUNT# for 1