dinsdag 19 juni 2012

I have decided to stop programming in Java

Since the applets no longer work. I have decided to stop programming in Java. I never really gotten used to Java.

I will keep programming but in another language. I was thinking of buying Play Basic but for the moment I do  my programming exercises in Blitz Basic.

(edit:)
I think the google site is returning errorous data from the applets. Maybe this will go away.

maandag 11 juni 2012

Java applets do not work anymore on my pc

I have tried firefox, internet explorer and google chrome but the applets do not show anymore. Also the browsers freeze when I load the pages. This happened before but not with all the browsers. I have no idea what I can do to fix it. I will try to look up what the problem might be.

edit :

I could not find any information yet. I have also tried reinstalling the java runtime. This did not fix it. I also tried another computer and this gives the same error. Also older applet that used to work did not work anymore. I get a magic number error with the applets when they do load. I hope this problem will fix itself in the future. As I have no idea what to do.

Manhattan Distance example



Manhattan distance example. Move the mouse over the applet to see the distance change.

 


import java.awt.*;
import java.applet.*;

public class manhattandistanceexample001 extends Applet implements Runnable {
 // Graphics for double buffering.
 Graphics      bufferGraphics;
    Image       offscreen;
 int mousex =     0;
 int mousey =    0;

 public void init() {
     setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
     bufferGraphics = offscreen.getGraphics();
     new Thread(this).start();

 }

    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

   public boolean mouseMove(Event e, int x, int y){
        mousex = x;
        mousey = y;
  return true;
 }

    public void update(Graphics g){
     bufferGraphics.clearRect( 0 , 0 , getSize().width , getSize().width );
        bufferGraphics.setColor( Color.red );
        bufferGraphics.drawString( "Manhattan Distance " , 10 , 10 );

  for ( int y = 0 ; y < 240/32 ; y++ ){
  for ( int x = 0 ; x < 320/32 ; x++ ){
   bufferGraphics.drawRect( x * 32 , y * 32 , 32 , 32 );
   int dist = mdist( mousex / 32 , mousey / 32 , x , y );
   bufferGraphics.drawString( "" + dist , x * 32 , y * 32 + 16 );
  }
  }

       g.drawImage(offscreen,0,0,this);
    }

 public int mdist( int x1 , int y1 , int x2 , int y2 ){
  return Math.abs( x2 - x1 ) + Math.abs( y2 - y1 );
 }

}


Euclidean Distance example





Euclidean distance example. Move the mouse over the applet to see the distance change.

 


import java.awt.*;
import java.applet.*;

public class euclideandistanceexample001 extends Applet implements Runnable {
 // Graphics for double buffering.
 Graphics      bufferGraphics;
    Image       offscreen;
 int mousex =     0;
 int mousey =    0;

 public void init() {
     setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
     bufferGraphics = offscreen.getGraphics();
     new Thread(this).start();

 }

    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

   public boolean mouseMove(Event e, int x, int y){
        mousex = x;
        mousey = y;
  return true;
 }

    public void update(Graphics g){
     bufferGraphics.clearRect( 0 , 0 , getSize().width , getSize().width );
        bufferGraphics.setColor( Color.red );
        bufferGraphics.drawString( "Euclidean Distance " , 10 , 10 );

  for ( int y = 0 ; y < 240/32 ; y++ ){
  for ( int x = 0 ; x < 320/32 ; x++ ){
   bufferGraphics.drawRect( x * 32 , y * 32 , 32 , 32 );
   int dist = edist( mousex / 32 , mousey / 32 , x , y );
   bufferGraphics.drawString( "" + dist , x * 32 , y * 32 + 16 );
  }
  }

       g.drawImage(offscreen,0,0,this);
    }

 public int edist( int x1 , int y1 , int x2 , int y2 ){
  return (int)Math.sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) );
 }

}



zaterdag 2 juni 2012

The blog still works.

It looks like the email I got from blogger support was wrong. The blog still works. I have 2 examples which I still need to place on the weblog. These are distance formula's examples. I am also stil thinking of what to program next. Though it is summer and I spend a lot of time outside. I have not programmed a lot. But I am reading programming books. I have an old Java 2 book which I am curently reading.

dinsdag 15 mei 2012

This blog might be blocked starting 30 may 2012

I got a reminder in the email that I need to transfer the blogger account into my google account. But my blogger username is not found on the conversion page. This means that my blog might stop after may 30th and that I need to start a new one. I have no idea what the login problem might be. I have a blogger username so why it cannot be found is a mystery to me.

Well if this is one of the last posts then I might have started a new blog about game programming. I might call it about the same name. Java game programming step by step or so.

Edit : I have replied to the support email of the notice that I can not converse so I hope to hear something soon. I hope this works.

Edit2: I did not get a reply from the support email adres of blogger but I did look into the support forum. There was a post about my problem and it said not to worry about this. You automatically are converted to the new method if you used the blog after the new license.

donderdag 19 april 2012

Game Menu Example





Use the s and w keys to move the selection cursor.
 


import java.awt.*;
import java.applet.*;

public class gamemenuexample001 extends Applet implements Runnable{

 Graphics bufferGraphics;
 Image offscreen;
 FontMetrics fm;
 int nummenuitems = 4;
 String gamemenu[] = new String[ nummenuitems ];
 int menuchoice = 0;

 public void init() {
        setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
        bufferGraphics = offscreen.getGraphics();
  Graphics g;
  g = getGraphics();
  fm = g.getFontMetrics();
        gamemenu[ 0 ] = "New Game";
        gamemenu[ 1 ] = "Load Game";
        gamemenu[ 2 ] = "Options";
        gamemenu[ 3 ] = "Credits";
  new Thread(this).start();
 }
    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }



     public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().height);
     bufferGraphics.setColor(Color.red);

  String s = "";
  for ( int i = 0 ; i < nummenuitems ; i++ ){
   if ( i == menuchoice ){
          s = "-> " + gamemenu[ i ];
    bufferGraphics.drawString(s,(this.getSize().width-fm.stringWidth(s)) / 2, 80 + i * 20 );
   }else{
    s = gamemenu[ i ];
    bufferGraphics.drawString(s,(this.getSize().width-fm.stringWidth(s)) / 2, 80 + i * 20 );
   }
  }

        bufferGraphics.drawString("Game Menu Screen.",10,10);
  bufferGraphics.drawString("w/s to move cursor.",10,237);

        g.drawImage(offscreen,0,0,this);
     }
  public boolean keyDown (Event e, int key){

   return true;
  }
 public boolean keyUp (Event e, int key){

  // key w
   if ( key == 119 ){
       if ( menuchoice > 0 ){
        menuchoice--;
       }
        }
        // key s
        if ( key == 115 ){
         if ( menuchoice < nummenuitems - 1 ){
          menuchoice++;
         }
        }
  //System.out.println(""+key);
  return true;
 }


}