본문 바로가기
코스웨어/10년 스마트폰BSP

[BSP]업무일지-손대원-20100826

by 알 수 없는 사용자 2010. 8. 26.
728x90
반응형

오전수업

JAVA

스윙
AWT(추상윈도 툴킷)의 확장버젼으로 JAVA2에 새롭게 추가된 GUI 처리 패키지이다.
스윙은 운영체제가 갖고있는 GUI를 사용하지 않고 JVM이 적접 Swing 패킺를 사용하여 구현하기 때문에 운영 체제가 서로 달라도 동일한 화면을 출력을 한다.

/*JFrame을 이용한 첫번째 GUI 어플리케이션*/

package
 exam01;

import javax.swing.JFrame;

class JFrameEx extends JFrame
{
  JFrameEx()
  {
    super("스윙 연습");
    setSize(500,200);
    setLocation(100,100);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
}
public class JFrameTest 
{
  public static void main(String[] args) 
  {
    new JFrameEx();

  }

}


위의 코드를 실행을 하면 아래와 같은 결과의 그림이 나온다




스레드의 구현과 실행

스레드를 구현하는 방법은 2가지가있다.

첫번째는 Thread클래스를 상속받는(확장 extends)방법
두번째는 Runnable 인터페이스를 상속받는 (구현,implenments)방법

/*Thread 클래스의 확장 클래스로 스레드 구현하기 */
package
 exam01;

class ThreadEx extends Thread
{
  String name;
  public ThreadEx(String name)
  {
    super(name);
    this.name = name;
  }
  @Override

  public void run()
  {
    int i = 0;
    while(true)
    {
      System.out.println("스레드명:" + name + "숫자:" + + i++);
      if(i==10)
      {
        break;
      }
      
try
      {
        sleep(30);
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
    }
  }
}

public class ThreadTest 
{
  public static void main(String[] args) 
  {
 //스레드 객체를 생성을한다.

    ThreadEx t1 = new ThreadEx("Thread01");
    ThreadEx t2 = new ThreadEx("Thread02");
    ThreadEx t3 = 
new ThreadEx("Thread03");
    //start()메소드를 호출하여 run()메소드를 실행시킨다.
    t1.start();
    t2.start();
    t3.start();
  }

}


위의 코드를 실행을 하게 되면 아래와 같은 결과의 값이 나오는 것을 확인을 할 수가 있다.

스레드명:Thread01숫자:0
스레드명:Thread03숫자:0
스레드명:Thread02숫자:0

스레드명:Thread01숫자:1
스레드명:Thread03숫자:1
스레드명:Thread02숫자:1

스레드명:Thread01숫자:2
스레드명:Thread03숫자:2
스레드명:Thread02숫자:2

스레드명:Thread01숫자:3
스레드명:Thread03숫자:3
스레드명:Thread02숫자:3

스레드명:Thread01숫자:4
스레드명:Thread03숫자:4
스레드명:Thread02숫자:4

스레드명:Thread01숫자:5
스레드명:Thread03숫자:5
스레드명:Thread02숫자:5

스레드명:Thread01숫자:6
스레드명:Thread03숫자:6
스레드명:Thread02숫자:6

스레드명:Thread01숫자:7
스레드명:Thread02숫자:7
스레드명:Thread03숫자:7

스레드명:Thread01숫자:8
스레드명:Thread02숫자:8
스레드명:Thread03숫자:8

스레드명:Thread01숫자:9
스레드명:Thread03숫자:9
스레드명:Thread02숫자:9



Runnable 인터페이스를 사용하는 방법

클랙스의 고유기능을 살리면서 스레드를 사용하고자 할 대는  Runnable인터페이스를 구현해야한다.

/* Runnable 인터페이스를 구현 클래스로 스레드 구현하기 */

package exam02;

class RunableEx implements Runnable
{
  @Override
  public void run()
  {
    int i = 0;
    while(true)
    {
      System.out.println("스레드명"+Thread.currentThread().getName()+"숫자:"+ +i++);
      if(i==50)
      {
        break;
      }
      try
      {
        Thread.sleep(10);  
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
    }
  }
  
}
public class ThreadTest 
{
  public static void main(String[] args) 
  {
    RunableEx r1 = new RunableEx();
    RunableEx r2 = new RunableEx();
    RunableEx r3 = new RunableEx();
    
    Thread t1 = new Thread(r1,"Thread01");
    Thread t2 = new Thread(r2,"Thread02");
    Thread t3 = new Thread(r3,"Thread03");
    
    t1.start();
    t2.start();
    t3.start();
  }

}

실행을 하게 되면 아래와 같은 결과물을 볼수가있다

스레드명Thread01숫자:0
스레드명Thread02숫자:0
스레드명Thread03숫자:0
스레드명Thread03숫자:1
스레드명Thread01숫자:1
스레드명Thread02숫자:1
스레드명Thread02숫자:2
스레드명Thread03숫자:2
스레드명Thread01숫자:2
스레드명Thread01숫자:3
스레드명Thread03숫자:3
스레드명Thread02숫자:3
스레드명Thread03숫자:4
스레드명Thread01숫자:4
스레드명Thread02숫자:4
스레드명Thread01숫자:5
스레드명Thread02숫자:5
스레드명Thread03숫자:5
스레드명Thread01숫자:6
스레드명Thread03숫자:6
스레드명Thread02숫자:6
스레드명Thread03숫자:7
스레드명Thread01숫자:7
스레드명Thread02숫자:7
스레드명Thread01숫자:8
스레드명Thread02숫자:8
스레드명Thread03숫자:8
스레드명Thread01숫자:9
스레드명Thread02숫자:9
스레드명Thread03숫자:9
스레드명Thread02숫자:10
스레드명Thread03숫자:10
스레드명Thread01숫자:10
스레드명Thread03숫자:11
스레드명Thread02숫자:11
스레드명Thread01숫자:11
스레드명Thread03숫자:12
스레드명Thread01숫자:12
스레드명Thread02숫자:12
스레드명Thread02숫자:13
스레드명Thread01숫자:13
스레드명Thread03숫자:13
스레드명Thread03숫자:14
스레드명Thread02숫자:14
스레드명Thread01숫자:14
스레드명Thread03숫자:15
스레드명Thread01숫자:15
스레드명Thread02숫자:15
스레드명Thread02숫자:16
스레드명Thread01숫자:16
스레드명Thread03숫자:16
스레드명Thread01숫자:17
스레드명Thread03숫자:17
스레드명Thread02숫자:17
스레드명Thread02숫자:18
스레드명Thread03숫자:18
스레드명Thread01숫자:18
스레드명Thread01숫자:19
스레드명Thread02숫자:19
스레드명Thread03숫자:19
스레드명Thread01숫자:20
스레드명Thread02숫자:20
스레드명Thread03숫자:20
스레드명Thread03숫자:21
스레드명Thread02숫자:21
스레드명Thread01숫자:21
스레드명Thread02숫자:22
스레드명Thread01숫자:22
스레드명Thread03숫자:22
스레드명Thread01숫자:23
스레드명Thread03숫자:23
스레드명Thread02숫자:23
스레드명Thread02숫자:24
스레드명Thread03숫자:24
스레드명Thread01숫자:24
스레드명Thread01숫자:25
스레드명Thread03숫자:25
스레드명Thread02숫자:25
스레드명Thread03숫자:26
스레드명Thread01숫자:26
스레드명Thread02숫자:26
스레드명Thread01숫자:27
스레드명Thread02숫자:27
스레드명Thread03숫자:27
스레드명Thread02숫자:28
스레드명Thread03숫자:28
스레드명Thread01숫자:28
스레드명Thread02숫자:29
스레드명Thread01숫자:29
스레드명Thread03숫자:29
스레드명Thread01숫자:30
스레드명Thread02숫자:30
스레드명Thread03숫자:30
스레드명Thread03숫자:31
스레드명Thread01숫자:31
스레드명Thread02숫자:31
스레드명Thread03숫자:32
스레드명Thread01숫자:32
스레드명Thread02숫자:32
스레드명Thread01숫자:33
스레드명Thread02숫자:33
스레드명Thread03숫자:33
스레드명Thread02숫자:34
스레드명Thread03숫자:34
스레드명Thread01숫자:34
스레드명Thread02숫자:35
스레드명Thread01숫자:35
스레드명Thread03숫자:35
스레드명Thread03숫자:36
스레드명Thread01숫자:36
스레드명Thread02숫자:36
스레드명Thread01숫자:37
스레드명Thread02숫자:37
스레드명Thread03숫자:37
스레드명Thread01숫자:38
스레드명Thread03숫자:38
스레드명Thread02숫자:38
스레드명Thread03숫자:39
스레드명Thread02숫자:39
스레드명Thread01숫자:39
스레드명Thread01숫자:40
스레드명Thread03숫자:40
스레드명Thread02숫자:40
스레드명Thread01숫자:41
스레드명Thread03숫자:41
스레드명Thread02숫자:41
스레드명Thread03숫자:42
스레드명Thread01숫자:42
스레드명Thread02숫자:42
스레드명Thread01숫자:43
스레드명Thread03숫자:43
스레드명Thread02숫자:43
스레드명Thread01숫자:44
스레드명Thread03숫자:44
스레드명Thread02숫자:44
스레드명Thread03숫자:45
스레드명Thread01숫자:45
스레드명Thread02숫자:45
스레드명Thread03숫자:46
스레드명Thread02숫자:46
스레드명Thread01숫자:46
스레드명Thread01숫자:47
스레드명Thread02숫자:47
스레드명Thread03숫자:47
스레드명Thread02숫자:48
스레드명Thread03숫자:48
스레드명Thread01숫자:48
스레드명Thread02숫자:49
스레드명Thread03숫자:49
스레드명Thread01숫자:49

오후수업

안드로이드

/* TabLayoutTest.java */

package
 test.test;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class TabLayoutTest extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Resources res = getResources();    //리소스 가져오기 
         
        TabHost tabHost = getTabHost();    //탭호스트
        TabHost.TabSpec spec;        //탭의 속성변경
          
        
        Intent intent = new Intent().setClass(this, SubActvity1.class);
        spec = tabHost.newTabSpec("Tab1");
        spec.setIndicator("Tab1",res.getDrawable(android.R.drawable.ic_menu_agenda));
        spec.setContent(intent);
        tabHost.addTab(spec);
        //초기화된 스펙을 탭에 붙이기
        
       
        //두번째 탭

        intent = new Intent().setClass(this, SubActvity2.class);
        spec = tabHost.newTabSpec("Tab2")
        .setIndicator("Tab2",res.getDrawable(android.R.drawable.ic_menu_edit))
        .setContent(intent);
        tabHost.addTab(spec);
        
        //세번째 탭
        
        intent = new Intent().setClass(this, SubActvity3.
class);
        spec = tabHost.newTabSpec("Tab3")
        .setIndicator("Tab3",res.getDrawable(android.R.drawable.ic_menu_help))
        .setContent(intent);
        tabHost.addTab(spec);
    }
}



/* main.xml */

<
?xml version="1.0" encoding="utf-8"?>
<TabHost
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
>
  <LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  >
    <TabWidget
      android:id="@android:id/tabs"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" />
    <FrameLayout
      android:id="@android:id/tabcontent"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
    ></FrameLayout>

  </LinearLayout>
</TabHost>


위의 코드를 실행을 하면 아래와 같은 결과를 확인할수있다.


3개의 버튼이 생성이 되고 버튼을 클릭을 할수있게 되었다

아래의 그림은 첫번째 그림을 클릭했을 때의 모습이다.

아직 내부에 실행을 시키는것을 집어넣지 않는 상태이다
외부 틀만 잡아놓은 상태인것이다.


728x90