Topic:   Java Applets   (Read 29735 times)


0 Members and 1 Guest are viewing this topic.

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Java Applets
« Reply #30 on: February 21, 2009, 05:32:12 PM »
There's still some random flickering, and the first time you walk into the mountains from below you go through them... but good job :P

What are you using to learn java? I'm getting bored of just making bank accounts and stuff in class...

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Java Applets
« Reply #31 on: February 21, 2009, 06:06:05 PM »
I used these tutorial sites to learn, now I've learned all I need. Just up to making any ideas I have...

Main tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
Another tutorial: http://www.dgp.toronto.edu/~mjmcguff/learn/java/


-Gandolf
« Last Edit: February 21, 2009, 06:12:09 PM by Gandolf »

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Java Applets
« Reply #32 on: February 21, 2009, 06:19:47 PM »
Wow, that first tutorial is cool. I especially like the random landscape generator; the concept might also work for a random dungeon generator with a bit of tweaking.
I survived the spammage of 2007

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Java Applets
« Reply #33 on: March 28, 2009, 03:11:17 PM »
Hey guys, I scoured google until I could find an amazing set of tutorials for Xcode that could teach me everything I would ever learn. I found it in 30 seconds. Besides that, I went through a couple tutorials with great ferocity, intently trying to memorize everything my eyes laid upon. Finally after learning a bit about C language and syntax, I opened Xcode, set specified preferences and was about to open a new cocoa app when...

...I saw another application type. Java Signed Applet! Sorry Netbeans, my heart now belongs to another...


-Gandolf

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Java Applets
« Reply #34 on: June 03, 2009, 06:07:55 PM »
Quick question for Gandolf (or anyone else who knows Java):

Will I be shot for making non-constant data static? I mean making a variable static and then using it with static methods as if it were a normal instance variable. Everything seems to say that this is unusual and not recommended... why?

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Java Applets
« Reply #35 on: June 03, 2009, 07:37:10 PM »
Yeah, that method isn't so good. It would be better to create a new instance of the class with a non-static version of that variable within the Main static method. It would make your life much easier.

Here is an example of something I would do:
Main Class
Code: [Select]
public class Main {
 Â   public Main() {
 Â   }
 Â   static Main main = new Main();
 Â   public MainScreen mainscreen;

 Â   public static void main(String args[]) {
 Â       main.mainscreen = new MainScreen(main);
 Â   }
}
MainScreen Class
Code: [Select]
import java.io.*;
import java.net.*;
import java.lang.Thread;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.lang.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.util.List;
import java.util.*;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.geom.*;

public class MainScreen extends javax.swing.JFrame implements Runnable {
 Â   public Runnable runnable = this;

 Â   // Create the thread supplying it with the runnable object
 Â   public Thread Thread = new Thread(runnable);
 Â   //The mouse Input
 Â   public int mx,  my;  // the mouse coordinates
 Â   public boolean isButtonPressed = false;
 Â   //Keyboard input
 Â   public boolean[] keys = new boolean[120];
 Â   public String pressed = "";

 Â   public void run() {
 Â       while (true) {
 Â           canvas1.repaint();
 Â           try {
 Â           Thread.sleep(50);
 Â           }catch (Exception e){}
 Â       }
 Â   }
 Â   public MainScreen() {
 Â   }
 Â   Main main;

 Â   public MainScreen(Main main) {
 Â       this.main = main;
 Â       initComponents();
 Â       this.setVisible(true);
 Â       Thread.setDaemon(true);
 Â       Thread.setPriority(Thread.MIN_PRIORITY);
 Â       Thread.start();
 Â       canvas1.requestFocus();
 Â   }

 Â   public static void main(String args[]) {
 Â       java.awt.EventQueue.invokeLater(new Runnable() {

 Â           public void run() {
 Â               new MainScreen().setVisible(true);
 Â           }
 Â       });
 Â   }

 Â   // Variables declaration - do not modify
 Â   public java.awt.Canvas canvas1;
 Â   private javax.swing.JButton jButton1;
 Â   // End of variables declaration
}

class GCanvas extends Canvas {
 Â   //For Double Buffering

 Â   private Image dbImage;
 Â   private Graphics dbg;
 Â   public MainScreen main;
 Â   public Graphics2D g2;
 Â   AffineTransform affineTransform = new AffineTransform();
 Â   Dimension d;

 Â   public GCanvas(MainScreen main) {
 Â       this.main = main;
 Â   }

 Â   public void paint(Graphics g) {
 Â       g2 = (Graphics2D) g;
 Â       d = this.getSize();

 Â       g2.setColor(Color.RED);
 Â       g2.drawString("hi", 100 ,100);
 Â   }
}

You see, I have my blank Main class which is static, inside it's static-ness; I have it create a non-static instance the the Application window, "Main Screen". On MainScreen is a canvas I made which will display the text, "Hi". It updates the canvas every few milliseconds. If you copy the code exactly, it won't work because I erased a bunch of Gui stuff that hogs space when posted, though if you copy the way I set it up; it will work wonderfully for you.


-Gandolf
« Last Edit: June 03, 2009, 07:37:49 PM by Gandolf »

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Java Applets
« Reply #36 on: June 03, 2009, 11:22:07 PM »
I understand that... but why are static variables bad? Do they use tons of memory or something?
« Last Edit: June 03, 2009, 11:22:18 PM by WarHampster »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Java Applets
« Reply #37 on: June 04, 2009, 11:29:31 AM »
Hmm. I'm unsure, haven't thought too much about that. I think it's probably the way it's set up that static variables won't do most things you want to do.

I'm self taught under google, I won't know too many of the best methods or the reasons for the best methods. You should try asking a professional on the official Java forum if the question bugs you too much.


-Gandolf
« Last Edit: June 04, 2009, 11:30:00 AM by Gandolf »

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Java Applets
« Reply #38 on: June 04, 2009, 12:31:23 PM »
I wrote my port of the RPG engine using tons of static variables and my computer science teacher was fine with it, so I'm not going to worry :P

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Java Applets
« Reply #39 on: June 04, 2009, 01:32:35 PM »
Could you post it here? I would love to feast my eyes upon it.


-Gandolf

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Java Applets
« Reply #40 on: June 04, 2009, 06:20:00 PM »
Yeah, I'll clean it up a bit and post it.