(c) Copyright 2003, 2004 by Daniel Berleant

 

Announcements

HW #3 due today

HW#4 due a week from Thursday (see HW statement on Web)

(Anyone surprised to hear about HW3?)

Team formation Thursday -

    3-4 people on each team

    You may choose own team or I can assign

Java test next Tuesday

Teamwork next Thursday (guided by Lifeng Zhang)

 

 

 

Here is information on GUI components in the swing library:

http://java.sun.com/docs/books/tutorial/uiswing/index.html



import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;
 
public class MyGUI{
   static Button B;
   static Frame F;
   public static void main(String args[]){
      F=new Frame("Hello, I am a Frame");
      F.setSize(800,500);
      F.setVisible(true);
      F.setBackground(Color.orange);
      //F.setBackground
      //  (new

      //     Color((float)0.99,

      //     (float)0.0,(float)0.99));
      Font myFont;
      myFont=new Font("TimesRoman",

                      Font.PLAIN, 60);
      Label L=new

                Label

                  ("Type password in box below");
      L.setFont(myFont);
      F.add("North",L);
      F.show();
       
      TextField T;
      T=new TextField("Password Here");
      // T=new TextField( );
      // T=new TextField(20);
      T.setFont(myFont);
      F.add("West",T);
      F.show();
       
      Label L2=new Label("Now click button:");
      L2.setFont(myFont);
      F.add("Center",L2);
      F.show();
       
      B=new Button("Click this button");
      B.setFont(new Font("Helvetica",

                          Font.ITALIC, 60));
      B.setBackground(Color.cyan);
      B.setForeground(Color.red);
      F.add("South",B);
      F.show();
        
      F.setSize(1100,500);
      F.show();
 
      Panel onRight;
      onRight=new Panel( );
      onRight.setLayout
      (new GridLayout(3,1)); //(rows, columns)
      Button B1,B2,B3;
      B1=new Button("Ok");
      B1.setFont(myFont);
      B2=new Button("Cancel");
      B2.setFont(myFont);
      B3=new Button("Menu");
      B3.setFont(myFont);
      onRight.add(B1);
      onRight.add(B2);
      onRight.add(B3);
      F.add("East",onRight);
      F.show();
       
      Menu M;
      M=new Menu("Options");
      M.setFont(myFont);
      
      M.add("save");
      M.add("print");
      M.add("help");
      M.add("status");
       
      Menu N;
      N=new Menu(" More Options");
      N.setFont(myFont);
      N.add("stop");
      N.add("go");
      N.add("go backward");
      N.add("click here for ice cream");
 
      MenuBar MB;
      MB=new MenuBar( );
      MB.add(M);
      MB.add(N);
      F.setMenuBar(MB);
      F.show();
 
      Dialog D;
      D=new Dialog(F, "My dialog box");
      D.setBackground(Color.green);
      // D=Dialog( );
      D.show();
 
      Checkbox C1, C2, C3;
      C1=new Checkbox(
                "Here is a Checkbox in" +

                " the Dialog object..."
             );
      C2=new Checkbox("Hello");
      C3=new Checkbox("Goodbye");
      C1.setFont(myFont);
      C2.setFont(myFont);
      C3.setFont(myFont);
      D.setLayout(new GridLayout(3,1));
      D.add(C1); D.add(C2); D.add(C3);
      D.show();
       
      D.setSize(100,500);
      D.show();
       
      doSomething S=new doSomething();
      B.addActionListener(S);
      T.addActionListener(S);
   }
}
 
class doSomething implements ActionListener{
   public void actionPerformed(ActionEvent e){
      System.out.println(e.getActionCommand());
  }
}