Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Beginning Java SE 6 Game Programming, Third Edition NOTES:
- There are two types of Java programs you can create:
- Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform.
- The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995.
- Java 2D is an API containing classes for advanced 2D graphics rendering and image manipulation, with support for vector (line-based) shapes, font-based text, image formats, and advanced RGBA color manipulation. This API works great for building 2D games with Java, and is what we will be using in this book. Among other things, we can perform transforms (rotation, translation, and scaling) on 2D images.
- Java 3D is an API that allows rendering of 3D graphics in a Java application or web-based applet with high-level constructs for building 3D scenes. The websites are java3d.dev.java.net and www.java3d.org. This API works very well for building 3D games with Java.
- The simplest way to create and run a Java program is with a text editor and the Java command-line tools javac.exe, java.exe, and appletviewer.exe.
- An application and an applet.
- An applet program extends a class called Applet, which means the applet will receive all of the features of the Applet class (which has the ability to run in a web browser). Essentially, all of the complexity of typing in your program with the web browser has been done for you through class inheritance (your program inherits the features of the Applet class).
- JFrame makes it possible to do graphics in a Java application that is normally limited to just console output. JFrame provides a Graphics context as goes the Applet class, which can be used for drawing. The source code for a JFrame-based application is not any less code than an Applet project, but it foregoes the need of a web browser (or appletviewer), meaning we can run such a program with java.exe.
- Let's go over what is in the JFrameDemo program:
- First, we need javax.swing, which owns the JFrame class, while java.awt makes the Graphics class available. The JFrameDemo class is the main class of the program, which extends JFrame, meaning that our class is a JFrame. There are some things that come with a JFrame class, such as the paint() method which renders the window when the program first starts up. We still need our main() function, and it has a single purpose: to launch the JFrame-powered class, JFrameDemo. The JFrameDemo() method is actually the constructor for the class, meaning it runs when the class is first created. Anything you want to happen when the window is first created and comes up, you could put in the constructor. So, we set the window title, the dimensions, and other useful properties.
- Again, there are two different types of programs you can compile with Java: applications and applets. A Java application, the most common type of Java program, is a program compiled to run on a computer as a standalone application. A Java applet, on the other hand, is compiled specifically to run in a web browser. Java applications are usually written to run as server programs or just for one user, whereas applets run as client programs in a networked environment.
- For example, Java Web Server (JWS) is a Java application that
- hosts web page files to a web browser (such as Internet Explorer or Mozilla
- Firefox), and it is comparable to Microsoft’s Internet Information Server (IIS)
- web server and the open-source Apache web server. But, Java applications are
- not solely devoted to services, as we can use the Swing library and the Abstract
- Windowing Toolkit (AWT) to bring up a graphical window for an application
- with all the same features as an applet window. Since applications are much
- easier to use, requiring fewer steps to compile and run, this is the approach we
- are taking in this new edition. The final game of Galactic War in the last chapter
- will support both.
Advertisement
Add Comment
Please, Sign In to add comment