Kjava Programming.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

J2ME Form Nesneleri Melih Sakarya. Form Nesnesi Form form= new Form("Giris"); display.setCurrent(form);
Java 2D Training. Basic Tools Java SDK 1.4x Wireless Toolkit 2.x NetBeans IDE + mobility pack Global Code editor Text Comparer Tools Graphics Editor Sprite.
Web Teknologi 3 (MKB721C) Minggu 10 Page 1 MINGGU 10 Web Teknologi 3 (MKB721C) Pokok Bahasan: –Programming a Custom User Interface Tujuan Instruksional.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
©College of Computer and Information Science, Northeastern UniversityApril 22, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 4.
Cosc 4755 Low-level GUI APIs. Low-Level API Composed of Canvas and Graphics classes – GameCanvas will be covered later on Canvas is an abstract class,
Developing an Application with J2ME Technology Scott Palmer, Nat Panchee, Judy Sullivan, Karen Thabet, Sten Westgard.
C++ Graphics Primitives April 15th. void clearscreen(int c) –clear the screen to background color c –If c = 1 screen black.
Developing J2ME Applications Mobile and Wireless Networks.
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Java Programs u 1 project file –with an extension of.mcp –contains information that CodeWarrior needs to run the program u >= 1 source files –have an extension.
Chapter 5 - Making Music: An On-Screen Piano
J2ME Java for Mobile Environments Based on J2ME In A Nutshell, by Kim Topley, O’Reilly & Associates Inc., 2002, and Tetris by Alexei Patinov.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
Histograms- HPP. What is homogeneous? Homogeneous point process treats all pixels the same. p'=f(p); // homogeneous point processing does not care about.
J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to introduce M3G; –to start talking about "M3G Chapter 2. An Animated Model" u leave the floor,
Java On The Web Session 15. Memory Upload JAVA Applets Colors Fonts Drawing Methods Posting your Applet.
2D Graphics: Rendering Details
PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
9/21/99www.cs.vt.edu/wwtut/1 User Interface Programming In Java Part 1 – Introduction Marc Abrams Virginia Tech CS Dept courses.cs.vt.edu/wwwtut/
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
User-defined parameters can be passed to an applet using the tags.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
© A+ Computer Science - Chicken yeller = new Chicken();
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
User Interface Summary Displayable ScreenCanvas FormAlertListTextbox Item DateFieldImageItemTextFieldStringItemGaugeChoiceGroup.
스레드 프로그래밍 Lecture #7.
Web Design–Part 2 Links, Graphics, Tables, and Color Explorers Guild May 25, 2000.
모바일 자바 프로그래밍 MIDP RMS Ps lab 오민경. MIDP RMS  RMS (Record Management System)  MIDP 에서 정의하는 영속성을 지닌 자체 데이터 저장 공간  Record Store 의 집합으로 구성된 아주 간단한 데이터베이스.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
1 CSC 551: Web Programming Spring 2004 Java Applets  Java vs. C++  instance vs. class variables, primitive vs. reference types, inheritance  graphical.
J2ME Programming. Java2 Micro edition Introduction 년 5 월 26 일 CLDC, MIDP 라이브러리 Reference :
CSE403: MIDlets and Ant1 MIDlets and Ant April 3, 2003 Shane Cantrell Zach Crisman.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
The Record Store ( ) Frank Ducrest. The Record Store 2 The Record Store provides persistence of data between MIDlet runs not quite a DBMS API.
Java Applets.
User Interface Programming In Java
UNIT II J2ME Best Practices and Patterns
Java N Amanquah.
Fundamental of Java Programming
Applets In Java Visit for more Learning Resources 1.
Java Applets.
Graphics Applets By Mr. Dave Clausen
Computer Programming Methodology File Input
Mobile Software Development Framework: Android
Outline The switch Statement The Conditional Operator The do Statement
J2ME Command Class.
J2ME User Interface I.
Color Values All colors in computer images are a combination of red, green and blue Each component is encoded as a number means the color is.
עקרונות תכנות מונחה עצמים
Java Applets.
Java Applets.
Shane Cantrell Zach Crisman
Java for Mobile Devices
12.4 p 471 a) double[] number = {1.05, 2.05, 3.05, 4.05, 5.05};
A+ Computer Science METHODS.
Presentation transcript:

Kjava Programming

Low Level UI 디바이스의 세밀한 제어 이식성 부족 Canvas Graphics 그래픽작업 수행 Low Level Event 처리 Graphics 텍스트,이미지,도형등의 표시

Canvas Abstract class Displayable Paint() method Low-level UI를 사용하려는 class 는 Canvas를 상속

Graphics J2SE의 Graphics와 유사 주요 그래픽함수 Void drawChar(char character, int x, int y, int anchor) Void drawImage(Image img, int x, int y, int anchor) Void drawLine(int x1, int y1, int x2, int y2) Void drawRect(int x, int y, int width, int height) Void drawString(String str, int x, int y, int anchor) Void setColor(int RGB) Void setGrayStyle(int value)

Color Low level API는 24bit(8,8,8) Color 지원 모든 장치에서 같은 색이 나온다는 보장 없음 Display.isColor() Color지원여부 검사 Display.numColor() 지원되는 색상수 검사

DeviceTest.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class DeviceTest extends MIDlet{ private Display display; private Form s1; private StringItem x,y,iscolor,numcolor; private DeviceTestCanvas cv; public DeviceTest(){ s1=new Form("Screen1"); x=new StringItem("MaxX:",""); y=new StringItem("MaxY:",""); iscolor=new StringItem("Color:",""); numcolor=new StringItem("NumColor:",""); cv=new DeviceTestCanvas(); s1.append(x); s1.append(y); s1.append(iscolor); s1.append(numcolor); display=Display.getDisplay(this); }

DeviceTest.java public void startApp() throws MIDletStateChangeException { x.setText(cv.getWidth()+""); y.setText(cv.getHeight()+""); if(display.isColor()) iscolor.setText("True"); else iscolor.setText("False"); numcolor.setText(display.numColors()+""); display.setCurrent(s1); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} class DeviceTestCanvas extends Canvas{ public DeviceTestCanvas(){ public void paint(Graphics g){

DeviceTest.java

ColorTest import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ColorTest extends MIDlet{ private Display display; public ColorTest(){ display=Display.getDisplay(this); } public void startApp() throws MIDletStateChangeException { display.setCurrent(new ColorTestCanvas(display.isColor())); public void pauseApp() {} public void destroyApp(boolean unconditional) {} class ColorTestCanvas extends Canvas{ boolean isColor; public ColorTestCanvas(boolean _isColor){ isColor=_isColor; public void paint(Graphics g){ int width=this.getWidth(); int height=this.getHeight(); int nrow=8; int ncol=8; int gap=3; int deltaX=(width-(ncol+1)*gap)/ncol; int deltaY=(height-(nrow+1)*gap)/nrow;

ColorTest if(true){ g.setColor(0xFFFFFF); g.fillRect(0,0,width,height); int deltaColor=0xFF/4; int red=0; int green=0; int blue=0; for(int i=0;i<nrow;i++){ for(int j=0;j<ncol;j++){ red+=deltaColor; if(red>0xFF){ red-=0xFF; green+=deltaColor; if(green>0xFF){ green-=0xFF; blue+=deltaColor; } g.setColor(red,green,blue); int x=gap*(j+1)+j*deltaX; int y=gap*(i+1)+i*deltaY; g.fillRect(x,y,deltaX,deltaY);

ColorTest else{ g.setGrayScale(0xFF); g.fillRect(0,0,width,height); int deltaGrayScale=0xFF/(nrow*ncol); for(int i=0;i<nrow;i++){ for(int j=0;j<ncol;j++){ int n=(i+1)*ncol+j; g.setGrayScale(deltaGrayScale*n); int x=gap*(j+1)+j*deltaX; int y=gap*(i+1)+i*deltaY; g.fillRect(x,y,deltaX,deltaY); }

ColorTest

Stroke Sytle 선을 그리는 두가지 방법이 존재 Void setStrokeStyle(int style) 실선(solid) 점선(Dotted) Void setStrokeStyle(int style)

Plot2DTest import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.lang.Math; public class Plot2DTest extends MIDlet{ private Display display; int v1[]={10,30,40,70,50}; int v2[]={30,90,50,60,65}; int maxX; int maxY; public Plot2DTest(){ display=Display.getDisplay(this); maxX=Math.max(v1.length,v2.length)-1; maxY=0; for(int i=0;i<v1.length;i++){ maxY=Math.max(maxY,v1[i]); } for(int i=0;i<v2.length;i++){ maxY=Math.max(maxY,v2[i]); maxY+=10; public void startApp() throws MIDletStateChangeException { display.setCurrent(new Plot2DTestCanvas(v1,v2,maxX,maxY)); public void pauseApp() {} public void destroyApp(boolean unconditional) {}

Plot2DTest class Plot2DTestCanvas extends Canvas{ int v1[]; int v2[]; int maxX,maxY; public Plot2DTestCanvas(int[] v1, int[] v2, int maxX, int maxY){ this.v1=v1; this.v2=v2; this.maxX=maxX; this.maxY=maxY; } public void paint(Graphics g){ int width=this.getWidth(); int height=this.getHeight(); g.setColor(0xFFFFFF); g.fillRect(0,0,width,height); g.setColor(0x000000); g.drawLine(0,height,0,0); g.drawLine(0,height-1,width,height-1); int deltaX=width/maxX; int deltaY=height/maxY; g.setColor(0xFF0000); for(int i=0;i<v1.length-1;i++){ g.drawLine(deltaX*i,height-deltaY*v1[i],deltaX*(i+1),height-deltaY*v1[i+1]); g.setStrokeStyle(Graphics.DOTTED); g.setColor(0x0000FF); for(int i=0;i<v2.length-1;i++){ g.drawLine(deltaX*i,height-deltaY*v2[i],deltaX*(i+1),height-deltaY*v2[i+1]);

Plat2DTest

Low Level Event 키패드의 이벤트를 지원 주요 Handler Void keyPressed(int keyCode) Void keyRepeated(int keyCode) Void keyReleased(int keyCode) Void pointerPressed() Void pointerDragged() Void pointerReleased()

KeyCode KEY_NUM0 ~ KEY_NUM9 KEY_STAR KEY_POUND

KeyEventTest import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class KeyEventTest extends MIDlet{ private Display display; public KeyEventTest(){ display=Display.getDisplay(this); } public void startApp() throws MIDletStateChangeException { display.setCurrent(new KeyEventTestCanvas()); public void pauseApp() {} public void destroyApp(boolean unconditional) {}

KeyEventTest class KeyEventTestCanvas extends Canvas{ String str=""; public KeyEventTestCanvas(){ } public void paint(Graphics g){ int width=this.getWidth(); int height=this.getHeight(); g.setColor(0xFFFFFF); g.fillRect(0,0,width,height); g.setColor(0x000000); g.drawString("Press a key",5,5,g.TOP|g.LEFT); g.drawString(str,5,25,g.TOP|g.LEFT); public void keyPressed(int keycode){ if(keycode==Canvas.KEY_NUM1) str="일 is pressed"; else if(keycode==Canvas.KEY_NUM2) str="이 is pressed"; repaint();

KeyEventTest