Like C++, where the program starts its execution through main() function and proceeds further by calling other functions, I can't figure out this sequence in Java.
I covered most of the topic in Java, and when I came to AWT, I got the folowing problem:
import java.awt.*;
public class MenuExample extends Frame {
String menuSelection = "Select a menu item.";
public static void main(String args[]){
MenuExample win = new MenuExample();
}
public MenuExample() {
super("MenuExample");
pack();
resize(400,400);
addMenus();
show();
}
void addMenus() {
MenuBar menubar = new MenuBar();
Menu file = new Menu("File");
Menu edit = new Menu("Edit");
Menu view = new Menu("View");
file.add("Open");
file.add("Save");
file.add("Close");
file.add("Quit");
edit.add("Copy");
edit.add("Cut");
edit.add("Paste");
view.add("Zoom");
menubar.add(file);
menubar.add(edit);
menubar.add(view);
setMenuBar(menubar);
}
public void paint(Graphics g) {
g.drawString(menuSelection,100,100);
}
public boolean handleEvent(Event event) {
if(event.id==Event.WINDOW_DESTROY){
System.exit(0);
return true;
}else if(event.id == Event.ACTION_EVENT &&
event.target instanceof MenuItem){
if("Quit".equals(event.arg)){
System.exit(0);
return true;
}else{
menuSelection = "You selected "+event.arg.toString()+".";
repaint();
return true;
}
}else return false;
}
}
I can't figure out the sequence in which the above programming code works. I means, starting from main(), constructor is invoked. then......!!!???


Sign In
Create Account

Back to top









