Java Programming Basic
since 6 June, 1999 last modified 6 June, 1999, working
Java Compile ¹æ¹ý (JDK1.1»ç¿ë½Ã)
- java compiler (javac)¸¦ ÀÌ¿ëÇÏ¿© class_name.class fileÀ» »ý¼ºÇÑ´Ù.
ex) javac hellow.java- ½ÇÇà °¡´ÉÇÑ file ÀÎ *.class file Àº <APPLET> tag¸¦ ÀÌ¿ëÇÏ¿© HTML¿¡ ¿¬°áÇÑ´Ù.
- ÀÛ¼ºÇÑ HTML file Àº appletviwer utility ¸¦ ÀÌ¿ëÇÏ¿© ½ÇÇàÇÑ´Ù.
ex) appletviewer hellow.htm- class °¡ ¿©·¯°³ÀÏ °æ¿ì °¢ class º°·Î °¢±â ´Ù¸¥ file ·Î compile ÇÑ´Ù.
Java Program(Applet)ÀÇ ±¸Á¶
import java.applet.Applet; /* »ç¿ëÇÒ Package¸¦ Import */ import java.awt.*; import java.awt.event.*; /* class ¸¦ »ó¼Ó¹Þ°í Interface ¼³Ä¡ */ public class button extends Applet implements ActionListener { TextField text1; /* member variable type Á¤ÀÇ */ Button button1; public void init() { text1 = new TextField(20); /* member variable instanciation */ add(text1); /* layout manager ¿¡ Ãß°¡ */ button1 = new Button("Do"); add(button1); button1.addActionListener(this); /* event listener Ãß°¡ */ } public void actionPerformed(ActionEvent e) /* event±¸Çö */ { if (e.getSource()== button1 ) { text1.setText("Do"); } } };
- Java Package Import :
ÇÁ·Î±×·¥ ³»¿¡¼ »ç¿ëÇÒ Class¸¦ °ü·Ã Class ÁýÇÕÀÎ Package ÇüÅ·ΠImport ÇÑ´Ù.- Class »ó¼Ó°ú Interface »ç¿ë :
extends super_class_name °ú implements interface_name À» ÀÌ¿ëÇÏ¿© super class ¿Í method ¸¸À» »ó¼ÓÇÏ°í member º¯¼ö¸¦ °¡Áö°í ÀÖÁö ¾ÊÀº Interface¸¦ Á¤ÀÇÇÑ´Ù. Interface ´Â ÀÏÁ¾ÀÇ super class ÀÌÁö¸¸ multipul inheritance¸¦ ¹æÁöÇÏ°íÀÚ method ¸¸À» »ó¼Ó½ÃÅ°´Â Ưº°ÇÑ class ÀÌ´Ù. Á¾·ù¿¡´Â buttonÀÇ Evnet¸¦ ó¸®ÇÏ´Â ActionListener¿Í MouseÀÇ Event¸¦ ó¸®ÇÏ´Â MouseListener°¡ ÀÖ´Ù.- Member variableÀÇ Á¤ÀÇ:
Member variable ÀÇ À̸§°ú TypeÀ» Á¤ÀÇÇÑ´Ù.- Member variable ÀÇ instanciation (Init() method):
- new constructor ¿Í override & overload :
- Layout manager :
- Paint() ¿Í Repaint() Method :
- Array Á¤ÀÇ :
ex) int integers[] = new int[10] /* 10 °³ÀÇ Integer array Á¤ÀÇ */
integer[1] = new int; integers[1]=15;
Knowledge and Engineering Databases © copyright Namchul Do, 1999