Info

2.5 mmmmmmf-mmmm

2.1 mm s ' mwmm-m^n—mam.m± > mmmmrnm^mtt • rüj m g^sfôsm'têwiMm^fôsm °

^fô®m«T«fôj¥#®m'• mmmnm® m °'rn^wm^m; mm••

' M^M^S : mmwmm = n^m m ciMg^) um ' mm cmm^) ^ak; iMgmmwBtii^ïj mtfôsm'i^w-g°airag•äwt«^:

OS(Linux/Windows)

mm abstract f2()

mmcw

pX

f3()

H4Linux m Windows' mMMMMMti^ ' M

4 mmmnrnrnrnT ■ 1. «Afsmr f1()' rn^^m^mr no - kmrn^mmrnm no

4. mmsisr f4() ' /zœmr f4() ° ¿tts^w f4o®» • M f4ow mmm csis) » f4o®»°

Control)IM rMímij ¿IS ° M^M»^ r!ígij ' m^ffi^ffi s ' rEími(mm)j ¿as • itêfflM» rMímmj ¿imr °

IoC OO ^ = (n C++ - Java ' Mn Java iaí ' ^^(Superdass)M»^^fn^^(Subdass)¿®» ' MIM

^Äffi^^mmm > > : • im m ioc = mmm ■ tüf^mags^mm • imm ioc mm • mn

«Mm^^tf (Function Library)a^Wfi#Mm®»(tm) ' M^Cft

abs()i/£a®«mj¥#®» ' trn^&ft ' it* ; ^rn^omm)® ' imm ° = mrnmmrn ° -^mmmclass Library)^

Person ^mmMT :

public class Person {

private String name;

public void SetName(String na) { name = na; } public void Display()

{ System.out.println("Name: " + name ); }

public class customer extends Person {

public void Init() { super. SetName("Tom"); } public void Show() { super.Display(); }

±mm Init()^^rmm SetName()®» ° ' MM JMain mm ■

public class JMain { private p; public void Init() {

mmimmmmmmrnm ° ^rnxm^mrmmmmmmmmm •

public class My Activity extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main):

SP MyActivity)m onCreate()SP Activity)m onCreate()fP setContentView()®m ° M Activity ^g Android g^gmS^ffia^B 0

2.2.2 KftPS

^mrnrn^xmrnm • xmm^mm^A^fm^mm^mm ° si^asb m' rn^mvi'g ° g^gmwara^g^MASBmnA • RgAW-^mm smra' ' AAAMmsm • gmftraM^muAmA®

// Shape.java package _framework; public class Shape {

public void Paint() { this.Draw(); } public abstract void Draw();

Draw()sm ' J^gf! PaintOWA^Bm Draw()®m ° DrawO,^ASB(M«)A^AA ' MT =

// Circle.java package _objects; import j ava. awt. Color; import java.awt.Graphics; import _framework.*;

public class Circle extends Shape { private Graphics m_gr; private int x, y, radius; public Circle(Graphics gr) { m_gr = gr; } public void SetValue(int x0, int y0, int rad){ x = x0; y = y0; radius = rad;

public void Draw(){

m_gr.setColor(Color.SZ^C^);

m_gr.drawOval(x-radius, y-radius, 2*radius, 2*radius);

// JMain.java import java.awt.*; import j avax. swing. *; import _framework.Shape; import _objects.*;

class JP extends JPanel {

public void paintComponent(Graphics gr) { super.p aintComponents (gr); Circle cir = new Circle(gr); cir.SetValue(160, 100, 45); Shape sp = cir; sp.Paint();

public class JMain extends JFrame {

public JMain() { setTitle(""); setSize(400, 300); } public static void main(String[] args) { JMain frm = new JMain(); JP panel = new JP(); frm.add(panel);

frm.setDefaultCloseOperation(JFrame.£A7r_0N_CZaS£); frm.setVisible(true);

M (Inversion of Control)0

public class MyView extends View { private Paint paint; public MyView(Context context) { super(context);

private Paint paint= new Paint(); }

public void ReDraw() { this.invalidate(); } @Override protected void onDraw(Canvas canvas) { // paint. setAntiAlias(true); paint. setColor(Color. YELLOW); canvas.clipRect(30, 30, 100, 100);

ReDraw()®m^ ' IMW^ Android g^M invalidate()® mT ° S^ ' Android MyView i^M® onDraw()®m ° MI

Person

Customer

MM Java U&^MZUT

// Person.java package _abstract_classes; public abstract class Person { protected String name;

public void setName(String na) { name = na; } public abstract void display();

// Customer.java package _abstract_classes; public class Customer extends Person { public void display()

{ System.out.println("Customer: " + super.name); }

// VIP.java package _concrete_classes; import _abstract_classes.*; public class VIP extends Customer { private String tel; public VIP(String na, String t) { super.setName(na); tel = t;

public void display() { super.display();

H^ VIP() f m m setName() ® ^ ' & display() f ^

Customer::display()®m ' MWMftmm ° AW ' fMAAmSWWgmA

H 2-4

// Product.java package _abstract_classes; public abstract class Product { protected int pno; protected Customer cust; public Product(int no) { pno = no; } public void soldTo(Customer cobj) { cust = cobj; } public void inquire() { this.print();

System.out.println("sold to ..."); cust.display();

public abstract void print();

// TV.java package _concrete_classes; import _abstract_classes.*; public class TV extends Product { private double price; public TV(int no, double pr) {

public void print() {

System. oM?.println("TV No: " + pno); System.oM?.println("Price: " + price);

public class Product { public void inquire() {

public class Customer extends Person {

public class TV extends Product {

public class VIP

extends Customer { public void display() {

// JMain.java import _abstract_classes.*;

import _concrete_classes.*; public class JMain {

public static void main(String[] args) { TV t = new TV(1100, 1800.5); VIP vp = new VIP("Peter", "666-8899"); t.soldTo(vp); t.inquire();

Product ^S^ISff^A ' ^MAffiA TV AS^ ' MMAA^AmiSff ° ^jj ' TO Product S^l inquire() TV SBUl print()®M? M

public abstract void print();

public void print() {

System. out.println("TV No: " + pno); System.out.println("Price: " + price);

ft^ ' Product SBUl inquire() ^^ VIP SBUl display()®^ ° Product SBU

m Customer lMSIx^ dlsplay() ' M^WW VIP dlsplay()®» ° ^

^ ' ZMWP^MS = MWcustüm^W^^ VIP= S^T ' fflalM^ISff^ ' M^PlSKMM ° ' l£ff Product | M ' VIP im^HM! Mg^MTmMM^Sa :

gf^ ' ÍM^MjtfflMg^fflffi Product

M$P ' TVlMprint(){£ mqulre()W£ ' M VIP dlsplay(){£ lnqulre()

0 0

Post a comment