70 likes | 185 Views
Supplier Class. import java.awt.Color ; import javax.swing.JFrame ; public class Target { private Oval outerWhiteOval , redOval , innerWhiteOval , blueOval ; public Target( int x, int y, int s) { int eighthS = ( int )(s / 8.0); outerWhiteOval = new Oval(x, y, s, s);
E N D
Supplier Class import java.awt.Color; import javax.swing.JFrame; public class Target { private Oval outerWhiteOval, redOval, innerWhiteOval, blueOval; public Target(int x, int y, int s) { inteighthS = (int)(s / 8.0); outerWhiteOval = new Oval(x, y, s, s); outerWhiteOval.setBackground(Color.white); redOval = new Oval(eighthS, eighthS, 6*eighthS, 6*eighthS); redOval.setBackground(Color.red); outerWhiteOval.add(redOval); innerWhiteOval = new Oval(eighthS, eighthS, 4*eighthS, 4*eighthS); innerWhiteOval.setBackground(Color.white); redOval.add(innerWhiteOval); blueOval = new Oval(eighthS, eighthS, 2*eighthS, 2*eighthS); blueOval.setBackground(Color.blue); innerWhiteOval.add(blueOval); } public void addTargetTo(JFramejf) { jf.add(outerWhiteOval); } }
Client Class import java.awt.Color; import javax.swing.JFrame; public class Driver { private JFrame win; private Target leftTarget, rightTarget, bigTarget; public Driver() { win = new JFrame("Targets"); win.setBounds(20, 20, 600, 500); win.getContentPane().setBackground(Color.black); win.setLayout(null); win.setVisible(true); leftTarget = new Target(10, 10, 100); leftTarget.addTargetTo(win); rightTarget = new Target(490, 10, 100); rightTarget.addTargetTo(win); bigTarget = new Target(200, 250, 200); bigTarget.addTargetTo(win); win.repaint(); } public static void main(String[] args) { new Driver(); } }
Another Supplier Class public class Fraction { private int numerator; private int denominator; public Fraction(int n, int d) { numerator = n; denominator = d; simplify(); } public intgetNumerator() { return numerator; public intgetDenominator() { return denominator; } public void add(Fraction f) { … } public void multiply(Fraction f) { numerator = numerator*f.getNumerator(); denominator = denominator*f.getDenominator(); simplify(); } private void simplify() { … } }