Download presentation
Presentation is loading. Please wait.
Published byPercival Hicks Modified over 9 years ago
1
Chapter 2 Creating a Java Application and Applet
2
The Start of a Java App. Public class className { public static void main(String[] args) { }
3
Output a String Syntax: system.out.println(“texts”); Examples: system.out.println(“Welcome!”);
4
Include a Java Package Syntax: import java.XXX.XXX Examples: import java.io.* import java.applet.*
5
The Start of a Java Applet import java.awt.*; import java.applet.*; public class className extends Applet { public void paint(Graphics g) { }
6
Draw a String Syntax: g.drawString(“texts”, x-pos, y-pos); Examples: Public void paint(Graphics g) { g.drawString(“Welcome”, 400, 200); }
7
Draw a Picture Syntax: Image imageObj = getImage(getDocumentBase, “image_file_name”); g.drawImage(imageObj, x-pos, y-pos, this); Examples: public void paint(Graphics g) { Image smile = getImage(getDocumentBase, “smile.gif”); g.drawImage(smile, 400, 200, this); }
8
Set Background Color Syntax: setBackground(Color.color); Example: public void paint(Graphics g) { setBackground(Color.pink); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.