[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
Java-Applications
This tutorial covers Java Applications. Creating Java applications is rather easy, once you know how it works.
This sample program is not really difficult to understand. It defines a class called Hello World and has a method called main which most people may know from C or C++ programming. Within the main function we use the println() function to write the message "Hello World" on the screen. The println() function is similar to printf in C.
Note: when compiling Java applications make sure that your file has the name as your main class. If it does not, the java compiler will complain an error.
Whoops! Did i say it was easy? Well, it actually is easy once you undertand how it works. When writing windows applications with Java, you basically need 2 classes. The first class implements the application body and Eventlisteners. The second implements the application logic.
The AWT framework To be able to use the windows application programming features of Java you first need to import the java.awt.*; classes. This is overall importance for any windows application.
The Java EventListener modell All windows applications written in Java need to implement so called Listeners. The class framework of Java supports various forms of Listeners. WindowListeners, MouseListeners, KeyboadListeners, etc..
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
Java-Applications
Java Applications
-----------------------This tutorial covers Java Applications. Creating Java applications is rather easy, once you know how it works.
A tiny Java application
The basic layout of a Java application is similar to that of a C# program. The Hello World program in Java looks like this:
public class Hallo
{
public static void main(string args[])
{
System.out.println("Hello World");
}
}
This sample program is not really difficult to understand. It defines a class called Hello World and has a method called main which most people may know from C or C++ programming. Within the main function we use the println() function to write the message "Hello World" on the screen. The println() function is similar to printf in C.
Note: when compiling Java applications make sure that your file has the name as your main class. If it does not, the java compiler will complain an error.
Windows applications with Java
Writing windows applications in Java is easy. This is because Java is a 100 % object oriented programming language and you dont need to worry about API function calls or pointers or unsafe castings.
import java.awt*;
class HelloWin extends Frame
{
//the constructor of the class
HellWin()
{
//create a new instance of WriteText
add("Center", new WriteText());
//our main window Listener
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
//the main function of this class
public static void main(string args[])
{
new HelloWindows();
}
}
//we create a 2nd class for data display
class WriteText extends Canvas
{
public void paint(Graphics g)
{
//print Hello World on the screen
g.drawString("Hello World",100,100);
}
}
Whoops! Did i say it was easy? Well, it actually is easy once you undertand how it works. When writing windows applications with Java, you basically need 2 classes. The first class implements the application body and Eventlisteners. The second implements the application logic.
The AWT framework To be able to use the windows application programming features of Java you first need to import the java.awt.*; classes. This is overall importance for any windows application.
The Java EventListener modell All windows applications written in Java need to implement so called Listeners. The class framework of Java supports various forms of Listeners. WindowListeners, MouseListeners, KeyboadListeners, etc..
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
