1 / 7

import java.awt.Color ; import javax.swing.JFrame ; public class Target {

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);

baina
Download Presentation

import java.awt.Color ; import javax.swing.JFrame ; public class Target {

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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); } }

  2. 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(); } }

  3. 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() { … } }

More Related