java programming
Applet programming Application programming
* run on the web browser run on the console window
(web application) (standalone application)
* there is no p s v m. there is p s v m.
* init() method for
initialization. Constructor for initialization
* there is securities there is not
file / folder / system / database / virus - SecurityException
* there is life cycle. there is not.
life cycle - path for execution or way to execute the Applet.
init() - for initialization.
start() - ready for running
repaint() - clear the Applet screen
update() - update the applet screen.
paint() - drawing on the applet screen.
stop() - to suspend the execution of applet
destroy() - final cleanup like , distructor in C++.
Q- suppose we r using only paint method then
where is lige cycle.
ans - all methods r concrete methods in applet
class, if user override any method then
user method to be called else Applet class called.
import java.applet.*;
import java.awt.*;
public class Hello extends Applet
{
public void paint(Graphics g)
{
g.drawString("Welcome to Java",100,100);
}
}
//
javac Hello.java
appletviewer Hello.java
notepad ----
save with abc.html
ie - abc.html view
Color class -
Color.red/blue/orange/white/pink/cyan /gray - 15.
Constructor -
Color(int r,int g,int b) 0 - 255
Color c = new Color(220,212,255);
setBackground(c);
or
setBackground(new Color(220,212,255));
Font class -
Font(String fname,int fstyle,int fsize)
fstyle - Font.PLAIN/BOLD/ITALIC / BOLD + ITALIC
0 1 2 1 + 2 = 3
Font f = new Font("Courier New",1,45);
g.setFont(f);
or
g.setFont(new Font("Courier New",1,45));
Graphics class methods -
void setFont(Font ob)
Font getFont() - return current Graphics Font
void setColor(Color ob)
Color getColor() - return current Graphics Color
void drawString(String str,int x,int y)
void drawLine(int x,int y,int x1,int y1)
g.drawLine(10,10,200,10);
void drawRect(int x,int y,int w,int h)
void fillRect(int x,int y,int w,int h)
void drawRoundRect(int x,int y,int w,int h,int arcwidth,int archeight)
void fillRoundRect(int x,int y,int w,int h,int arcwidth,int archeight)
g.drawRoundRect(10,130,200,100,60,30);
void drawOval(int x,int y,int w,int h)
void fillOval(int x,int y,int w,int h)
g.drawOval(10,240,200,100);
void drawArc(int x,int y,int w,int h,int start,int enddg)
void fillArc(int x,int y,int w,int h,int start,int enddg)
g.drawArc(440,20,200,100,30,300);