Commit 9db188b4 by Joe Student

casting objects changes

parent f8d888c4
package lec07.glab.casting;
import java.awt.*;
/**
* Created with IntelliJ IDEA.
* User: ag
......@@ -91,13 +93,15 @@ public class CastObjectsDriver {
//toggle uncomment/comment to show compile-time error
//Rectangle recMe = (Rectangle) numMe;
//However, if we try to cast comMe to a Rectangle (Rectangle implements Comparable) the compiler will NOT complain, but of course, we will still throw ClassCastException
//because the underlying object stored in comMe is still of type Double, and Rectangle is not in Double's class hierarchy.
//toggle uncomment/comment this code below to throw a ClassCastException
// Rectangle recMeAgain = (Rectangle) comMe;
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
//Let's go full circle. Casting-down is trivial.
//Let's go full circle. Casting-down is trivial. When you cast down, you are actually opening the aperture.
//The underlying object that objMe points to is of type Double. If it weren't of type Double, we would get a ClassCastException
//We are effectively widening the filter to see all the methods of the original Double object
Double dubMeDown = (Double) objMe;
......
......@@ -36,12 +36,12 @@ public class MockTable {
protected void drawCards(Graphics g) {
BufferedImage bufferedImage;
//use this counter to position the cards horizontally
int nC = 10;
int nXPos = 10;
for (Card card : crdHands) {
bufferedImage = SoundImageUtils.genBuffImage("/src/lec07/glab/jpanel_gui/imgs/" + card + ".png");
//nc = x-pos, 100 = y-pos
g.drawImage(bufferedImage, nC, 100, null);
nC = nC +25;
g.drawImage(bufferedImage, nXPos, 100, null);
nXPos = nXPos +25;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment