home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / Linux / old / alpha3 / MyAwtApp.java < prev    next >
Encoding:
Java Source  |  1995-09-19  |  2.0 KB  |  113 lines

  1.  
  2. package randy;
  3.  
  4. import awt.*;
  5.  
  6. class MyWindow extends Window
  7. {
  8.     private MyAwtApp app = null;
  9.     private String data;
  10.  
  11.     public void SetData(String newData) {
  12.         data = newData;
  13.         update();
  14.     }
  15.  
  16.     public String GetData() {
  17.         return data;
  18.     }
  19.  
  20.     public MyWindow(MyAwtApp appP) {
  21.         super(appP, "Center", new Color(255,255,255), 200, 50);
  22.         app = appP;
  23.         enablePointerMotionEvents();
  24.     }
  25.  
  26.     public void expose(int x, int y, int w, int h) {
  27.         drawString(data, 0, 0);
  28.     }
  29.  
  30.     public void handleMouseMoved(int x, int y, int mods) {
  31.         super.handleMouseMoved(x,y,mods);
  32.         app.setStatusMessage(String.valueOf(x) + ", " + String.valueOf(y));
  33.     }
  34. }
  35.  
  36. public class MyAwtApp extends Frame
  37. {
  38.     private WServer server = null;
  39.     private MenuBar mbar = null;
  40.     private FileMenu fileMenu = null;
  41.     private MyWindow mainWindow = null;
  42.     
  43.     public MyAwtApp(WServer serv, String args[]) {
  44.         super(serv, true, null, 300, 200, Color.lightGray);
  45.         server = serv;
  46.  
  47.         mbar = new MenuBar(this);
  48.         fileMenu = new FileMenu(mbar, this);
  49.  
  50.         mainWindow = new MyWindow(this);
  51.         mainWindow.SetData("This is an empty file\n  More sutff!");
  52.  
  53.         super.setTitle("Randy's test java program");
  54.  
  55.         showStatusBar(true);
  56.         setStatusMessage("I'm running!");
  57.  
  58.         serv.sync();
  59.  
  60.         map();
  61.     }
  62.  
  63.     public static void main(String args[]) {
  64.         WServer server = null;
  65.         MyAwtApp app = null;
  66.  
  67.         try {
  68.             server = new WServer();
  69.         } catch(Exception e) {
  70.             System.out.println("Couldn't open connection to window server");
  71.             return;
  72.         }
  73.  
  74.         server.start();
  75.  
  76.         app = new MyAwtApp(server, args);
  77.  
  78.         System.out.println("Opened the window!");
  79.     }
  80.  
  81.     public void handleQuit() {
  82.         super.handleQuit();
  83.         System.exit(0);
  84.     }
  85. }
  86.  
  87. class FileMenu extends Menu {
  88.     private MyAwtApp app = null;
  89.  
  90.     public FileMenu(MenuBar mbar, MyAwtApp appP) {
  91.         super("File", mbar);
  92.  
  93.         app = appP;
  94.  
  95.         MenuItem item;
  96.         item = new MenuItem("Open...", this);
  97.         item.disable();
  98.         new MenuItem("Quit", this);
  99.     }
  100.  
  101.     public void selected(int index) {
  102.         switch (index) {
  103.         case 0:    // open
  104.             break;
  105.         case 1:    // quit
  106.             System.exit(0);
  107.             break;
  108.         }
  109.     }
  110.  
  111. }
  112.  
  113.