달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

1. Thread 클래스 사용
 public class ThreadTest extends Activity {
    int mMainValue = 0;
    int mBackValue = 0;
   TextView mMainText;
   TextView mBackText;

   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.thread_threadtest);

      mMainText = (TextView)findViewById(R.id.mainvalue);
      mBackText = (TextView)findViewById(R.id.backvalue);
      Button btn = (Button)findViewById(R.id.increase);
      btn.setOnClickListener(new Button.OnClickListener() {
           public void onClick(View v) {
               mMainValue++;
               mMainText.setText("MainValue : " + mMainValue);
              mBackText.setText("BackValue : " + mBackValue);
          }
     });
  
     BackThread thread = new BackThread();
     thread.setDaemon(true);
     thread.start();
 }
 
 class BackThread extends Thread {
     public void run() {
        while (true) {
              mBackValue++;
              //mBackText.setText("BackValue : " + mBackValue);
              try {
                 Thread.sleep(1000);
              } catch (InterruptedException e) { }
        }
     } 

  } // end of main
 } // end of class

2. Runnable 인터페이스 사용
 public class ThreadTest extends Activity {
      int mMainValue = 0;
      int mBackValue = 0;
      TextView mMainText;
      TextView mBackText;

      public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.thread_threadtest);

           mMainText = (TextView)findViewById(R.id.mainvalue);
           mBackText = (TextView)findViewById(R.id.backvalue);
           Button btn = (Button)findViewById(R.id.increase);
           btn.setOnClickListener(new Button.OnClickListener() {
                 public void onClick(View v) {
                      mMainValue++;
                      mMainText.setText("MainValue : " + mMainValue);
                      mBackText.setText("BackValue : " + mBackValue);
                 }
           });
  
           BackRunnable runnable = new BackRunnable();
           Thread thread = new Thread(runnable);
            thread.setDaemon(true);
            thread.start();
       }
 
      class BackRunnable implements Runnable {
            public void run() {
                  while (true) {
                          mBackValue++;
                          try {
                               Thread.sleep(1000);
                          } catch (InterruptedException e) { }
                  }
            }
       }
 }


Posted by kingjung
|

'Lecture Notes > Java Programming' 카테고리의 다른 글

Java Input & Output  (0) 2011.09.23
Java Applet & Application 상호 변경하기  (0) 2011.09.23
Java Applet Programming  (0) 2011.09.23
Java SWING Application 만들기  (0) 2011.09.23
Java AWT Application 만들기  (0) 2011.09.23
Posted by kingjung
|

'Lecture Notes > Java Programming' 카테고리의 다른 글

Java Executable File 만들기  (0) 2011.09.23
Java Applet Programming  (0) 2011.09.23
Java AWT Application 만들기  (0) 2011.09.23
Java Framework Programming  (0) 2011.09.23
Java AWT & SWING  (0) 2011.09.23
Posted by kingjung
|

'Lecture Notes > Java Programming' 카테고리의 다른 글

Java SWING Application 만들기  (0) 2011.09.23
Java AWT Application 만들기  (0) 2011.09.23
Java AWT & SWING  (0) 2011.09.23
자바 애플릿 & 어플리케이션  (0) 2011.09.23
Java Important Issues  (0) 2011.09.23
Posted by kingjung
|

'Lecture Notes > Java Programming' 카테고리의 다른 글

Java Framework Programming  (0) 2011.09.23
Java AWT & SWING  (0) 2011.09.23
Java Important Issues  (0) 2011.09.23
Java Event Componet  (0) 2011.09.23
Java Object Oriented Programming  (0) 2011.09.23
Posted by kingjung
|

'Lecture Notes > Java Programming' 카테고리의 다른 글

Java AWT & SWING  (0) 2011.09.23
자바 애플릿 & 어플리케이션  (0) 2011.09.23
Java Event Componet  (0) 2011.09.23
Java Object Oriented Programming  (0) 2011.09.23
Software Life Cycle  (0) 2011.09.23
Posted by kingjung
|

1. android source code (JavaStyle.java)
package com.example.oldstyle;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Date;

public class JavaStyle extends Activity implements View.OnClickListener {
 Button btn;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        btn = new Button(this);
        btn.setOnClickListener(this);
        setContentView(btn);
        //setContentView(R.layout.main);
    }
   
    public void onClick(View view) {
     updateTime();
    }
   
    private void updateTime() {
     btn.setText(new Date().toString());
    }
}

2. AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.oldstyle"
      android:versionCode="1"
      android:versionName="1.0">
    <application>
        <activity android:name=".JavaStyle">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="2" />

</manifest>

'Lecture Notes > Android Basics' 카테고리의 다른 글

안드로이드 프로그램 시작  (0) 2010.07.20
안드로이드 설치 및 개발 환경 구축  (0) 2010.07.20
Default Android Program (Basic)  (0) 2010.06.04
WIPI Basic Program  (0) 2010.06.03
J2ME Basic Program  (0) 2010.06.03
Posted by kingjung
|


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet {
   private Display display;
 
   public HelloWorld() {
      display = Display.getDisplay(this);
   }

   /* startApp() : call when MIDlet executes */

   public void startApp() {
      TextBox t = new TextBox("Hello, World!", "Welcome To J2ME MIDP", 256, 0);
      display.setCurrent(t);
   }

   /* pauseApp() :  call when MIDlet suspends */

   public void pauseApp() {
   }

   /* destroyApp() : call when MIDlet stops */

   public void destroyApp(boolean unconditional) {
   }

}

'Lecture Notes > Android Basics' 카테고리의 다른 글

Javastyle Android Program (Basic)  (0) 2010.06.04
Default Android Program (Basic)  (0) 2010.06.04
WIPI Basic Program  (0) 2010.06.03
Basic Framework : Java SWING Program  (0) 2010.06.03
Basic Framework : JAVA AWT Program  (0) 2010.06.03
Posted by kingjung
|

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SWINGCaseFive extends JFrame implements ActionListener  {
             public static final int WIDTH = 300;
             public static final int HEIGHT = 200;

 public SWINGCaseFive() {
    setTitle("Swing Case 5");
    setSize(WIDTH, HEIGHT);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JButton endButton = new JButton("Click to End the Program");
    endButton.addActionListener(this);
    getContentPane().add(endButton);
    setVisible(true);
 }

 public static void main(String[] args) {
    new SWINGCaseFive();
 }

 public void actionPerformed(ActionEvent e) {
    System.exit(0);
 }

}

'Lecture Notes > Android Basics' 카테고리의 다른 글

Javastyle Android Program (Basic)  (0) 2010.06.04
Default Android Program (Basic)  (0) 2010.06.04
WIPI Basic Program  (0) 2010.06.03
J2ME Basic Program  (0) 2010.06.03
Basic Framework : JAVA AWT Program  (0) 2010.06.03
Posted by kingjung
|

import java.awt.*;
import java.awt.event.*;


public class AWTCaseFive extends Frame implements ActionListener  {
            public static final int WIDTH = 300;
            public static final int HEIGHT = 200;

public AWTCaseFive() {
    setTitle("AWT Case 5");
    setSize(WIDTH, HEIGHT);

    Button endButton = new Button("Click to End the Program");
    endButton.addActionListener(this);

    add(endButton);

    setVisible(true);
 }

 public static void main(String[] args) {
    new AWTCaseFive();
 }

 public void actionPerformed(ActionEvent e) {
    System.exit(0);
 }

}

'Lecture Notes > Android Basics' 카테고리의 다른 글

Javastyle Android Program (Basic)  (0) 2010.06.04
Default Android Program (Basic)  (0) 2010.06.04
WIPI Basic Program  (0) 2010.06.03
J2ME Basic Program  (0) 2010.06.03
Basic Framework : Java SWING Program  (0) 2010.06.03
Posted by kingjung
|