I started with iPhone programming, and I found that iPhone has a clear picture to let developers know what to do, like loadView, viewWillAppear, and so on. Now, I would like to write some Java SE programme, but it is not as easy as I think. I found that Java seems not to have these things (or I don’t know the details). And I found that Java purely uses JFrame to create the GUI, like this:
import javax.swing.*;
class MyFrame extends JFrame {
public MyFrame() {
setTitle("My Empty Frame");
setSize(300,200); // default size is 0,0
setLocation(10,200); // default is 0,0 (top left corner)
}
public static void main(String[] args) {
JFrame f = new MyFrame();
f.show();
}
}
Is is the Java way to put everything in the main method? Is there a better architecture?
iPhone “applications” have a lifecycle because they’re not really “applications” in the traditional sense of the word. They’re more akin to drivers, plugins, or other bits that are meant to be embedded in a larger framework. There’s a lot of scaffolding around them that makes them work, and that scaffolding invokes the various handlers at the right time. That scaffolding isn’t considered part of the application, but it’s an essential part of the running code.
Java itself is a programming language in which you can certainly write the same sort of “plugin” things — for example, Java applets, Java servlets, Enterprise Java Beans, etc — but you can also write the framework in Java, too! Plenty of such frameworks exist, and then writing an application becomes just a matter of writing one or more “plugins.” But if you sit down and write a
main()method and go from there, then you’re eschewing any framework and have complete freedom over how to structure your code.