SlideShare a Scribd company logo
Lab 7 – 8:
  Memory Game

 The Final Stretch!

 Victoria A. Minorczyk
Davis 302 | Thurs 1-1:50
vaminorc@buffalo.edu
For Lab 7,
              at the start of your program…
Your window should                                    Note:
look something like this.                    -cards should NOT over
It should contain only                           lap each other.
TWO cards, showing the                     -cards should be displayed
back of the card.                                at 128 pixels by
                                                    160 pixels



When you                    When the
click on a                  same card is
card, it                    clicked, it
should flip                 should flip
over (show                  back over
the front                   (show the
of the                      back of the
card.)                      card again)
A little about ‘extends’ in Java
SYNTAX – How do I write this in my code?
• The keyword extends is to be specified in the HEADER of a CLASS
• It’s syntax is as follows:
         <access control modifier> class <class name> extends <class name>
• For example: public class Basketball extends Ball
SEMANTICS – What does it mean?
• When class A extends class B, you may think of class A as a literal extension of class
  B
• Class A will retain ALL of it’s own attributes, properties and methods, and…
• Class A will also inherit all of class B’s attributes, properties, and methods.
• Class B does NOT gain any additional attributes, properties, or methods from class
  A.
                     For this lab, your
           GameBoard class will extend JPanel.
                           So…
         EVERYTHING that you can do with a JPanel
             you can do with your GameBorad!
                             
public class BasicMath {                         public class AdvancedMath extends BasicMath{

    public int add(int x, int y) {                 public int specialFunction(int a, int b){
      return x + y;
    }                                                  /*Notice how the add, mult, and sub methods
                                                       are not defined in AdvancedMath. However,
    public int sub(int x, int y){                      because AdvancedMath extends BasicMath, it
      return x - y;                                    inherits all the methods in BasicMath!*/
    }
                                                       int answer = this.add(a,0);
    public int mult(int x, int y){                     answer = this.mult(answer, 2);
      return x*y;                                      answer = this.sub(answer, b);
    }
                                                       return answer;
    public void printAns(int x){                   }
      System.out.println("The answer is: " + x);
    }                                            }

}
public class Calculations {                                   public class Computer {

    public static void main(String[] args){                       private BasicMath _b;

        AdvancedMath calculator = new AdvancedMath();             public Computer(BasicMath b){
        //AdvancedMath has specialFunction defined                  _b = b;
        int a = calculator.specialFunction(5,2);                  }
        int b = calculator.specialFunction(8,3);
                                                              }
        /*Notice how the printAns method is defined in
         * the BasicMath class and is NOT defined in the
         * AdvancedMath class. However, we can still invoke
         * the printAns method on an AdvancedMath object
         * because AdvancedMath extends BasicMath.*/
        calculator.printAns(a);
        calculator.printAns(b);

        /*Notice that the parameter for a Computer is a
         * BasicMath object However, it is acceptable to
         * use an AdvanceMath object, because AdvancedMath
         * extends BasicMath*/
        Computer comp = new Computer(new AdvancedMath());
    }
}
Displaying Images
ImageIcon Objects:
• Use javax.swing.ImageIcon objects to display images
• When instantiating an ImageIcon object, you must supply a path name as an
  argument. For example…
• new ImageIcon(“FolderName/PackageName/FileName.jpg”);
• HOWEVER, you can NOT add an ImageIcon oject directly to a JPanel object

Adding Images to a JPanel:
*Recall* - You can add JLabel objects directly to a JPanel object
• Use a JLabel to hold your ImageIcon objects!
*Recall* - JLabel has a ‘setText’ method to change the text the JLabel displays
• Use the JLabel ‘setIcon’ method to change the Icon the JLabel displays
 Awesome If-Else Statements 
Syntax:
      if ( <condition> ) {
              <if-body>
      }
      else {
              <else-body>
      }

Semantics:
If the condition is TRUE, only the if-body is executed.
If the condition is FALSE, only the else-body is executed.
 Awesome If-Else Statements 
public class IfElseClass {

public static void main (String[] args){
int x = -5;
int y = 1;

if (x < y){
//Executes ONLY when condition is TRUE
System.out.println("Condition was TRUE. " + x + " is less than " + y);

}
else{
//Executes ONLY when condition is FALSE
System.out.println("Condition was FALSE. " + x + " is not less than " + y);

}.
Overview
GameBoard
• Extends JPanel class
• Responsible for putting two cards to itself
Card
• Responsible for keeping track of two ImageIcons (one for
  face-up image and one for face-down image)
• Responsible for knowing if the Card is face-up or face-
  down
LableListener
• Handles events for the “cards” or the JLables
• When a card is clicked, the IconImage on the JLable
  should change.

More Related Content

Similar to Lab 7 – 8 (Part 1)

CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ Homework Help
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
rd1742
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
R. Sosa
 
Lecture 7.pdf
Lecture 7.pdfLecture 7.pdf
Lecture 7.pdf
SakhilejasonMsibi
 
Virtual Method Table and accident prevention
Virtual Method Table and accident preventionVirtual Method Table and accident prevention
Virtual Method Table and accident prevention
Andrey Karpov
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
SantoshVarshney3
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
simonlbentley59018
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of featuresvidyamittal
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
irshadkumar3
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext js
Mats Bryntse
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegro
snowfarthing
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Fwdays
 

Similar to Lab 7 – 8 (Part 1) (20)

CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Lecture 7.pdf
Lecture 7.pdfLecture 7.pdf
Lecture 7.pdf
 
Virtual Method Table and accident prevention
Virtual Method Table and accident preventionVirtual Method Table and accident prevention
Virtual Method Table and accident prevention
 
Introduction to-java
Introduction to-javaIntroduction to-java
Introduction to-java
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
 
C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of features
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
SenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext jsSenchaCon 2010: Developing components and extensions for ext js
SenchaCon 2010: Developing components and extensions for ext js
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

Lab 7 – 8 (Part 1)

  • 1. Lab 7 – 8: Memory Game The Final Stretch! Victoria A. Minorczyk Davis 302 | Thurs 1-1:50 vaminorc@buffalo.edu
  • 2. For Lab 7, at the start of your program… Your window should Note: look something like this. -cards should NOT over It should contain only lap each other. TWO cards, showing the -cards should be displayed back of the card. at 128 pixels by 160 pixels When you When the click on a same card is card, it clicked, it should flip should flip over (show back over the front (show the of the back of the card.) card again)
  • 3. A little about ‘extends’ in Java SYNTAX – How do I write this in my code? • The keyword extends is to be specified in the HEADER of a CLASS • It’s syntax is as follows: <access control modifier> class <class name> extends <class name> • For example: public class Basketball extends Ball SEMANTICS – What does it mean? • When class A extends class B, you may think of class A as a literal extension of class B • Class A will retain ALL of it’s own attributes, properties and methods, and… • Class A will also inherit all of class B’s attributes, properties, and methods. • Class B does NOT gain any additional attributes, properties, or methods from class A. For this lab, your GameBoard class will extend JPanel. So… EVERYTHING that you can do with a JPanel you can do with your GameBorad! 
  • 4. public class BasicMath { public class AdvancedMath extends BasicMath{ public int add(int x, int y) { public int specialFunction(int a, int b){ return x + y; } /*Notice how the add, mult, and sub methods are not defined in AdvancedMath. However, public int sub(int x, int y){ because AdvancedMath extends BasicMath, it return x - y; inherits all the methods in BasicMath!*/ } int answer = this.add(a,0); public int mult(int x, int y){ answer = this.mult(answer, 2); return x*y; answer = this.sub(answer, b); } return answer; public void printAns(int x){ } System.out.println("The answer is: " + x); } } }
  • 5. public class Calculations { public class Computer { public static void main(String[] args){ private BasicMath _b; AdvancedMath calculator = new AdvancedMath(); public Computer(BasicMath b){ //AdvancedMath has specialFunction defined _b = b; int a = calculator.specialFunction(5,2); } int b = calculator.specialFunction(8,3); } /*Notice how the printAns method is defined in * the BasicMath class and is NOT defined in the * AdvancedMath class. However, we can still invoke * the printAns method on an AdvancedMath object * because AdvancedMath extends BasicMath.*/ calculator.printAns(a); calculator.printAns(b); /*Notice that the parameter for a Computer is a * BasicMath object However, it is acceptable to * use an AdvanceMath object, because AdvancedMath * extends BasicMath*/ Computer comp = new Computer(new AdvancedMath()); } }
  • 6. Displaying Images ImageIcon Objects: • Use javax.swing.ImageIcon objects to display images • When instantiating an ImageIcon object, you must supply a path name as an argument. For example… • new ImageIcon(“FolderName/PackageName/FileName.jpg”); • HOWEVER, you can NOT add an ImageIcon oject directly to a JPanel object Adding Images to a JPanel: *Recall* - You can add JLabel objects directly to a JPanel object • Use a JLabel to hold your ImageIcon objects! *Recall* - JLabel has a ‘setText’ method to change the text the JLabel displays • Use the JLabel ‘setIcon’ method to change the Icon the JLabel displays
  • 7.  Awesome If-Else Statements  Syntax: if ( <condition> ) { <if-body> } else { <else-body> } Semantics: If the condition is TRUE, only the if-body is executed. If the condition is FALSE, only the else-body is executed.
  • 8.  Awesome If-Else Statements  public class IfElseClass { public static void main (String[] args){ int x = -5; int y = 1; if (x < y){ //Executes ONLY when condition is TRUE System.out.println("Condition was TRUE. " + x + " is less than " + y); } else{ //Executes ONLY when condition is FALSE System.out.println("Condition was FALSE. " + x + " is not less than " + y); }.
  • 9. Overview GameBoard • Extends JPanel class • Responsible for putting two cards to itself Card • Responsible for keeping track of two ImageIcons (one for face-up image and one for face-down image) • Responsible for knowing if the Card is face-up or face- down LableListener • Handles events for the “cards” or the JLables • When a card is clicked, the IconImage on the JLable should change.