'분류 전체보기'에 해당되는 글 84건

  1. 2010.08.13 자바 소수점 출력
  2. 2010.08.13 [RelativeLayout] 0. 레이아웃 만들기
  3. 2010.08.13 생성자와 소멸자
  4. 2010.08.13 XML 문법
  5. 2010.08.12 [CustomView] 4. Thread 이용하여 그림 움직이기
  6. 2010.08.12 [CustomView] 3. RobotView 그림 위치 지정 - 성공
  7. 2010.08.12 [CustomView] 1. 그림 정가운데 출력
  8. 2010.08.11 1일차
  9. 2010.08.11 [CustomView] 0. RobotView 생성
  10. 2010.07.26 C# 기본

자바 소수점 출력

|

double d = Double.parseDouble(String.format("%.3f", 1.4455555));
 System.out.println(d);

'Java' 카테고리의 다른 글

Exception  (0) 2010.08.23
자바 주요 클래스  (0) 2010.08.19
static vs final  (0) 2010.08.17
내부 클래스 용도  (0) 2010.08.17
주민등록번호 추출  (0) 2010.08.16
And

[RelativeLayout] 0. 레이아웃 만들기

|

#RelativeLayout
RelativeLayoutTest.java
1. findViewById()로 버튼 객체 선택. final로 선언되어 있어야 함.
2. 버튼에 이벤트 리스너 설정.
package net.itisn.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class RelativeLayoutTest2 extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		//리소스에서 버튼을 가져옴
		final Button buttonCancel = (Button)this.findViewById(R.id.ButtonCancel);
		//리소스에서 에디트텍스트를 가져옴
		final EditText editText = (EditText)this.findViewById(R.id.EditText01);

		//취소 버튼에 이벤트 추가
		buttonCancel.setOnClickListener(new OnClickListener() {

			@Override//클릭했을 때 에디트텍스트에 문자열 출력
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				editText.setText("Button is Pushed.");
			}

		});
	}
}

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
>
	<TextView
		android:text="@+id/TextView01"
		android:id="@+id/TextView01"
		android:layout_height="wrap_content"
		android:layout_width="fill_parent"
	></TextView>
	<EditText
		android:text="@+id/EditText01"
		android:id="@+id/EditText01"
		android:layout_below="@id/TextView01"
		android:layout_height="wrap_content"
		android:layout_width="fill_parent"
	></EditText>
	<Button
		android:layout_below="@id/EditText01"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="Cancel"
		android:id="@+id/ButtonCancel"
	></Button>
	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="OK"
		android:id="@+id/ButtonOK"
		android:layout_below="@+id/EditText01"
		android:layout_toRightOf="@+id/ButtonCancel"
	></Button>
</RelativeLayout>



- END -

'Android' 카테고리의 다른 글

[ShapeEx]  (0) 2010.08.16
[.java로 View Control]  (0) 2010.08.16
XML 문법  (0) 2010.08.13
[CustomView] 4. Thread 이용하여 그림 움직이기  (0) 2010.08.12
[CustomView] 3. RobotView 그림 위치 지정 - 성공  (0) 2010.08.12
And

생성자와 소멸자

|
생성자
클래스와 동일한 이름
반환 값이 없다.
객체가 생성될 때 자동으로 호출된다.
생성자를 작성하지 않으면 기본 생성자가 자동으로 호출된다. Class::Class() {}
Point::Point() { _x = 0; _y = 0; }
Point pt;
Point pt = Point();

디폴트 생성자
인자가 없는 생성자 Class::Class() { initialize code; }
Point pt;
Point pt = Point();

인자가 있는 생성자
Point::Point(int x, int y) {_x = x; _y = y; }
Point pt(10, 20);

복사 생성자
자신과 동일한 타입의 객체에 대한 레퍼런스를 인자로 받는 생성자.
Class::Class(Class& c) { intialize code; }
Class::Class(const Class& c) { intialize code; } 권장
Point::Point(const Point& pt) { x = pt.x; y = pt.y; }
Point pt1;
Point pt2 = pt1; (초기화 문법 이용)
Point pt2(pt1); (생성자 호출 문법 이용)
*초기화 : 생성과 동시에 값을 대입하는 것???
Point pt1;
Point pt2;
pt2 = pt1; 복사 생성자가 호출되지 않고, 멤버변수를 1:1로 복사한다.

class string
{
private:
char* p;
public:
string(const string& s);
int size() const
{
return strlen(p);
}
...

Shallow Copy
string::string(const string& s) { p = s.p; }
string str1;
string str2(str1);
str1 객체의 문자열의 시작 주소만 복사된다. str1 객체가 소멸되면 str1이 가리키고 있던 문자열도 소멸되므로 str2는???
Deep Copy
string::string(const string& s) { p = new char[s.Size() + 1]; strcpy(p, s.p);
string str1;
string str2(str1);
str1 객체의 문자열 자체를 복사한다. str1 객체가 소멸되어도 str2 객체는 새로 생성된 문자열의 시작주소를 가리키므로 문제없다.

반드시 생성자가 필요한 경우 : const, &
const : 한 번 정의된 이후에는 값을 변경할 수 없으므로 반드시 초기화하여 그 값만을 가져야 한다.
& : 처음 정의할 때 참조한 변수 이외의 다른 변수는 참조할 수 없으므로 반드시 초기화해야 한다.

class NeedConstructor
{
public:
const int maxCount;
int& ref;
int sample;

NeedConstructor();
NeedConstructor(int count, int& number);
};

NeedConstructor::NeedConstructor()
: maxCount(100), ref(sample)
{
sample = 200;
}

NeedConstructor::NeedConstructor(int count, int& number)
: maxCount(count), ref(number0
{
sample = 200;
}

생성자를 이용한 임시 객체
void Func(const Point& pt)
{
...
}
Func(Point(x, y));

소멸자
DynamicArray::DynamicArray(int arraySize)
{
arr = new int [arraySize];
}

DynamicArray::~DynamicArray()
{
delete [] arr;
arr = NULL;
}

main() 죵료시 함수 내의 객체도 소멸되므로 소멸자를 호출하고 이 때 메모리를 해제한다. 













import android.view.View.oonclickelisterne;

setContentView(R.laout.hello_layout);

EditText edittext = (EditiText)this.findViewById(R.id.EditText01);
Button button = (button)this.findViewById(R.id....);
button.setonclickelistenter(new onclicklistener() {

 } )

public onClick(View arg0) {
edittext.setText("버튼 눌러짐"); << final 처리 변수 -- final EditText edit~~~

'C++' 카테고리의 다른 글

다중 상속의 문제점  (0) 2010.08.16
C++ 생성자  (0) 2010.08.13
c++ 오버라이딩  (0) 2010.07.03
동적 할당 0614  (0) 2010.06.14
c++ 0610  (0) 2010.06.10
And

XML 문법

|
선언
<?xml version="버전 번호" encoding="인코딩 방식" standalone="yes|no"?>
<와 ?와 xml 사이에 공백이 있으면 안됨.

standalone
작성된 XML 문서를 XML 파서가 해석할 때 외부 DTD 문서를 참고해야 한다는 것을 XML 파서에게 알려주기 위한 목적
yes : DTD 문서를 참고하지 않고 XML 문서 해석
no : DTD 문서를 참고하여 XML 문서 해석
보통 생략하는데 생략시 no로 설정됨

DOM : 전체를 읽어서 추출
SAX : 파일을 읽으면서 처리

Ctrl + Shift + F : 자동으로 정렬, 옵션을 줄 수 있다.
Ctrl + I : 자동으로 정렬

XML 소스 정렬
Preference - XML - Editor - Split, Align


xmlns 네임스페이스
xmlns:android="http://schemas.android.com/apk/res/android"

android 네임스페이스
android:layout_width="fill_parent"

string.xml : Add > name, value 작성
main.xml : Text 태그의 android:id="@+id/text" -> android:text="@string/my_name"

And

[CustomView] 4. Thread 이용하여 그림 움직이기

|
#Thread 이용하여 그림 움직이기

[RobotView.java]
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class RobotView extends View implements Runnable {
    private final static int STEP = 10;
    private Drawable image;
    private int viewWidth, viewHeight;
    private int imageWidth, imageHeight;
    private int x, y;

    public RobotView(Context context, AttributeSet attrs) {
    	super(context, attrs);
    	// TODO Auto-generated constructor stub
    	image = this.getResources().getDrawable(R.drawable.su);

    	Thread thread = new Thread(this);
    	thread.start();
    }

    @Override
    protected void onDraw(Canvas canvas) {
    	// TODO Auto-generated method stub
    	image.setBounds(x, y, x + imageWidth, y + imageHeight);
    	image.draw(canvas);

    	super.onDraw(canvas);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    	// TODO Auto-generated method stub
    	viewWidth = this.getWidth();
    	viewHeight = this.getHeight();

    	imageWidth = image.getIntrinsicWidth();
    	imageHeight = image.getIntrinsicHeight();

    	x = viewWidth / 2 - imageWidth / 2;
    	y = viewHeight / 2 - imageHeight / 2;

    	super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    public void run() {
    	// TODO Auto-generated method stub
    	for (; ;) {
    		try {
    			Thread.sleep(500);
    			y = Math.min(viewHeight - imageHeight, y + STEP);
    			this.postInvalidate();
    		} catch(InterruptedException e) {
    			e.printStackTrace();
    		}
    	}
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    	// TODO Auto-generated method stub
    	x = (int)event.getX();
    	y = (int)event.getY();
    	this.invalidate();

    	return super.onTouchEvent(event);
    }
}

[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<net.itisn.test.RobotView
    android:id="@+id/su"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    />

</LinearLayout>



sleep을 쓸 경우 InterrupedException 예외 발생
따라서 try catch 문을 반드시 써주어야 함

static 클래스는 new 연산자 없이 바로 사용가능. 
Math.min
System.out.println(); 
원래 System sys = new System();
sys.out.println()

postInvalidate() 화면을 새로 그림..

ontouchEvent
x = (int)event.getx();
y = (int)event.gety();

this.invalidate();

return true;

- END

'Android' 카테고리의 다른 글

[RelativeLayout] 0. 레이아웃 만들기  (0) 2010.08.13
XML 문법  (0) 2010.08.13
[CustomView] 3. RobotView 그림 위치 지정 - 성공  (0) 2010.08.12
[CustomView] 1. 그림 정가운데 출력  (0) 2010.08.12
[CustomView] 0. RobotView 생성  (0) 2010.08.11
And

[CustomView] 3. RobotView 그림 위치 지정 - 성공

|
#onSizeChanged()에서 그림 위치 셋팅 - 그림이 정상적으로 그려짐
[RobotView.java]
onSizeChanged()를 오버라이드하여 그 안에 작성한다.
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class RobotView extends View {

    private Drawable image;
    private int viewWidth, viewHeight;
    private int imageWidth, imageHeight;
    private int x, y;

    public RobotView(Context context, AttributeSet attrs) {
    	super(context, attrs);
    	// TODO Auto-generated constructor stub
    	image = this.getResources().getDrawable(R.drawable.su);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    	// TODO Auto-generated method stub
    	image.draw(canvas);
    	super.onDraw(canvas);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    	// TODO Auto-generated method stub
    	viewWidth = this.getWidth();
    	viewHeight = this.getHeight();

    	imageWidth = image.getIntrinsicWidth();
    	imageHeight = image.getIntrinsicHeight();

    	x = viewWidth / 2 - imageWidth / 2;
    	y = viewHeight / 2 - imageHeight / 2;
    	image.setBounds(x, y, x + imageWidth, y + imageHeight);

    	super.onSizeChanged(w, h, oldw, oldh);
    }
}

[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<net.itisn.test.RobotView
    android:id="@+id/su"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    />

</LinearLayout>

'Android' 카테고리의 다른 글

[RelativeLayout] 0. 레이아웃 만들기  (0) 2010.08.13
XML 문법  (0) 2010.08.13
[CustomView] 4. Thread 이용하여 그림 움직이기  (0) 2010.08.12
[CustomView] 1. 그림 정가운데 출력  (0) 2010.08.12
[CustomView] 0. RobotView 생성  (0) 2010.08.11
And

[CustomView] 1. 그림 정가운데 출력

|
#RobotView 이미지 가운체 드로우
[RobotView.java]
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class RobotView extends View {

    private Drawable image;

    public RobotView(Context context, AttributeSet attrs) {
    	super(context, attrs);
    	// TODO Auto-generated constructor stub
    	image = this.getResources().getDrawable(R.drawable.su);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    	// TODO Auto-generated method stub
    	int viewWidth = this.getWidth();
    	int viewHeight = this.getHeight();

    	int imageWidth = image.getIntrinsicWidth();
    	int imageHeight = image.getIntrinsicHeight();

    	int x = viewWidth / 2 - imageWidth / 2;
    	int y = viewHeight / 2 - imageHeight / 2;

    	image.setBounds(x, y, x + imageWidth, y + imageHeight);
    	image.draw(canvas);

    	super.onDraw(canvas);
    }
}

[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<net.itisn.test.RobotView
    android:id="@+id/su"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />

</LinearLayout>

- END -

And

1일차

|
#부트 이미지 - Binary
helloos.img
0000:0000 EB 4E 90 48 45 4C 4C 4F-49 50 4C 00 02 01 01 00
0000:0010 02 E0 00 40 0B F0 09 00-12 00 02 00 00 00 00 00
0000:0020 40 0B 00 00 00 00 29 FF-FF FF FF 48 45 4C 4C 4F
0000:0030 2D 4F 53 20 20 20 46 4C-54 31 32 20 20 20 00 00
0000:0040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0050 B8 00 00 8E D0 BC 00 7C-8E D8 8E C0 BE 74 7C 8A
0000:0060 04 83 C6 01 3C 00 74 09-B4 0E BB 0F 00 CD 10 EB
0000:0070 EE F4 EB FD 0A 0A 68 65-6C 6C 6F 2C 20 88 6F 72
0000:0080 6C 64 0A 00 00 00 00 00-00 00 00 00 00 00 00 00

0000:0090 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00C0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:00F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:01A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:01B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:01C0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:01D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0000:01E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

0000:01F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA
0000:0200 F0 FF FF 00 00 00 00 00-00 00 00 00 00 00 00 00

0000:0210 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
~
0000:13F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

0000:1400 F0 FF FF 00 00 00 00 00-00 00 00 00 00 00 00 00

0000:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
~
0016:7FFF 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
0016:8000


#부트 이미지 - Assembly
helloos.nas
DB 0xeb, 0x4e, 0x90, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x02, 0xe0, 0x00, 0x40, 0x0b, 0xf0, 0x09, 0x00
DB 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x29, 0xff
DB 0xff, 0xff, 0xff, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x2d, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x46, 0x4c
DB 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c
DB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a
DB 0x04, 0x8., 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09
DB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb
DB 0xee, 0xf4, 0xeb, 0xfd, 0x0a, 0x0a, 0x68, 0x65
DB 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x88, 0x6f, 0x72
DB 0x6c, 0x64, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00

DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa

DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
~ (약 18만 행)
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

#부트 이미지 - 개선된 Assembly
helloos.nas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
DB 0xeb, 0x4e, 0x90, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x02, 0xe0, 0x00, 0x40, 0x0b, 0xf0, 0x09, 0x00
DB 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x29, 0xff
DB 0xff, 0xff, 0xff, 0x48, 0x45, 0x4c, 0x4c, 0x4f
DB 0x2d, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x46, 0x4c
DB 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00
RESB 16
DB 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c
DB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a
DB 0x04, 0x8., 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09
DB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb
DB 0xee, 0xf4, 0xeb, 0xfd, 0x0a, 0x0a, 0x68, 0x65
DB 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x88, 0x6f, 0x72
DB 0x6c, 0x64, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00
RESB 368
DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB 4600
DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB 1469432


#부트 이미지 - 더욱 개선된 Assembly
helloos.nas
;hello-os
;이하는 표준적인 FAT12 포맷 플로피디스크를 위한 서술
DB    0xeb, 0x4e, 0x90
DB    "HELLOIPL"    ;부트섹터의 이름을 자유롭게 써도 좋음
DW    512    	;1섹터의 크기
DB    1    	;클러스터의 크기 (1섹터로 해야 함)
DW    1    	;예약된 섹터의 수
DB    2    	;디스크의 FAT 테이블의 수
DW    224    	;루트 디렉토리 엔트리의 수 (보통은 224엔트리)
DW    2880    	;디스크의 총 섹터 수 (2880섹터로 해야 함)
DB    0xf0    	;미디어 타입 (0xf0으로 해야 함)
DW    9    	;하나의 FAT 테이블의 섹터 수 (9섹터로 해야 함)
DW    18    	;1트랙의 섹터 수 (18로 해야 함)
DW    2    	;헤드의 수 (2로 해야 함)
DD    0    	;파티션을 사용하지 않으므로 이곳은 반드시 0
DB    0, 0, 0x29    ;잘 모르겠지만 이 값을 넣어 두면 좋다고 함
DD    0xffffffff    ;아마 볼륨의 시리얼 번호
DB    "HELLO-OS"    ;디스크의 이름
DB    "FAT12   "    ;포맷의 이름 (8바이트)
RESB    18    	;어쨋든 18바이트 남겨둠

;프로그램 본체
DB    0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c
DB    0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a
DB    0x04, 0x83, 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09
DB    0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb
DB    0xee, 0xf4, 0xeb, 0xfd

;메시지 부분
DB    0x0a, 0x0a    ;줄바꿈 2개
DB    "hello, world"
DB    0x0a    	;줄바꿈
DB    0

RESB    0x1fe-$    	;0x001fe(510바이트, 0x001fe 앞)까지 0x00으로 채움
DB    0x55, 0xaa

;이하는 부트섹터 이외의 부분에 기술
DB    0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB    4600
DB    0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
RESB    1469432

- END -
And

[CustomView] 0. RobotView 생성

|
#CustomView 만들기

View(Context context, AttributeSet attrs) {}
1. 안드로이드 OS의 현재 상태 정보를 관리하는 클래스
2. 속성 배열

java.lang.Object
ㄴandroid.content.Context

java.lang.Object
ㄴandroid.content.Context
  ㄴandroid.content.ContextWrapper
    ㄴandroid.view.ContextThemeWrapper
      ㄴandroid.app.Activity

Context는 OS입장에서 실행 중인 application을 관리하기 위한 자료구조라고 보시면 될 것 같습니다. 
Class를 생성할 때 또는 정보를 얻고자 할때 context가 parameter로 많이 사용이 되는데 
이는 Class memory를 할당하거나 정보를 얻고자 하는 memory block 정보를 검색하기 위해서 
어떠한 application에서 요청했는지가 필요하기 때문입니다. 

예를들어서 TextView를 생성하는 경우 내부적으로는 heap memory를 할당하고 
해당 memory pointer를 Application context 정보를 기반으로 관리하는 것이고 
Application이 종료하게 되면 해당 application이 사용하는 heap memory를 free하는데 사용합니다. 

AttributeSet은 일반적으로 layout xml에서 android:text="@string/hello"와 같이 설정을 하는데 
LayoutInflater class를 사용해서 TextView를 실시간으로 생성하게 되는 경우 
TextView의 속성을 지정할 때 사용하는 class입니다. 

AttributeSet은 SDK를 보시면 아시겠지만 XML에 기반한 class입니다.


[개요]
1. MyView Class 추가
SuperClass : android.view.View 선택
2. MyView(Context context, AttributeSet attrs) 생성자 추가
View 클래스는 반드시 생성자를 필요로 한다.
x 클릭 > 2번째 생성자 선택
3. 우클릭 > Source > Override 선택 (Alt + Shift + S > v)
onDraw() 선택
위치 지정
4. 그림 정보를 담을 image 변수 생성
private Drawable image; (자동 임포트 : Ctrl + Shift + O)
생성자 안의 super() 아래에서 image에 그림의 아이디를 할당 (R.java에 모든 리소스들이 자동 생성됨)
5. onDraw() 안의 super() 위에서 image 위치 지정 및 그리기
6. main.xml에 태그 삽입
@+id/myview_id : 새로운 아이디 생성하여 사용
@id/myview_id : 기존 아이디 사용
직접 생선한 클래스이므로 디자이너에는 없다. 따라서 직접 xml 코드를 작성해 주어야 한다.
특정 동작을 하는 애니메이션 같은 경우에 커스텀 뷰를 만들어 사용한다.

[RobotView.java]
package net.itisn.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class RobotView extends View {

    private Drawable image;

    public RobotView(Context context, AttributeSet attrs) {
    	super(context, attrs);
    	// TODO Auto-generated constructor stub
    	image = this.getResources().getDrawable(R.drawable.su);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    	// TODO Auto-generated method stub
    	image.setBounds(0, 0, 128, 128);
    	image.draw(canvas);
    	//layout(0, 0, 128, 128);

    	super.onDraw(canvas);
    }
}

[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<net.itisn.test.MyView android:id="@+id/su"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<net.itisn.test.SunView
    android:id="@+id/icon"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    />

</LinearLayout>

And

C# 기본

|
기본 출력
using System;

class MainClass
{
    public static void Main()
    {
        Console.WriteLine("A simple C# program.");
    }
}

메인함수 인자 반복 출력
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        foreach (string arg in args)
            Console.WriteLine("Arg: {0}", arg);
    }
}

메인함수 리턴
using System;

class MainClass
{
    public static int Main()
    {
        Console.WriteLine("Hello, Universe!");
        return (0);
    }
}

메인함수 4가지 형태
using System;

class MainClass
{
    static void Main()
    {
    }

    static int Main()
    {
    }

    static void Main(string[] args)
    {
    }

    static int Main(string[] args)
    {
    }
}

인자 옵션 사용 여부 확인
class MainClass
{
    static void Main(string[] args)
    {
        if (args[0][0] == '-')
        {
            System.Console.WriteLine("-");
        }
    }
}

WriteLine 문자열 안에 변수 사용
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("{0} command line arguments were specified:", args.Length);
        foreach (string arg in args)
            Console.WriteLine(arg);
    }
}

네임스페이스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("A simple C# program.");
        System.Console.WriteLine("A simple C# program.");
    }
}

네임스페이스 사용, [STAThread]
기본적으로, VS .NET에 의해 만들어진 응용 프로그램의 Main()메소드에는 [STAThread] 어트리뷰트가 첨가되어 있다. 
이 어트리뷰트는 해당 응용 프로그램이 COM형식을 이용하는 경우에 (단지 이 경우에만 해당하는 것인데) 해당 응용 프로그램이 
단일 스레드 아파트(single threaded apartment, STA) 모델로 설정되어야 한다는 것을 런타임에게 알려주는 역할을 한다. 
해당 응용 프로그램에서 COM 형식을 이용하지 않는다면, [STAThread] 어트리뷰트는 무시되기 때문에 삭제해도 무방하다.
using System;

namespace HelloWorld
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            System.Console.WriteLine("Hello world from C#");
        }
    }
}

네임스페이스 안에 들어 있는 클래스 객체 생성
using System;

namespace Counter
{
    class MyClass
    {
    }
}

class MainClass
{
    public static void Main()
    {
        Counter.MyClass my = new Counter.MyClass();
    }
}

네임스페이스 별명 사용
using ThatConsoleClass = System.Console;

class MainClass
{
    public static void Main()
    {
        ThatConsoleClass.WriteLine("Hello");
    }
}

네임스페이스 안의 클래스 사용하여 출력
using System;

namespace Counter
{
    class MyClass
    {
        public MyClass()
        {
            Console.WriteLine("Counter1 namespace.");
        }
    }
}

namespace Counter2
{
    class MyClass
    {
        public MyClass()
        {
            Console.WriteLine("Counter2 namespace.");
        }
    }
}

class MainClass
{
    public static void Main()
    {
        Counter.MyClass m1 = new Counter.MyClass();

        Counter2.MyClass m2 = new Counter2.MyClass();
    }
}

네임스페이스를 나누어서 클래스 정의 가능
using System;

using Counter;

namespace Counter
{
    class MyClass
    {
    }
}

namespace Counter
{
    class MySecondClass
    {
    }
}

class MainClass
{
    public static void Main()
    {
        MyClass m = new MyClass();
        MySecondClass cu = new MySecondClass();
    }
}

네스티디 네임스페이스
using System;

namespace NS1
{
    class ClassA
    {
        public ClassA()
        {
            Console.WriteLine("constructing ClassA");
        }
    }
    namespace NS2
    {
        class ClassB
        {
            public ClassB()
            {
                Console.WriteLine("constructing ClassB");
            }
        }
    }
}

class MainClass
{
    public static void Main()
    {
        NS1.ClassA a = new NS1.ClassA();

        NS1.NS2.ClassB b = new NS1.NS2.ClassB();
    }
}

네임스페이스 별명, :: 사용
using System;

using Counter;
using AnotherCounter;

using Ctr = Counter;

namespace Counter
{
    class MyClass
    {
    }
}

namespace AnotherCounter
{
    class MyClass
    {
    }
}

class MainClass
{
    public static void Main()
    {
        Ctr::MyClass m = new Ctr::MyClass();
    }
}

네임스페이스.클래스 오브젝트 = new 네임스페이스.생성자();
namespace CompanyName
{
    public class Car
    {
        public string make;
    }
}

namespace DifferentCompany
{
    public class Car
    {
        public string make;
    }
}

class MainClass
{
    public static void Main()
    {
        System.Console.WriteLine("Creating a CompanyName.Car object");
        CompanyName.Car myCar = new CompanyName.Car();
        myCar.make = "Toyota";
        System.Console.WriteLine("myCar.make = " + myCar.make);

        System.Console.WriteLine("Creating a DifferentCompany.Car object");
        DifferentCompany.Car myOtherCar = new DifferentCompany.Car();
        myOtherCar.make = "Porsche";
        System.Console.WriteLine("myOtherCar.make = " + myOtherCar.make);
    }
}

네임스페이스 계층...
namespace CompanyName
{
    namespace UserInterface
    {
        public class MyClass
        {
            public void Test()
            {
                System.Console.WriteLine("UserInterface Test()");
            }
        }
    }
}

namespace CompanyName.DatabaseAccess
{
    public class MyClass
    {
        public void Test()
        {
            System.Console.WriteLine("DatabaseAccess Test()");
        }
    }
}

class MainClass
{
    public static void Main()
    {
        CompanyName.UserInterface.MyClass myUI = new CompanyName.UserInterface.MyClass();
        CompanyName.DatabaseAccess.MyClass myDB = new CompanyName.DatabaseAccess.MyClass();

        CompanyName.DatabaseAccess.MyClass myMT = new CompanyName.DatabaseAccess.MyClass();

        myUI.Test();
        myDB.Test();
        myMT.Test();
    }
}

-------pause 1.5.15-----

-------start 5장 문자열-----

문자열 선언
using System;

class MainClass
{
    static void Main(string[] args)
    {
        string MyString = "Hello World";
        string Path = @"c:\Program Files";
        string Path2 = "c:\\Program Files";

        string Name = "Joe";
    }
}

문자열 인자로 넘겨서 변환 -> 복사되어 원본은 변경 안됨
using System;

class MainClass
{
    static void Main(string[] args)
    {
        string strOriginal = "Original String";
        Console.WriteLine("Value of strOriginal before call: {0}", strOriginal);

        TryToAlterString(strOriginal);

        Console.WriteLine("Value of strOriginal after call: {0}", strOriginal);
    }

    static void TryToAlterString(string str)
    {
        str = "Modified string";
    }
}

문자열 대분자로 변환, 복사되어 변환, 원본은 그대로
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string s1 = "This is my string.";
        Console.WriteLine("s1 = {0}", s1);

        string upperString = s1.ToUpper();
        Console.WriteLine("upperString = {0}", upperString);

        Console.WriteLine("s1 = {0}", s1);

        string s2 = "My other string";
        s2 = "New string value";
    }
}

빈 문자열 생성
using System;
using System.IO;
using System.Text;

public class MainClass
{
    public static void Main(String[] args)
    {
        string address = String.Empty;
    }
}

문자열을 한 문자씩 출력
using System;

class MainClass
{
    public static void Main()
    {
        string myString = "To be or not to be";

        for (int count = 0; count < myString.Length; count++)
        {
            Console.WriteLine("myString(" + count + "] = " + myString[count]);
        }
    }
}

문자열 비교, 같으면 0, 앞이면 -1, 뒤면 1, 비교시 대소문자 구분, 일부 문자열만 비교
using System;

class MainClass
{
    public static void Main()
    {
        int result;
        result = String.Compare("bbc", "abc");
        Console.WriteLine("String.Compare(\"bbc\", \"abc\" = " + result);

        result = String.Compare("abc", "bbc");
        Console.WriteLine("String.Compare(\"abc\", \"bbc\" = " + result);

        result = String.Compare("bbc", "bbc");
        Console.WriteLine("String.Compare(\"bbc\", \"bbc\" = " + result);

        result = String.Compare("bbc", "BBC", true);
        Console.WriteLine("String.Compare(\"bbc\", \"BBC\", true = " + result);

        result = String.Compare("bbc", "BBC", false);
        Console.WriteLine("String.Compare(\"bbc\", \"BBC\", false = " + result);

        result = String.Compare("Hello World", 6, "Goodbye World", 8, 5);
        Console.WriteLine("String.Compare(\"Hello World\", 6, " + "\"Goodbye World\", 8, 5) = " + result);
    }
}

문자열 합치기
using System;

class MainClass
{
    public static void Main()
    {
        string myString4 = String.Concat("A, ", "B");
        Console.WriteLine("String.Concat(\"A, \", \"B\") = " + myString4);

        string myString5 = String.Concat("A, ", "B ", "and countrymen");
        Console.WriteLine("String.concat(\"A, \", \"B \", " + "\"and countrymen\") = " + myString5);
    }
}

문자열 합치기 +연산자
using System;

class MainClass
{
    public static void Main()
    {
        string myString6 = "To be, " + "or not to be";
        Console.WriteLine("\"To be, \" + \"or not to be\" = " + myString6);
    }
}

문자열 복사 String.Copy() 이용
using System;

class MainClass
{
    public static void Main()
    {
        string myString4 = "string4";
        Console.WriteLine("myString4 = " + myString4);

        Console.WriteLine("Copying myString4 to myString7 using Copy()");

        string myString7 = String.Copy(myString4);
        Console.WriteLine("myString7 = " + myString7);
    }
}

문자열 비교 String.Equals(str1, str2), str1.Equals(str2), str1 == str2
using System;

class MainClass
{
    public static void Main()
    {
        bool boolResult;
        string myString = "str";
        string myString2 = "str2";

        boolResult = String.Equals("bbc", "bbc");
        Console.WriteLine("String.Equals(\"bbc\", \"bbc\") is " + boolResult);

        boolResult = myString.Equals(myString2);
        Console.WriteLine("myString.Equals(myString2) is " + boolResult);

        boolResult = myString == myString2;
        Console.WriteLine("myString == myString2 is " + boolResult);
    }
}

문자열 형식 지정
using System;

class MainClass
{
    public static void Main()
    {
        float myFloat = 1234.56789f;
        string myString8 = String.Format("{0, 10:f3}", myFloat);
        Console.WriteLine("String.Format(\"{0, 10:f3}\", myFloat) = " + myString8);
    }
}

문자열 합치기. "." 대신 "", " " 등 사용 가능
using System;

class MainClass
{
    public static void Main()
    {
        string[] myStrings = { "To", "be", "or", "not", "to", "be" };
        string myString9 = String.Join(".", myStrings);
        Console.WriteLine("myString9 = " + myString9);
    }
}

문자열 나누기
using System;

class MainClass
{
    public static void Main()
    {
        string[] myStrings = { "To", "be", "or", "not", "to", "be" };
        string myString9 = String.Join(".", myStrings);
        myStrings = myString9.Split('.');
        foreach (string mySplitString in myStrings)
        {
            Console.WriteLine("mySplitString = " + mySplitString);
        }
    }
}

문자열에서 문자의 인덱스 추출
using System;

class MainClass
{
    public static void Main()
    {
        string[] myStrings = { "To", "be", "or", "not", "to", "be" };
        string myString = String.Join(".", myStrings);

        char[] myChars = { 'b', 'e' };
        int index = myString.IndexOfAny(myChars);
        Console.WriteLine("'b' and 'e' occur at index " + index + " of myString");
        index = myString.LastIndexOfAny(myChars);
        Console.WriteLine("'b' and 'e' last occur at index " + index + " of myString");
    }
}

문자열 추가, 삭제, 치환(대소문자 일치해야 함)
using System;

class MainClass
{
    public static void Main()
    {
        string[] myStrings = { "To", "be", "or", "not", "to", "be" };
        string myString = String.Join(".", myStrings);

        string myString10 = myString.Insert(6, "A, ");
        Console.WriteLine("myString.Insert(6, \"A, \") = " + myString10);

        string myString11 = myString10.Remove(14, 7);
        Console.WriteLine("myString10.Remove(14, 7) = " + myString11);

        string myString12 = myString11.Replace(',', '?');
        Console.WriteLine("myString11.Replace(',', '?') = " + myString12);

        string myString13 = myString12.Replace("to be", "Or not to be A");
        Console.WriteLine("myString12.Replace(\"to be\", \"Or not to be A\") = " + myString13);
    }
}

문자열 좌우에 공백, 또는 문자 채우기
using System;

class MainClass
{
    public static void Main()
    {
        string[] myStrings = { "To", "Be", "or", "not", "to", "be" };
        string myString = String.Join(".", myStrings);

        string myString14 = '(' + myString.PadLeft(20) + ')';
        Console.WriteLine("'(' + myString.PadLeft(20) + ')' = " + myString14);

        string myString15 = '(' + myString.PadLeft(20, '.') + ')';
        Console.WriteLine("'(' + myString.PadLeft(20, '.') = " + myString15);

        string myString16 = '(' + myString.PadRight(20) + ')';
        Console.WriteLine("'(' + myString.PadRight(20) + ')' = " + myString16);

        string myString17 = '(' + myString.PadRight(20, '|') + ')';
        Console.WriteLine("'(' + myString.PadRight(20, '|') + ')' = " + myString17);
    }
}

문자열 양 끝 잘라내기, 문자 배열을 인자로 가질 수 있음
using System;

class MainClass
{
    public static void Main()
    {
        string myString18 = '(' + "  Whitespace  ".Trim() + ')';
        Console.WriteLine("'(' + \"  Whitespace  \".Trim() + ')' = " + myString18);

        string myString19 = '(' + "  Whitespace  ".TrimStart() + ')';
        Console.WriteLine("'(' + \"  Whitespace  \".TrimStart() + ')' = " + myString19);

        string myString20 = '(' + "  Whitespace  ee".TrimEnd(new char[] {'e', ' '}) + ')';
        Console.WriteLine("'(' + \"  Whitespace  \".TrimEnd() + ')' = " + myString20);
    }
}




























--------------------------------------http://csharpcomputing.com/Tutorials/Lesson9.htm---------------------------------------

파일 입출력 기본
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if(File.Exists("test.txt"))
            {
                string content = File.ReadAllText("test.txt");
                Console.WriteLine("Current content of file:");
                Console.WriteLine(content);
            }
            Console.WriteLine("Please enter new content for the file:");
            string newContent = Console.ReadLine();
            File.WriteAllText("test.txt", newContent);
        }
    }
}

파일 입출력 스트림 이용
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("test.txt"))
            {
                string content = File.ReadAllText("test.txt");
                Console.WriteLine("Current content of file:");
                Console.WriteLine(content);
            }
            Console.WriteLine("Please enter new content for the file:");
            using (StreamWriter sw = new StreamWriter("test.txt"))
            {
                string newContent = Console.ReadLine();
                while (newContent != "exit")
                {
                    sw.Write(newContent + Environment.NewLine);
                    newContent = Console.ReadLine();
                }
            }
        }
    }
}

파일 삭제, ReadKey() 문자 입력( 콘솔 화면 멈춤용으로 사용)
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("test.txt"))
            {
                File.Delete("test.txt");
                if (File.Exists("test.txt") == false)
                {
                    Console.WriteLine("File deleted...");
                }
            }
            else
            {
                Console.WriteLine("File test.txt does not yet exist!");
            }
            Console.ReadKey();
        }
    }
}

디렉토리 삭제
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (Directory.Exists("testdir"))
            {
                Directory.Delete("testdir");
                if (Directory.Exists("testdir") == false)
                    Console.WriteLine("Directory deleted...");
            }
            else
                Console.WriteLine("Directory testdir does not yet exist!");
        }
    }
}

파일 이름 변경
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("test.txt"))
            {
                Console.WriteLine("Please enter a new name for this file:");
                string newFilename = Console.ReadLine();
                if (newFilename != String.Empty)
                {
                    File.Move("test.txt", newFilename);
                    if (File.Exists(newFilename))
                    {
                        Console.WriteLine("The file was renamed to " + newFilename);
                    }
                }
            }
        }
    }
}

디렉토리 변경
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a new name for this directory:");
            string newDirName = Console.ReadLine();
            if (newDirName != String.Empty)
            {
                Directory.Move("testdir", newDirName);
                if (Directory.Exists(newDirName))
                {
                    Console.WriteLine("The directory was renamed to " + newDirName);
                }
            }
        }
    }
}

디렉토리 생성
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a name for the new directory:");
            string newDirName = Console.ReadLine();
            if (newDirName != String.Empty)
            {
                Directory.CreateDirectory(newDirName);
                if (Directory.Exists(newDirName))
                {
                    Console.WriteLine("The directory was created!");
                }
            }
        }
    }
}

현재 파일 정보 얻기
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
            if (fi != null)
                Console.WriteLine(String.Format("Information about file: {0}, {1} bytes, last modified on {2} - Full path: {3}", fi.Name, fi.Length, fi.LastWriteTime, fi.FullName));
        }
    }
}

디렉토리의 파일 정보 얻기
using System;
using System.IO;

namespace FileHandlingArticleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
            if (di != null)
            {
                FileInfo[] subFiles = di.GetFiles();
                if (subFiles.Length > 0)
                {
                    Console.WriteLine("Files:");
                    foreach (FileInfo subFile in subFiles)
                    {
                        Console.WriteLine("\t" + subFile.Name + "\t(" + subFile.Length + " bytes)");
                    }
                }
            }
        }
    }
}

멤버 변수와 정적 멤버 변수
using System;

class Demo
{
    public static int k;
    public int i;
    public void show()
    {
        Console.WriteLine("k = {0} i = {1}", k, i);
    }
}

class Test
{
    public static void Main()
    {
        Demo a = new Demo();
        a.i = 1;

        Demo b = new Demo();
        b.i = 2;

        Demo.k = 4;

        a.show();
        b.show();
    }
}

ref 타입
using System;

public class Swap
{
    public void swap(ref int x, ref int y)
    {
        int temp = x;
        x = y;
        y = temp;
    }
}

public class Test
{
    static void Main()
    {
        int a = 2;
        int b = 4;

        Swap hi = new Swap();
        hi.swap(ref a, ref b);
        Console.WriteLine("a = {0}, b = {1}", a, b);
    }
}

상속
using System;

class Demo
{
    public class animal
    {
        int weight;
        string name;
        public void show()
        {
            Console.WriteLine("{0} has weight {1}", name, weight);
        }
        public void my_set(int k, string z)
        {
            weight = k;
            name = z;
        }
    }

    public class tiger : animal
    {
        public tiger()
        {
            my_set(100, "tiger");
            show();
        }
    }

    public class lion : animal
    {
        public lion()
        {
            my_set(200, "lion");
            show();
        }
    }

    public static void Main()
    {
        tiger Mike = new tiger();
        lion Bob = new lion();
    }
}

레퍼런스 - 안바뀌는 것
using System;

class Demo
{
    public class Test
    {
        public void change(int k)
        {
            k = k + 2;
        }
    }
    public static void Main()
    {
        int i = 3;
        Test hi = new Test();
        Console.WriteLine("Before {0}", i);
        hi.change(i);
        Console.WriteLine("After {0}", i);
    }
}

레퍼런스 - 리턴받는 것
using System;

class Demo
{
    public class Test
    {
        public int change(int k)
        {
            return k + 2;
        }
    }

    public static void Main()
    {
        int i = 3;
        Test hi = new Test();
        Console.WriteLine("Before {0}", i);
        Console.WriteLine("After {0}", hi.change(i));
    }
}

레퍼런스 - ref 사용한 것
using System;

class Demo
{
    public class Test
    {
        public void change(ref int k)
        {
            k = k + 2;
        }
    }

    public static void Main()
    {
        int i = 3;
        Test hi = new Test();
        Console.WriteLine("Before {0}", i);
        hi.change(ref i);
        Console.WriteLine("After {0}", i);
    }
}

윈도우 폼 생성
using System.Windows.Forms;

class test : Form
{
    public static void Main()
    {
        test Helloform = new test();
        Helloform.Text = "How do you do?";
        Application.Run(Helloform);
    }
}

윈도우 폼 텍스트박스 추가
using System.Windows.Forms;

class test : Form
{
    public static void Main()
    {
        test HelloForm = new test();
        System.Windows.Forms.TextBox text = new System.Windows.Forms.TextBox();

        text.Text = "This is a textbox";
        HelloForm.Controls.Add(text);
        Application.Run(HelloForm);
    }
}

윈도우 폼 체크박스 추가
using System.Windows.Forms;

class test : Form
{
    public static void Main()
    {
        test HelloForm = new test();
        HelloForm.BackColor = System.Drawing.Color.Yellow;

        System.Windows.Forms.CheckBox check = new System.Windows.Forms.CheckBox();
        check.Text = "checkbox";

        HelloForm.Controls.Add(check);
        Application.Run(HelloForm);
    }
}





































'C#' 카테고리의 다른 글

[GUI] Empty Form  (0) 2010.09.19
And
prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | next