CS100A, Fall 1997. Lecture, 4 Nov. 1 CS100A, Fall 1997 Lecture 4 November: OTHELLO Goals: Introduce you to assignment 8. Let you have fun with the game.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 32 – Java Graphical User Interfaces (GUIs) Webpage:
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
By Dr. Jiang B. Liu 3. Graphic User Interface using AWT.
Contructing GUI’s in Java Implemented in the Swing API Imported into your programs by: import javax.swing.*; Most Swing programs also need the AWT packages.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Games and Simulations O-O Programming in Java The Walker School
Chapter 5 - Making Music: An On-Screen Piano
Io package as Java’s basic I/O system continue’d.
Java: Chapter 1 Computer Systems Computer Programming II Aug
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Even-Driven Programming and basic Graphical User Interface.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
1 Lesson: Applets with User Input and Output with GUI ICS4M.
ITEC 109 Lecture 27 GUI. GUIs Review Sounds –Arrays hold sample values –Creating a keyboard –Sound effects Homework 3 –The big two –Due after break –Lab.
CS100A, Lecture 16, 27 October CS100A Lecture October 1998 Assignment 7: A Checker-playing program: learning about GUIs and working with a.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Computer Programming with JAVA Chapter 7. Event-Driven Programming Using the AWT Event-Driven Programming GUIs and the AWT Simple Window Interfaces Components,
Chapter 7Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 7 l Event-Driven Programming »GUIs and the AWT l Simple Window.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
May 12, 1998CS102-01Lecture 7-3 Building GUIs in Java I CS Lecture 7-3 A picture's worth a thousand words.
Csc Basic Graphical User Interface (GUI) Components.
1 Lecture 25 Listening to buttons and mice Quotes by Tony Hoare There are two ways of constructing a software design: (1) make it so simple that there.
Graphical User Interfaces Tonga Institute of Higher Education.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Creating a GUI Class An example of class design using inheritance and interfaces.
Graphical User Interfaces (GUI). PART ONE About GUI’s.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
CSC 205 Programming II Lecture 5 AWT - I.
Java GUI.
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Introduction to Programming
AWT Components and Containers
Constructors, GUI’s(Using Swing) and ActionListner
A picture's worth a thousand words
Presentation transcript:

CS100A, Fall Lecture, 4 Nov. 1 CS100A, Fall 1997 Lecture 4 November: OTHELLO Goals: Introduce you to assignment 8. Let you have fun with the game Othello. Introduce you to graphical user interfaces (GUIs) and the Java abstract window toolkit (awt). You don’t have to write code that effects the GUI, but you should understand fully what is going on in the Othello program. Discuss two-dimensional arrays (which are used in this assignment 8; you will write code that deals with the arrays and plays the game). There is a lot to read, a lot to learn. But it’s worthwhile! Start Early!!!!!

CS100A, Fall Lecture, 4 Nov. 2 Here is the game board of the game Othello. It’s an 8x8 board of green squares onto which pieces can be placed. The pieces are black on one side and white on the other. Help You can play Othello on the web. Access the CS100A home page, find assignment 8, and click on the appropriate link to play the game. Click the HELP button for help.

CS100A, Fall Lecture, 4 Nov. 3 Basic play for white (black is similar). Place a white piece in an empty square that is at one end of a sequence of black pieces and that has a white piece at the other end. Turn over the black pieces just described, in all 8 directions. Play here and turn these over (make them white).

CS100A, Fall Lecture, 4 Nov. 4 The Java Abstract Window Toolkit (awt): A collection of classes that provides facilities for writing graphical user interfaces (GUIs) Each square is an instance of class Canvas instances of class Button instances of class Label The area that comes here when you press Help The whole window is an is an instance instance of class Frame of TextArea.

CS100A, Fall Lecture, 4 Nov. 5 The next four slides contain a class, an extension of Frame, that can be used to illustrate many of the features of the awt. The class places an Othello square (a Canvas), a Label, a TextField, a TextArea, and two titles in the Frame. We use this class in the lecture to illustrate: How layout manager GridBagLayout is used to place components in its rectangular grid. How to say that the Frame should not be resized. How gbc.fill is used to indicate how a component should be resized when the Frame is resized. How weights are used to guide resizing of components. That a component use more than one element of the grid. Events: How the pressing of a mouse button is communicated to the program. (See method action.) Events: How a mouse-up event (and other mouse events) and a click in the window-destroy box are communicated to the program. (See method handleEvent.) This class will be in file Experiment.java on our home page, so you can try it yourself. Add it to your project and place the following statement in method main: Experiment ex= new Experiment ( );

CS100A, Fall Lecture, 4 Nov. 6 import java.awt.*; // Frame to illustrate the awt. public class Experiment extends Frame { // Components that go in the frame OthelloSquare sq; Label lab; TextField textf; TextArea texta; // Titles for buttons String[ ] buttons= {"new game", "quit"}; // The layout and constraint variables for this frame GridBagLayout gbl; GridBagConstraints gbc; final int xweight= 100; // Weights for all components final int yweight= 100; // when they are resized

CS100A, Fall Lecture, 4 Nov. 7 // Constructor: a frame with the above components public Experiment() { super(”Experiment"); gbl= new GridBagLayout(); gbc= new GridBagConstraints(); setFont(new Font("Dialog", Font.PLAIN, 10)); setLayout(gbl); gbc.fill= gbc.BOTH; sq= new OthelloSquare(0,0); add(sq,gbl,gbc,0,0,1,1,xweight,yweight); lab= new Label("A label at (1,1)"); add(lab, gbl,gbc,1,1,1,1,xweight,yweight); textf= new TextField("A TextField at (1,2)"); add(textf,gbl,gbc,1,2,1,1,xweight,yweight); texta= new TextArea("A TextArea at (1,3)"); add(texta,gbl,gbc,1,3,1,1,xweight,yweight); add(new Button(buttons[0]),gbl,gbc, 2,0, 1,1, xweight,yweight); add(new Button(buttons[1]),gbl,gbc, 3,0, 1,1, xweight,yweight); pack(); move(150,50); show(); //setResizable(false); }

CS100A, Fall Lecture, 4 Nov. 8 // Add c to gbl with constraints gbc at position (x,y). // c takes w cols and r rows, and is weighted (wx, wy). private void add(Component c, GridBagLayout gbl, GridBagConstraints gbc, int x, int y, int w, int h, int wx, int wy){ gbc.gridx= x; gbc.gridy= y; gbc.gridwidth= w; gbc.gridheight= h; gbc.weightx= wx; gbc.weighty= wy; gbl.setConstraints(c, gbc); add(c); } // If a button was pressed, process it; else, return false public boolean action(Event e, Object arg) { if (arg.equals(buttons[0])) { System.out.println("\"new game\" pressed"); return true; } if (arg.equals(buttons[1])) { System.out.println("\"Quit\" pressed"); System.out.println("TextField is: \"" + textf.getText() + "\""); System.out.println("selection is: \"" + textf.getSelectedText() + "\""); return true; } return false; }

CS100A, Fall Lecture, 4 Nov. 9 // Process press of WINDOW_DESTROY or // mouse up in an Othello square --return super.handleEvent(e) // if the even is not one of those. public boolean handleEvent(Event e) { //System.out.println("" + e); if (e.id == Event.WINDOW_DESTROY) { System.out.println("Window destroy clicked"); //dispose(); return true; } if (e.id == Event.MOUSE_UP && e.target instanceof OthelloSquare) { System.out.println("Mouse up in Othello square"); return true; } return super.handleEvent(e); }

CS100A, Fall Lecture, 4 Nov. 10 On to Othello! Variable b[ ] [ ] will be an 8 x 8 array of elements of class OthelloSquare. Each element of class OthelloSquare maintains (0) its column and row number in the square. (1) whether it is empty, contains a white piece, or contains a black piece. The OthelloSquare constructor saves the col and row number, makes the square empty, and gives it a “preferred” size of 42 x 42 pixels. Since it is an extension of Canvas, it contains method paint(graphics g), which paints the square. It also has three methods: (0) Contents, which returns what piece it contains (or EMPTY). (1) pickUpPiece, which makes the square empty. (2) placePiece(p), which puts piece p on the square (if thesquare is empty).

CS100A, Fall Lecture, 4 Nov. 11 Mapping the Othello Board onto the Frame (0,0) (1,0) (7,0) 2 3 (0,1) (1,1) (7,10) Button Label

CS100A, Fall Lecture, 4 Nov. 12 Section this week Section this week will deal with two-dimensional arrays and the way they are used in this game. Don’t miss section.

CS100A, Fall Lecture, 4 Nov. 13

CS100A, Fall Lecture, 4 Nov. 14 From: Jeffrey HarradineFrom: Hector Yee A team of cornell students have set up a distributed computing effort to coordinate participation in projects such as breaking the rc5 64-bit encryption (RSA sponsored competition) and a distributed computing initiative to scan 2 KHz chunks of the radio spectrum for intelligent signals from elsewhere.If you have spare cycles on your home machine to spare, please do join us in the rc 5 competition. More information can be found at: Instructions to join our mailing list are included. Our team, Big Red, is ranked eleventh in the world as of now in the RC5-64 competition. If you do join us, we are team ID 38. Team Stats: RC5 competition: Please use personal computers for these projects as the lab administrators do not think it is an appropriate use of lab facilities. The programs use only idle time and can even be run offline. We might embark on our own distributed computing programs in the future if we gather enough programming talent and interest. Thanks for your time and interest!