Java Animation: Happy Vacation Demo
Java Animation: Happy Vacation Demo
*; public class vacation extends JFrame { ShapeCanvas canvas; public vacation() { canvas = new ShapeCanvas(); JButton button = new JButton("Next"); //declares object or event source class moveAllListener implements ActionListener { public void actionPerformed(ActionEvent e) { [Link](); //certifies the ActionListener command [Link](); //calls moveAll class to move objects } } [Link](new moveAllListener()); setLayout(new BorderLayout()); setTitle( "Happy Happy Vacation!" ); setSize( 800, 600 ); // size of the border setResizable( false ); //disables the maximize button add( canvas, [Link] ); add( button, [Link] ); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // exits program } public static void main ( String args[] ) { ( new vacation() ).setVisible( true ); // if setVisible is false, there'll be no visible output } } interface Shape { public void draw(Graphics g); // calls draw(Graphics g) class public void move(); // calls move() class
} class ShapeCanvas extends Canvas { ArrayList<Shape> s; //declares the shape variables in their position int v = 0; // initializes v value to 0; v = no of clicks Image buffer = null; // scans class for images public ShapeCanvas() { setBackground([Link]); // positions the shapes s = new ArrayList<Shape>(); [Link](new Staff(-10000,20,100,30,0xffff00,100,0,50)); //1 [Link](new Note8(25,105,50,40,20,8,0x00ffff,0,25,22,"letz",0)); //2 [Link](new Note2(110,90,50,40,0x00ffff,25,22,"enjoy",0)); //3 [Link](new Note4(195,105,50,40,0x00ffff,25,21,"our",0)); //4 [Link](new Note8(280,90,50,40,20,8,0x00ffff,0,25,22,"vacation",0)); //5 [Link](new Note2(365,105,50,40,0x00ffff,25,20,"&",0)); //6 [Link](new Note4(450,90,50,40,0x00ffff,25,20,"4get",0)); //7 [Link](new Note8(535,105,50,40,20,8,0x00ffff,0,25,22,"diz",0)); //8 [Link](new Note2(620,90,50,40,0x00ffff,25,22,"hell",0)); //9 [Link](new Note4(705,105,50,40,0x00ffff,25,20,"sem" ,0)); //10 [Link](new Heart(250,225,300,20,0xff0000,0xff1493,0,0,0,true)); //11 [Link](new Guitar(25, 500, 0x800080)); //12 [Link](new Guitar(650, 500, 0x0000cd)); //13 } public void paint(Graphics g2) { if(buffer == null) { buffer = createImage(getWidth(), getHeight()); } Graphics g = [Link](); [Link](0, 0, getWidth(), getHeight()); //clears screen to give way for the ff if(v>=0) [Link](0).draw(g); //condition used to display staff for(int i=1; i<7; i++) { if(v>=i+2) { [Link](i).draw(g); //condition used to display first note }
} if(v>=8) { [Link](11).draw(g); // gets guitar w/ heart [Link](12).draw(g); // gets guitar w/ heart } if(v==8) // 8th Click displays "4get" { Font music = new Font("Curlz MT", [Link], 150); [Link](music); [Link](new Color(0xff00ff)); [Link](" 4get", 218, 358); //Shadow colored pink (x,y) [Link](new Color(0xffffff)); [Link](" 4get",215, 355); } if(v==9) { Font music = new Font("Curlz MT", [Link], 150); [Link](music); [Link](new Color(0x8a2be2)); [Link](" 4get", 218, 358); [Link](new Color(0xffffff)); [Link](" 4get",215, 355); } if(v==10) { Font music = new Font("Curlz MT", [Link], 150); [Link](musicP); [Link](new Color(0xff0000)); [Link](" 4get", 218, 358); [Link](new Color(0xffffff)); [Link](" 4get",215, 355); } if(v>=11) { [Link](7).draw(g); } if(v>=12) { [Link](8).draw(g); } if(v>=13) { [Link](9).draw(g); [Link](10).draw(g); // gets heart }
if(v==13) { Font heart = new Font("Curlz MT", [Link], 90); [Link](heart); [Link](new Color(0xff0000)); [Link]("HELL SEM", 218, 358); [Link](new Color(0xffffff)); [Link]("HELL SEM",215, 355); } if(v>=14) { Font hvd = new Font("Papyrus", [Link], 40); [Link](hvd); [Link](new Color(0x000000)); [Link]("Happy Happy Vacation!", 162, 342); [Link](new Color(0xffffff)); [Link]("Happy Happy Vacation!", 165, 340); } [Link](buffer, 0, 0, null); } public void update(Graphics g) // initiates next button event { paint(g); } public void moveAll() // responsible for the movement of the notes { if(v>=0) [Link](0).move(); for(int i=1; i<[Link](); i++) { if(v>=i+2) { [Link](i).move(); } } v++; } } class Line implements Shape// responsible for all the lines { int x1, y1, x2, y2, color, moveY; boolean a, b;
public Line( int x1, int y1, int x2, int y2, int color, int moveY, boolean a, boolean b) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; [Link] = color; [Link] = moveY; this.a = a; this.b = b; } public void draw(Graphics g) { [Link](new Color(color)); [Link](x1,y1,x2,y2); } public void move() { if(a) { if(b) { y1 -= moveY; y2 -= moveY; b = false; } else { y1 += moveY; y2 += moveY; b = true; } } } } class Circle implements Shape { int x, y, w, h, color, newC, moveY, check; boolean a = true; boolean b;
public Circle( int x, int y, int w, int h, int color, int newC, int moveY, int check, boolean b) { this.x = x; this.y = y; this.w = w; this.h = h; [Link] = color; [Link] = newC; [Link] = moveY; [Link] = check; this.b = b; } public void draw(Graphics g) { if(a) [Link](new Color(color)); else [Link](new Color(newC)); [Link](x,y,w,h); } public void move() // responsible for the movement of the circle { if(check == 0) { if(a) a = false; else a = true; } if(check == 1) { if(b) { y -= moveY; b = false; } else { y += moveY; b = true; } } }
} class Rectangle implements Shape { int x, y, w, h, color; public Rectangle( int x, int y, int w, int h, int color) { this.x = x; this.y = y; this.w = w; this.h = h; [Link] = color; } public void draw(Graphics g) { [Link](new Color(color)); [Link](x,y,w,h); } public void move() {} } class Diamond implements Shape { int[] x = new int[4]; int[] y = new int[4]; int color, newC; boolean a = true; public Diamond(int x1, int y1, int s, int color, int newC) { x[0] = x1; x[1] = x1 + (s/2); x[2] = x1 + s; x[3] = x1 + (s/2); y[0] = y1 + (s/2); y[1] = y1 + s; y[2] = y1 + (s/2); y[3] = y1; [Link] = color; [Link] = newC; } public void draw(Graphics g) // responsible for the colors
{ if(a) [Link](new Color(color)); else [Link](new Color(newC)); [Link](x,y,4); } public void move() { if(a) a = false; else a = true; } } class Heart implements Shape { Circle c1; Circle c2; Diamond d; public Heart(int x1, int y1, int s, int cx, int color, int newC, int moveX, int moveY, int check, boolean b) { c1 = new Circle( x1-(s/7)-1, y1-(s/7),(s*5/7), (s*5/7), color, newC, moveY, check, b); c2 = new Circle( x1+(s/2)-(s/7)+cx, y1-(s/7), (s*5/7), (s*5/7), color, newC, moveY, check, b); d = new Diamond(x1, y1, s, color, newC); } public void draw(Graphics g) // displays heart { [Link](g); [Link](g); [Link](g); } public void move() // moves heart { [Link](); [Link](); [Link]();
} } class Curve implements Shape //curves of the staff { int x, y, w, h, color, moveX, moveY, check; boolean b; public Curve(int x, int y, int w, int h, int color, int moveX, int moveY, int check, boolean b) { this.x = x; this.y = y; this.w = w; this.h = h; [Link] = color; [Link] = moveX; [Link] = moveY; [Link] = check; this.b = b; // boolean value to know when to move staff } public void draw(Graphics g) { [Link](new Color(color)); [Link](x, y, w, h, 0, 180); [Link](x+w, y, w, h, 0, -180); } public void move() { if(check == 0) { x += moveX; } else if(check == 1) { if(b) { y -= moveY; b = false; } else { y += moveY; b = true;
} } } } class Poly implements Shape // All shapes with corners are polygons except circle { int[] x = new int[5]; int[] y = new int[5]; int color; public Poly(int x1, int y1, int w, int h, int color) { x[0] = x1; x[1] = x1+(w/2); x[2] = x1+w; x[3] = x1+(w*2/3); x[4] = x1+(w/3); y[0] = y1; y[1] = y1-(h/3); y[2] = y1; y[3] = y1-h; y[4] = y1-h; [Link] = color; } public void draw(Graphics g) { [Link](new Color(color)); [Link](x,y,5); } public void move() {} } class Guitar implements Shape { Poly p; Rectangle a, b; Heart h; Line[] l = new Line[6]; public Guitar(int x, int y, int color) { p = new Poly(x,y,120, 150,color); a = new Rectangle(x+40,y-90,40,20,0x000000);
b = new Rectangle(x+40,y-250,40,120,0xd2691e); for(int i=0; i<6; i++)// to create two guitars l[i] = new Line( x+45+(i*6), y-250, x+45+(i*6), y-90, 0x000000, 0, false, false); h = new Heart(x+38,y-270,45,3,0xff0000,0xff0000,0,0,3,false); } public void draw(Graphics g) { [Link](g); [Link](g); [Link](g); for(int i=0; i<6; i++) // to create two guitars l[i].draw(g); [Link](g); } public void move() {} } class Words implements Shape { int size, x, y, color, moveY; boolean b; String word; public Words(int size, int x, int y, int moveY, String word, boolean b) { [Link] = size; this.x = x; this.y = y; [Link] = moveY; [Link] = word; this.b = b; } public void draw(Graphics g) { Font f = new Font("Papyrus", [Link] | [Link], size); [Link](f); [Link]([Link]); [Link](word,x,y); } public void move() { if(b)
{ y -= moveY; b = false; } else { y += moveY; b = true; } } } class Note4 implements Shape { Circle c; Line l; Words W; public Note4(int x, int y, int w, int h, int color, int moveY, int size, String word, int a) { c = new Circle(x, y, w, h, color, color, moveY, 1, true); l = new Line( x-(h/2), y+(h/2), x+w+(h/2), y+(h/2), color, moveY, true, true); W = new Words(size, x-a+7, y+27, moveY, word, true); } public void draw(Graphics g) { [Link](g); [Link](g); [Link](g); } public void move() { [Link](); [Link](); [Link](); } } class Note2 implements Shape { Circle c; Line l; Words W;
public Note2(int x, int y, int w, int h, int color, int moveY, int size, String word, int a) { c = new Circle(x, y, w, h, color, color, moveY, 1, true); l = new Line( x+w-1, y+(h/2), x+w-1, y-w, color, moveY, true, true); W = new Words(size, x-a+7, y+27, moveY, word, true); } public void draw(Graphics g) { [Link](g); [Link](g); [Link](g); } public void move() { [Link](); [Link](); [Link](); } } class Note8 implements Shape { Circle c; Line l; Curve C; Words W; public Note8(int x, int y, int w, int h, int wA, int hA, int color, int moveX, int moveY, int size, String word, int a) { c = new Circle(x, y, w, h, color, color, moveY, 1, true); l = new Line( x+w-1, y+(h/2), x+w-1, y-w, color, moveY, true, true); C = new Curve( x+w, y-w, wA, hA, color, moveX, moveY, 1, true); W = new Words(size, x-a+7, y+27, moveY, word, true); } public void draw(Graphics g) { [Link](g); [Link](g); [Link](g); [Link](g); }
public void move() { [Link](); [Link](); [Link](); [Link](); } } class StaffL implements Shape //displays the staff line as a whole // without this, the staff line will appear broken { Curve[] c; int n; public StaffL(int x, int y, int w, int h, int color, int moveX, int moveY, int n) { this.n = n; c = new Curve[n]; for(int i = 0; i<n; i++) { c[i] = new Curve( x+(i*w*2), y, w, h, color, moveX, moveY, 0, true); } } public void draw(Graphics g) { for(int i = 0; i<n; i++) { c[i].draw(g); } } public void move() { for(int i = 0; i<n; i++) { c[i].move(); } } } class Staff implements Shape //displays the staff as a whole // without this, the staff will appear broken {
StaffL[] s; public Staff(int x, int y, int w, int h, int color, int moveX, int moveY, int n) { s = new StaffL[5]; for(int i = 0; i<5; i++) // mirrors the staff line into five { s[i] = new StaffL( x, y+(h*i), w, h, color, moveX, moveY, n); } } public void draw(Graphics g) { for(int i = 0; i<5; i++) // mirrors the staff line into five { s[i].draw(g); } } public void move() { for(int i = 0; i<5; i++) // mirrors the staff line into five { s[i].move(); } } }
import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; /* <applet code="[Link]" width=670 height=300> </applet> */
public class DXBall1 extends Applet implements Runnable,KeyListener,MouseListener { Thread th; static Rectangle ob[] = new Rectangle[30]; Ball ball; Bar bar; Message mes; int i,j; int x = 1; int y=1; int z = 0; int xx,yy1,zz; int b,b1; int flag; //static int yy=0; boolean runing=true; Image dbimage; Graphics dbg; int c1,c2,c3,c4; int flagg=1; //int ballCheck=0; String ss = ""; String ss1=""; String me = ""; static int score = 0; static Font ff; TextArea ta; public void start() { th = new Thread(this); runing = false; //[Link](); } public void stop() { runing = true; th = null; } public void run() { for(; ;)
{ if([Link]()) { ss = "Game Over!!!!!"; ss1 = "You have loss the game"; repaint(); [Link]("braek"); break; } try {
[Link](20); if(runing)break; int tempx=[Link]; int tempy=[Link]; if (tempx==1) [Link](); else ball.move1(); if(tempy==1) ball.move2(); else ball.move3(); if(tempy==1) [Link](); else ball.move3(); repaint();
} catch(InterruptedException ie) { [Link](); } } } public void init() { /*me =" THIS IS A DXBALL GAME. "+
" This Game is Devlopped by [Link] Rahman "+ " University of DIU BATCH 9th ROLL 9007 "+ " Created by Mujibur's Group "+ " HOW TO PLAY "+ " Level 1: First You press mouse "+ "when you press mouse the the ball is moved "+ "Then Score will be increase "+ " Control the bar for using left arrow and right arrow "+ "the Ball moved Randomly "+ "If the ball hits the Rectangle "+ "Then Score will Increase "+ "if the ball is passed the bar level "+ "Game will be over and Game is finished"; setLayout(null); ta = new TextArea(me); [Link](470,120,150,150); [Link](false); add(ta);*/ int xx=30,mm=30; for(int i =0 ;i<24;i=i+3) { ob[i] = new Rectangle(xx,mm); ob[i].display=true; mm=mm+20; ob[i+1] = new Rectangle(xx,mm);
ob[i+1].display=true; mm=mm+20; ob[i+2] = new Rectangle(xx,mm); ob[i+2].display=true; xx=xx+50; mm = 30; } mes =new Message(); ball = new Ball(90,250); bar = new Bar(70); ff = new Font("arial",[Link],20); [Link](this); [Link](this); } public void paint(Graphics g) { int count=0; for(int i=0;i<24;i++) { if(ob[i].display==false) count++; } if(count==24) { [Link](g); return; } [Link](new Font("arial",[Link],15)); [Link]([Link]); [Link](470,30,150,70); [Link]([Link]); [Link]("Score: "+score,480,50); [Link]("Status:"+[Link],480,70); [Link]("Life: "+[Link],480,90); //[Link](""+[Link],455,50); [Link]([Link]); [Link](20,20,410,300); [Link]([Link]);
[Link](ff); [Link](ss,100,200); [Link](ss1,100,230); [Link]([Link]); for(int j = 0;j<24;j++) { if(ob[j].display==false) { continue; } [Link]("check false : "+ob[j].display); if(ob[j].display==true) { breaking(j) ; } if(ob[j].display==true) ob[j].ppaint(g); } [Link](g); [Link](g); } public void keyTyped(KeyEvent k) { } public void keyReleased(KeyEvent k) { } public void keyPressed(KeyEvent k) { int R =[Link](); if(R==k.VK_LEFT) { if([Link] > 25) [Link]=[Link]-10; [Link]("Left"); repaint();
} } public void mousePressed(MouseEvent me) { [Link](); } public void mouseReleased(MouseEvent me) { } public void mouseClicked(MouseEvent me) { } public void mouseExited(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void update(Graphics g) //to remove flickering { if (dbimage==null) { dbimage=createImage([Link]().width,[Link]().height); dbg=[Link](); } [Link](getBackground()); [Link](0,0,[Link]().width,[Link]().height); [Link](getForeground()); paint(dbg);
[Link](dbimage,0,0,this); } public boolean breaking(int i) { if(check(i)) return true; else return false; } public boolean check(int i) { int am,ami; am = [Link](ball.x1-ob[i].x); ami = [Link](ball.y1-ob[i].y); if(am<20 && ami<20 ) { ob[i].display=false; score=score+10; [Link]=1; return true; } else { return false; } } } //Class main is end
Graphics g; int ballCheck=0; boolean display; Rectangle(int m ,int n) { x = m; y =n; } public void ppaint(Graphics g) { [Link](x,y,40,10); } } class Ball { static int flag=3; static int flagx=1; static int flagy=2; static int Point = 0; static String over=""; static int life=1; int x,y,m; int x1,y1; Graphics g; Ball(int a1,int a2) { x1 = a1; y1 = a2; } public void bpaint(Graphics g) { //[Link](" y : "+y1,455,250); if(20>=x1||x1>=410||y1<=20||y1>=260) //checking boundaries { getflag(); } [Link]([Link]); [Link](x1,y1,15,15); } public boolean over()
{ //[Link](""+y1); if(y1>290) return true; else return false; } public void move() { x1++; } public void move1() { x1--; } public void move2() { y1=y1+2; } public void move3() { y1=y1-2; } public void move4() { x1++; y1--; } public void getflag() { if(x1<=20) // check boundaries and ball motion { x1=20; flagx=1; } if(x1>=410) { x1=410; flagx=2; }
if(y1<=20) { y1=20; Point = Point +10; flagy=1; } if(y1>=260) { if([Link]>=x1||x1<=([Link]+50)) { [Link]("/n /n true [Link] :"+[Link]+" Y1:"+y1); [Link](" /n/n/n/ncheck ok"); y1=260; flagy=2; } else { [Link]("/n /n [Link] :"+[Link]+" Y1:"+y1); if([Link]>260 && [Link]<200) { flag=2; [Link]("/n game over"); } else { if([Link]>290) { } else { life=0; [Link]([Link]); over="LOSS GAME"; } } } //else1 end } } }//end class
class Bar { int ss; static int yy=0; int q; static int pp; Bar(int a) { yy=a+yy; } public void barpaint(Graphics g) { [Link]([Link]); [Link](yy,270,60,10); } } class Message { public void mess(Graphics g) { [Link]([Link]); [Link](0,0,400,300); [Link]([Link]); [Link]([Link]); [Link]("YOU HAVE WON THE GAME",160,180); [Link]("Your Score is:"+[Link],160,200); } }
-------------------------------------------------(3) CALENDAR & CLOCK -------------------------------------------------import [Link].*; import [Link].*; import [Link]; import [Link].*; public class sample extends Applet implements Runnable{ Button m100; //year decrement buttons.
Button m10; Button m1; Button p1; Button p10; Button p100; Button fontColor; Button backColor; TextField yearbox;
int day[] = new int[12]; int year, dayofweek; int lineinc = 16; int lindex; int FontIndex, BackIndex; String line = ""; //clock int width, height; Thread t = null; boolean threadSuspended; int hours=0, minutes=0, seconds=0; String timeString = ""; ///// Read Date from the computer to setup initial display ///// Calendar ReadTime = [Link](); int CurrentYear = [Link]([Link]); public void init() { backColor = new Button("BackColor"); m100 = new Button("-100"); m10 = new Button("-10"); m1 = new Button("-1"); yearbox = new TextField(4); //box to put year in. p1 = new Button("+1"); p10 = new Button("+10"); p100 = new Button("+100"); fontColor = new Button("FontColor"); FlowLayout Buttons = new FlowLayout([Link], 10, 7 ); setLayout(Buttons);
add ( fontColor ); add ( m100 ); add ( m10 ); add ( m1 ); add ( yearbox ); add ( p1 ); add ( p10 ); add ( p100 ); add ( backColor );
//Year buttons.
//clock width = getSize().width; height = getSize().height; } //clock public void start() { if ( t == null ) { t = new Thread( this ); [Link]( Thread.MIN_PRIORITY ); threadSuspended = false; [Link](); } else { if ( threadSuspended ) { threadSuspended = false; synchronized( this ) { notify(); } } } } public void stop() { threadSuspended = true; } void drawHand( double angle, int radius, Graphics g ) { angle -= 0.5 * [Link]; int x = (int)( radius*[Link](angle) ); int y = (int)( radius*[Link](angle) ); [Link]( width*3+185, height*2-20, width*3+185 + x, height*2-20 + y ); } void drawWedge( double angle, int radius, Graphics g ) {
angle -= 0.5 * [Link]; int x = (int)( radius*[Link](angle) ); int y = (int)( radius*[Link](angle) ); angle += 2*[Link]/3; int x2 = (int)( 5*[Link](angle) ); int y2 = (int)( 5*[Link](angle) ); angle += 2*[Link]/3; int x3 = (int)( 5*[Link](angle) ); int y3 = (int)( 5*[Link](angle) ); [Link]( width*3+185+x2, height*2-20+y2, width*3+185 + x, height*220 + y ); [Link]( width*3+185+x3, height*2-20+y3, width*3+185 + x, height*220 + y ); [Link]( width*3+185+x2, height*2-20+y2, width*3+185 + x3, height*220 + y3 ); } public void paint( Graphics g ) { //CLOCK [Link](1040,190, 380, 380); [Link]( [Link] ); drawWedge( 2*[Link] * hours / 12, width/5, g ); drawWedge( 2*[Link] * minutes / 60, width/3, g ); drawHand( 2*[Link] * seconds / 60, width/2, g ); [Link]( [Link] ); [Link]( timeString, 1210, height+280 ); //calendar Font font1 = new Font( "Courier", [Link], 16 ); //Fixed width font needed Font font2 = new Font( "Courier", [Link], 16 ); switch ( BackIndex ) //Background Color settings { case 0: setBackground( [Link] ); break; case 1: setBackground( [Link] ); break; case 2: setBackground( [Link] ); break; case 3: setBackground( [Link] ); break; case 4: setBackground( [Link] ); break; case 5: setBackground( [Link] ); break; case 6: setBackground( [Link] ); break; case 7: setBackground( [Link] ); break; case 8: setBackground( [Link] ); break; case 9: setBackground( [Link] ); break;
case 10: setBackground( [Link] ); break; case 11: setBackground( [Link] ); break; case 12: setBackground( [Link] ); break; } switch ( FontIndex ) //Font Color settings { case 0: [Link]( [Link] ); break; case 1: [Link]( [Link] ); break; case 2: [Link]( [Link] ); break; case 3: [Link]( [Link] ); break; case 4: [Link]( [Link] ); break; case 5: [Link]( [Link] ); break; case 6: [Link]( [Link] ); break; case 7: [Link]( [Link] ); break; case 8: [Link]( [Link] ); break; case 9: [Link]( [Link] ); break; case 10: [Link]( [Link] ); break; case 11: [Link]( [Link] ); break; case 12: [Link]( [Link] ); break; } ////////// Draw Frame around Months ////////// [Link]( 0, 0, 779, 679 ); // main box [Link]( 260, 40, 260, 680 ); // Center verticle lines [Link]( 520, 40, 520, 680 ); [Link]( 0, 40, 780, 40 ); // Lines around buttons [Link]( 0, 72, 780, 72 ); [Link]( 0, 200, 780, 200 ); // Horizontal lines around Months [Link]( 0, 232, 780, 232 ); [Link]( 0, 360, 780, 360 ); [Link]( 0, 392, 780, 392 ); [Link]( 0, 520, 780, 520 ); [Link]( 0, 552, 780, 552 ); [Link]( font2 ); String Year = [Link](); year = [Link]( Year ); if ( year < 1 ) { [Link]( " return;
for ( int i = 0; i <= 11; i++ ) day[i] = 1; //initialize day of each Month to 1 ////////////////// Main program flow //////////////////////////// for ( int row= 0 ; row <= 3 ; ++row ) // 4 rows of Months 0-1-2 3-4-5 6-7-8 9-10-11 { [Link]( font2 ); if ( row != 0 ) lindex += lineinc; switch (row) // Draw Month names { case 0: [Link]( " ***** JANUARY ****** ***** FEBRUARY ***** ******* MARCH ******", 10, lindex ); break; case 1: [Link]( " ****** APRIL ******* ******* MAY ******** ******* JUNE *******", 10, lindex ); break; case 2: [Link]( " ******* JULY ******* ****** AUGUST ****** ***** SEPTEMBER ****", 10, lindex ); break; case 3: [Link]( " ***** OCTOBER ****** ***** NOVEMBER ***** ***** DECEMBER *****", 10, lindex ); } lindex += 2*lineinc; //increment line space by 2. One blank line. [Link]( " Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa", 10, lindex ); lindex += lineinc; for ( int week = 0 ; week <= 5 ; ++week ) //week loops. one line includes one week for 3 Months. { [Link]( font1 ); line = " "; for ( int col = 0 ; col <= 2 ; ++col ) //3 Months in a row { if (week == 0) //1st week needs to know what day to start. firstweek( row*3 + col, year ); else otherweek( row*3 + col );
[Link](line, 10, lindex); lindex += lineinc; line = " "; } } } // Week end // Row end // Paint end
/////////////////// first week of the Month ///////////////////// public void firstweek( int Month, int year ) { int dayofweek = firstday ( Month, year ); for ( int i = 0 ; i < dayofweek ; i++ ) line = [Link](" "); do { line = [Link]( " " + [Link]( day[Month] ) ); //print day of Month with leading blanks. ++day[Month]; ++dayofweek; } while (dayofweek <= 6 ); if ( ((Month + 1) % 3) != 0 ) //if last day of week, print spaces between Month. line = [Link](" "); } /////////////////// weeks 2 - 6 ///////////////////// public void otherweek( int Month ) { dayofweek = 0; //initialize day of week to 0. Sunday int daysinMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0))) daysinMonth[1] = 29; do { if ( day[Month] <= daysinMonth[ Month ] ) //check to see if days still left. {
if ( day[Month] < 10 ) //if 1-9, 2 leading spaces needed. line = [Link]( " " + [Link]( day[Month] ) ); else //if 10-31, 1 leading space needed. line = [Link]( " " + [Link]( day[Month] ) ); ++day[Month]; ++dayofweek; } else { line = [Link](" "); //if after last day of Month, print blanks. ++dayofweek; } } while ( dayofweek <= 6 ); if ( ((Month + 1) % 3) != 0 ) //if last day of week, print spaces between Month. line = [Link](" "); } //end of otherweek ///////////////// first day of Month //////////////// public int firstday( int Month, int year ) { int yeardiff, days_since, dayofyear[]={ 0,31,59,90,120,151,181,212,243,273,304,334 }; yeardiff = year - 1; days_since = yeardiff * 365; days_since += ( ( yeardiff/4 ) - ( yeardiff/100 ) + ((yeardiff)/400) ) + dayofyear[ Month ]; if (((((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)))) && ( Month > 1 )) days_since++; return ( ( days_since + 1 ) % 7 ); } ////////// Button and Mouse Activity /////////////// public boolean action(Event event, Object arg ) { if ([Link] instanceof Button ) HandleButtons(arg); repaint(); return true; }
/////////////////// Button Handler ////////////////// protected void HandleButtons(Object label) { String NewYear; if ( label == "-100" ) year -= 100; else if ( label == "-10" ) year -= 10; else if ( label == "-1" ) year -= 1; else if ( label == "+1" ) year += 1; else if ( label == "+10" ) year += 10; else if ( label == "+100" ) year += 100; else if ( label == "Now" ) year = CurrentYear; NewYear = [Link]( year ); [Link]( NewYear ); ////////////// Font and Background Color //////////// if ( label == "FontColor" ) { FontIndex++; if ( FontIndex == 13 ) FontIndex = 0; } if ( label == "BackColor" ) { BackIndex++; if ( BackIndex == 13 ) BackIndex = 0; } } //handle buttons public void run() { try { while (true) { // Here's where the thread does some work
Calendar cal = [Link](); hours = [Link]( Calendar.HOUR_OF_DAY ); if ( hours > 12 ) hours -= 12; minutes = [Link]( [Link] ); seconds = [Link]( [Link] ); SimpleDateFormat formatter = new SimpleDateFormat( "hh:mm:ss", [Link]() ); Date date = [Link](); timeString = [Link]( date ); // Now the thread checks to see if it should suspend itself if ( threadSuspended ) { synchronized( this ) { while ( threadSuspended ) { wait(); } } } repaint(); [Link]( 1000 ); // interval given in milliseconds } } catch (InterruptedException e) { } } } // calendar class end
------------------------------------------(4) PAYSLIP SYSTEM ------------------------------------------import [Link].*; import [Link].*; import [Link].*; public class Project extends Applet implements ActionListener,ItemListener{ Label CA = new Label ("COMIC ALLEY INCORPORATED"); Label pay = new Label ("PAYSLIP"); Label Name = new Label ("Name: "); TextArea t=new TextArea(30,45); Label Pos = new Label ("Position: "); Choice CPos= new Choice ();
Label CBran = new Label ("Company-Branch: "); CheckboxGroup CBra = new CheckboxGroup(); Checkbox MOA = new Checkbox(); Checkbox Mega = new Checkbox(); Checkbox Ortigas = new Checkbox(); Checkbox Rob = new Checkbox(); Checkbox Gway = new Checkbox(); Checkbox SM = new Checkbox(); Label HW= new Label ("Hours Work: "); Label Rate = new Label ("Rate: "); Label Bonus = new Label ("Bonus: "); Label Gross = new Label ("Gross: "); Label Deduction = new Label ("Deduction: "); Label Net = new Label ("Net Income: "); TextField txtName = new TextField ("Type your Name Here...", 50); TextField txtHW = new TextField ("Type Here...", 12); TextField txtRate = new TextField ("", 12); TextField txtBonus = new TextField ("", 12); TextField txtGross = new TextField ("", 12); TextField txtDedct = new TextField ("", 12); TextField txtNet = new TextField ("", 12); Button Sub = new Button ("SUBMIT"); Button Can = new Button ("CANCEL"); Font font = new Font ("Courier new", [Link] , 12); Font Ffont = new Font ("Comic Sans", [Link] , 30); Font Ffnt = new Font ( "",[Link] , 20); int Medical,SSS,Tax; int G, T, N; public void init(){ setBackground ([Link]); setFont (font); setForeground ([Link]); add (CA); add (pay); add (Name); add (txtName); add (Pos); CPos= new Choice(); [Link]("Store Manager"); [Link]("Shift Manager"); [Link]("Employee"); add (CPos);
add (CBran); CBra= new CheckboxGroup(); MOA=new Checkbox("Comic Alley-MOA",CBra,false); Mega=new Checkbox("Comic Alley-Megamall",CBra,false); Ortigas=new Checkbox("Comic Alley-Ortigas",CBra,false); Rob=new Checkbox("Comic Alley-Robinson",CBra,false); Gway=new Checkbox("Comic Alley-Gateway",CBra,false); SM=new Checkbox("Comic Alley-SM TAYTAY",CBra,false); add (MOA); add (Mega); add (Ortigas); add (Rob); add (Gway); add (SM); add (HW); add (txtHW); add (Rate); add (txtRate); add (Bonus); add (txtBonus); add (Gross); add (txtGross); add (Deduction); add (txtDedct); add (Net); add (txtNet); add(t); add(Sub); [Link](this); add(Can); [Link](this); [Link](this); [Link](this); [Link](this); [Link](this); [Link](this); [Link](this); [Link](this); }//END of INIT() public void paint (Graphics gr){
[Link]([Link]); [Link](450, 20, 750, 10); [Link]([Link]); [Link](450, 28, 650, 10); [Link]([Link]); [Link](20, 50, 10, 550); [Link]([Link]); [Link](28, 50, 10, 450); [Link]([Link]); [Link](75, 75, 802, 505, 80, 80); [Link](Color.LIGHT_GRAY); [Link](78, 79, 798, 499, 500, 500); [Link]( [Link] ); [Link]( 88, 89, 778, 479, 500, 500); [Link](Ffont); [Link]([Link]); [Link](20, 20); [Link](Ffnt); [Link]([Link]); [Link]([Link]); [Link](85,100); [Link](200, 130); [Link](290, 130); [Link](200, 160); [Link](290, 160); [Link](200, 190); [Link](320,190); [Link](320, 220); [Link](320, 250); [Link](500,190); [Link](500, 220); [Link](500, 250); [Link](200, 290); [Link](290, 290); [Link](200, 320); [Link](290, 320); [Link](200, 350); [Link](290, 350); [Link](200, 380);
[Link](290, 380); [Link](200, 410); [Link](290, 410); [Link](200, 440); [Link](290, 440); [Link](300, 470); [Link](410, 470); [Link](900, 100); [Link](Color.LIGHT_GRAY); }//END OF PAINT public void actionPerformed(ActionEvent e) { if([Link]().equals("SUBMIT")) {//Start of ([Link]().equals("SUBMIT")) if([Link]().equals("Store Manager")) { [Link]("500"); [Link]("1000"); } else if([Link]().equals("Shift Manager")) { [Link]("350"); [Link]("700"); } else { [Link]("150"); [Link]("400"); } if ([Link]().equals(Sub)){ //Start of Computation of GROSS G=([Link]([Link]()))*([Link]([Link]())); [Link]([Link](G)); }//End of Computation of GROSS //Deduction if([Link]().equals("Store Manager")) {//SM SSS=500; Medical=100; if([Link](7000)) { Tax=1000; }
else if([Link](6999)&&([Link](4000))) { Tax=700; } else { Tax=500; } }//End-SM else if([Link]().equals("Shift Manager")) {//ShM SSS=300; Medical=100; if([Link](7000)) { Tax=1000; } else if([Link](6999)&&([Link](4000))) { Tax=700; } else { Tax=500; } }//End-ShM else {//Emp SSS=125; Medical=100; if([Link](7000)) { Tax=1000; } else if([Link](6999)&&([Link](4000))) { Tax=700; } else { Tax=500; } }//End-Emp }//END([Link]().equals("SUBMIT"))
if ([Link]().equals(Sub)){//Start of Computation of DEDUCTION T=SSS+Medical+Tax; [Link]([Link](T)); }//End of Computation of Deduction if ([Link]().equals(Sub)){//Start of Computation of Net N=(([Link]([Link]()))+ ([Link]([Link]())))-([Link]([Link]())); [Link]([Link](N)); }//End of Computation of Net if ([Link]().equals(Sub)){ //Start-TextAREA [Link]("Name: "+[Link]()+ "\nPosition: "+[Link]()+ "\nCompany-Branch: "+[Link]().getLabel()+ "\nNumber of Hours Work: "+[Link]()+ " hrs."+ "\n"+ "\nComputation of GROSS"+ "\nRate * Hours Work = Gross"+ "\n"+[Link]()+" * "+[Link]()+ "\nGROSS = "+[Link]()+ "\nBonus = "+[Link]()+ "\n"+ "\nComputation of DEDUCTIONS"+ "\nSSS + Medical + Tax = Total Deductions"+ "\nSSS = "+SSS+ "\nMedical = "+Medical+ "\nTax = "+Tax+ "\nTOTAL DEDUCTIONS = "+[Link]()+ "\n"+ "\nComputation of NET INCOME"+ "\n( Gross + Bonus ) - Deduction = NET INCOME"+ "\nNET INCOME = "+[Link]()); }//End-TextAREA if([Link]().equals("CANCEL")) {//Start-Cancel repaint(); }//End-Cancel }//End of Applet Event
public void itemStateChanged(ItemEvent e) {//Start-ItemChanged throw new UnsupportedOperationException("Not supported yet."); }//End-ItemChanged }//Class Name
-----------------------------------------------(5) CALCULATOR -----------------------------------------------import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class Project extends Applet implements Runnable { int width, height; Thread t = null; boolean threadSuspended; int hours=0, minutes=0, seconds=0; String timeString = ""; public void init() { width = getSize().width; height = getSize ().height; setBackground( [Link] ); //represents the background of the applet as a whole } public void start() { if ( t == null ) { t = new Thread( this
); [Link]( Thread.MIN_PRIORITY ); threadSuspended = false; [Link](); } else { if ( threadSuspended ){ threadSuspended = false; synchronized( this ){ notify(); } } } } public void stop() { threadSuspended = true; } public void run() { try { while (true) { Calendar cal = [Link](); //Here's where the thread does some work hours = [Link]( Calendar.HOUR_OF_DAY ); if ( hours > 12 )
hours -= 12; minutes = [Link]( [Link] ); seconds = [Link]( [Link] ); //this declaration links itself to the info such as date and time displayed on the PC SimpleDateFormat formatter = new SimpleDateFormat( "hh:mm:ss", [Link]() ); Date date = [Link](); timeString = [Link]( date ); if ( threadSuspended ) { // Now the thread checks to see if it should suspend itself synchronized( this ) { while ( threadSuspended ) { wait();
} } } repaint(); [Link]( 1000 ); //this represents that interval should be given in milliseconds } } catch (InterruptedException e) { } } void drawHand( double angle, int radius, Graphics g ){ angle -= 0.5 * [Link]; int x = (int)( radius*[Link](angle) ); int y = (int)( radius*[Link](angle) ); [Link]( width/2, height/2, width/2 + x, height/2 + y ); } void drawWedge( double angle, int radius, Graphics g ){ angle -= 0.5 * [Link]; int x = (int)( radius*[Link](angle) );
int y = (int)( radius*[Link](angle) ); angle += 2*[Link]/3; int x2 = (int)( 5*[Link](angle) ); int y2 = (int)( 5*[Link](angle) ); angle += 2*[Link]/3; int x3 = (int)( 5*[Link](angle) ); int y3 = (int)( 5*[Link](angle) ); //represents the degree of turn for the line of hands [Link]( width/2+x2, height/2+y2, width/2 + x, height/2 + y ); //represents the first layer line of hands of the minute and hour [Link]( width/2+x3, height/2+y3, width/2 + x, height/2 + y ); //represents the second layer line of hands of the minute and hour [Link]( width/2+x2, height/2+y2, width/2 + x3, height/2 + y3 ); //represents the small lines connecting the
minute and hour hands } public void paint( Graphics g){ [Link]( [Link] ); //represents the color of the hand lines drawWedge( 2*[Link] * hours / 12, width/5, g ); //represents the 2 hour lines length drawWedge( 2*[Link] * minutes / 60, width/3, g ); //represents the 2 minute lines length drawHand( 2*[Link] * seconds / 60, width/5, g ); //represents the line for the second hand //changed the width of drawHand for second to /4 as it is too long if /2 [Link]( [Link] ); //represents the color of numeric time [Link]( timeString, 5, height-5 );
-----------------------------------------(6) TIC TAC TOE -----------------------------------------import [Link].*; import [Link].*; import [Link].*; import [Link]; import [Link]; public class TicTacToe implements ActionListener { //actionlistener usually used in buttons; event like hyperlink String CPU, CPU1; final String VERSION = "3.0"; //declaring of variable that when version appears on code, it would display "3.0" //Setting up ALL the variables JFrame window = new JFrame("Tic-Tac-Toe " + VERSION); //title bar of window frame JMenuBar maMain = new JMenuBar(); //this is the Menu Bar Button that we seen above the applet JMenuItem maNewGame = new JMenuItem("New Game"), //'New Game' option on Menu bar maInstruction = new JMenuItem("Instructions"), //'Instructions' option on Menu bar maExit = new JMenuItem("Exit"), //'Exit' option on Menu bar maAbout = new JMenuItem("About"); //'About' option on Menu bar //this contain the name of the buttons in menu bar JButton ca = new JButton("Player vs Player"), //declaring of buttons on application caSetName = new JButton("Set Player Names"), //these are the options that will appear as buttons caQuit = new JButton("Quit"), //these are the options that will appear as buttons caCPU = new JButton("Player vs Computer"), //these are the options that will appear as buttons caContinue = new JButton("Continue..."), caTryAgain = new JButton("Try Again?"); JButton caEmpty[] = new JButton[10]; JPanel mbNewGame = new JPanel(), //declaring of all the panels that will be used in applet mbMenu = new JPanel(), mbMain = new JPanel(), mbTop = new JPanel(), mbBottom = new JPanel(), mbQuitNTryAgain = new JPanel(), mbPlayingField = new JPanel(); JLabel lblTitle = new JLabel("Tic-Tac-Toe"), //title of the game at the beginning page lblTurn = new JLabel(), //label for the turn of players lblStatus = new JLabel("", [Link]), //label for status of scores lblMode = new JLabel("", [Link]); JTextArea txtMessage = new JTextArea(); final int winCombo[][] = new int[][] { {1, 2, 3}, {1, 4, 7}, {1, 5, 9}, //winning positions for scoring {4, 5, 6}, {2, 5, 8}, {3, 5, 7}, {7, 8, 9}, {3, 6, 9}
/*Horizontal Wins*/ /*Vertical Wins*/ /*Diagonal Wins*/ }; final int X = 535, Y = 342, mainColorR = 190, mainColorG = 50, mainColorB = 50, //mainColorR - displays the color value of red //mainColorG - displays the color value of green //mainColorB - displays the color value of blue btnColorR = 70, btnColorG = 70, btnColorB = 70; //btnColorR - displays the color value of red for button, //btnColorG - displays the color value of green for button, //btnColorB - displays the color value of blue for button Color clrBtnWonColor = new Color(190, 190, 190); int turn = 1, //declaring of how many turns per player player1Won = 0, player2Won = 0, wonNumber1 = 1, wonNumber2 = 1, wonNumber3 = 1, option; boolean inGame = false, CPUGame = false, win = false; String message, Player1 = "Player 1", Player2 = "Player 2", //showing of text on which player's turn to move and the words Player 1 and 2 to appear on game tempPlayer2 = "Player 2"; public TicTacToe() { //Setting game properties and layout and sytle... //Setting window properties: [Link](X, Y); //size of window or button [Link](350, 260); //[Link](false); [Link](new BorderLayout()); [Link](JFrame.EXIT_ON_CLOSE); //declaring of action for exit button //Setting Menu, Main, Top, Bottom Panel Layout/Backgrounds [Link](new FlowLayout([Link])); //position of Menu bar (if left, right or center) [Link](new FlowLayout([Link])); //position of panel bar (continue, player vs player & etc) [Link](new FlowLayout([Link])); //position of lower panel [Link](new Color(mainColorB)); //represents the color of the space between continue, PVsP, PVsCPU & Set Player names [Link](new Color(mainColorB)); //represents the color of the space on Menu bar [Link](new Color(mainColorR)); //declaration of bg color of main space of title page [Link](new Color(mainColorR)); //declaration of bg color for the part of continue, PVsP, PVsCPU & Set Player names [Link](new Color(mainColorB)); //declaration of bg color for the part of Turn, Player 1 & Player 2 (3rd slide of game) //Setting up Panel QuitNTryAgain [Link](new GridLayout(1, 2, 2, 2)); [Link](caTryAgain); //declaring of adding button for try again [Link](caQuit); //declaring of adding button for quit [Link]([Link]); //Adding menu items to menu bar [Link](maNewGame); [Link](maInstruction); //instruction option [Link](maAbout); //about option [Link](maExit); // Menu Bar is Complete. this are the following button you can see in Menu Bar
//Adding buttons to NewGame panel [Link](new GridLayout(4, 1, 2, 10)); [Link](caContinue); //button for continue [Link](ca); //button for player vs player [Link](caCPU); //button for player vs cpu [Link](caSetName); //button to set name of players //Setting Button propertied [Link](true); //declaring function of button 'try again' [Link](true); //declaring function of button 'continue' //Setting txtMessage Properties [Link](new Color(mainColorR)); [Link]([Link]); [Link](false); //Adding Action Listener to all the Buttons and Menu Items [Link](this); //declaring of the functions for each button; putting animation/events on buttons [Link](this); //this option is to call method [Link](this); //to put action for instruction button [Link](this); //to put action for about button [Link](this); //to put action for pvp button [Link](this); //to put action for pvcpu button [Link](this); //to put action for quit button [Link](this); //to put action for set name button [Link](this); //to put action for continue button [Link](this); //to put action for try again button //Setting up the playing field [Link](new GridLayout(3, 3, 2, 2)); [Link]([Link]); //bg color of the playing field for(int i=1; i<=9; i++) { caEmpty[i] = new JButton(); caEmpty[i].setBackground(new Color(btnColorR, btnColorG, btnColorB)); //color of playing field buttons caEmpty[i].addActionListener(this); //declaring of event on buttons [Link](caEmpty[i]);//Playing Field is complete } //Adding everything needed to pnlMenu and pnlMain [Link]([Link]); //font color of label [Link](lblMode); //label on menu tab (1v1) [Link](maMain); [Link](lblTitle); //label title Tik-Tac-Toe //Adding to window and Showing window [Link](mbMenu, [Link]); [Link](mbMain, [Link]); [Link](true); } public static void main(String[] args) { new TicTacToe();// Calling the class construtor. // PROGRAM STARTS HERE! } //start of all method public void showGame() { // Shows the Playing Field // *IMPORTANT*- Does not start out brand new (meaning just shows what it had before) clearPanelSouth(); [Link](new BorderLayout()); //creating of layout for main [Link](new BorderLayout()); //creating of layout for top
[Link](new BorderLayout()); //creating of layout for bottom [Link](mbPlayingField); //linking playing field on the top panel [Link](lblTurn, [Link]); //this is the position of the information in the playing field [Link](lblStatus, [Link]); //same as above [Link](mbQuitNTryAgain, [Link]); [Link](mbTop, [Link]); [Link](mbBottom, [Link]); [Link](); inGame = true; checkTurn(); checkWinStatus(); } public void newGame() { // Sets all the game required variables to default // and then shows the playing field. // (Basically: Starts a new 1v1 Game) caEmpty[wonNumber1].setBackground(new Color(btnColorR, btnColorG, btnColorB)); caEmpty[wonNumber2].setBackground(new Color(btnColorR, btnColorG, btnColorB)); caEmpty[wonNumber3].setBackground(new Color(btnColorR, btnColorG, btnColorB)); for(int i=1; i<10; i++) { {//this represent the row and column of the playing field caEmpty[i].setText(""); caEmpty[i].setEnabled(true); } turn = 1; win = false; showGame(); }} public void quit() { //method to quit inGame = false; [Link](""); [Link](false); clearPanelSouth(); setDefaultLayout(); [Link](mbNewGame); [Link](mbTop); } public void checkWin() { // checks if there are 3 symbols in a row vertically, diagonally, or horizontally. // then shows a message and disables buttons. If the game is over then it asks // if you want to play again. for(int i=0; i<8; i++) { if( !caEmpty[winCombo[i][0]].getText().equals("") && caEmpty[winCombo[i][0]].getText().equals(caEmpty[winCombo[i][1]].getText()) && // if {1 == 2 && 2 == 3} caEmpty[winCombo[i][1]].getText().equals(caEmpty[winCombo[i][2]].getText())) { /* The way this checks the if someone won is: First: it checks if the btnEmpty[x] is not equal to an empty string- x being the array number inside the multi-dementional array winCombo[checks inside each of the 7 sets][the first number] Secong: it checks if btnEmpty[x] is equal to btnEmpty[y]- x being winCombo[each set][the first number] y being winCombo[each set the same as x][the second number] (So basically checks if the first and second number in each set is equal to each other) Third: it checks if btnEmtpy[y] is eual to btnEmpty[z]- y being the same y as last time and z being winCombo[each set as y][the third number] Conclusion: So basically it checks if it is equal to the btnEmpty is equal to each set of numbers
*/ win = true; wonNumber1 = winCombo[i][0]; wonNumber2 = winCombo[i][1]; wonNumber3 = winCombo[i][2]; caEmpty[wonNumber1].setBackground(clrBtnWonColor); caEmpty[wonNumber2].setBackground(clrBtnWonColor); caEmpty[wonNumber3].setBackground(clrBtnWonColor); break; } } if(win || (!win && turn>9)) { //using if else if statement to determine pop up for winner if(win) { if(caEmpty[wonNumber1].getText().equals("X")) { //message pop-up: this tells or gives pop up if player 1 won message = Player1 + " has won"; player1Won++; //lets scoring update } else { message = Player2 + " has won"; //message pop-up: this tells if player 2 won player2Won++; //lets scoring update } } else if(!win && turn>9) message = "Both players have tied!\nBetter luck next time."; //message pop-up: this tells if both players are tied showMessage(message); for(int i=1; i<=9; i++) { caEmpty[i].setEnabled(false); } [Link](true); //try again button will enable or show up once game is finished checkWinStatus(); //this command will link with the scoring to update the score of given winner once game ends } else checkTurn(); //if game is not finish, it will continue by checking which player's turn it is to make a move } public void AI() { //this is a method for player vs computer option Method doMove; int computerButton; if(turn <= 9) { turn++; computerButton = [Link]( //option of the buttons being empty since start of the game caEmpty[1], caEmpty[2], caEmpty[3], caEmpty[4], caEmpty[5], caEmpty[6], caEmpty[7], caEmpty[8], caEmpty[9]); if(computerButton == 0) Random(); else { caEmpty[computerButton].setText("O"); //setting the character 'o' as the player mark of computer caEmpty[computerButton].setEnabled(false); } checkWin(); //will check winnings of computer 'if won the game' and link with the scoring to update the score of given winner once game ends } }
public void Random() { //command moves of the computer int random; if(turn <= 9) { random = 0; while(random == 0) { random = (int)([Link]() * 10); } if([Link](caEmpty[random])) { caEmpty[random].setText("O"); caEmpty[random].setEnabled(false); } else { Random(); } } } public void checkTurn() { //method for turns of player that will play String whoTurn; if(!(turn % 2 == 0)) { whoTurn = Player1 + " [X]"; //setting of x being player1 character } else { whoTurn = Player2 + " [O]"; //setting of o being player2 character } [Link]("Turn: " + whoTurn); //on the bottom panel, this will display which player's turn to make a move [Link]([Link]); } public void askUserForPlayerNames() { //this is the command that will allow you to set player's name String temp; boolean tempIsValid = false; temp = getInput("Enter player 1 name:", Player1); //this will link the name you entered to player1 so that it will show for the rest of the game if(temp == null) {/*Do Nothing*/} else if([Link]("")) showMessage("Invalid Name!"); //this shows up if the name entered is not valid or is the same as name for Player2 else if([Link](Player2)) { option = askMessage("Player 1 name matches Player 2's\nDo you want to continue?", "Name Match", JOptionPane.YES_NO_OPTION); //message pop-up fo the error and if to continue game if(option == JOptionPane.YES_OPTION) //declaring of action for the yes or no option tempIsValid = true; } else if(temp != null) { tempIsValid = true; } if(tempIsValid) { //this will command if player1 name is valid then will continue to player2 name Player1 = temp; tempIsValid = false; } temp = getInput("Enter player 2 name:", Player2); if(temp == null) {/*Do Nothing*/} else if([Link]("")) showMessage("Invalid Name!"); //same as well; if name for player2 is not valid or same as player1 name then this will appear else if([Link](Player1)) { option = askMessage("Player 2 name matches Player 1's\nDo you want to continue?", "Name Match", JOptionPane.YES_NO_OPTION);
//message pop-up if name for player 2 matches with player1 and will be given option to change if(option == JOptionPane.YES_OPTION) tempIsValid = true; } else if(temp != null) { tempIsValid = true; } if(tempIsValid) { //if name is valid and will continue Player2 = temp; tempPlayer2 = temp; tempIsValid = false; } } public void setDefaultLayout() { [Link](new GridLayout(2, 1, 2, 5)); [Link](new FlowLayout([Link])); [Link](new FlowLayout([Link])); } public void checkWinStatus() { [Link](Player1 + ": " + player1Won + " | " + Player2 + ": " + player2Won); //how scoring will apear on bottom panel [Link]([Link]); } public int askMessage(String msg, String tle, int op) { return [Link](null, msg, tle, op); //joptionpane function for confirming message pop-up } public String getInput(String msg, String setText) { return [Link](null, msg, setText); //joptionpane function for input message pop-up } public void showMessage(String msg) { [Link](null, msg); //joptionpane function for message pop-up to show } public void clearPanelSouth() { //Removes all the possible panels //that pnlMain, pnlTop, pnlBottom //could have. [Link](lblTitle); [Link](mbTop); [Link](mbBottom); [Link](mbNewGame); [Link](txtMessage); [Link](mbPlayingField); [Link](lblTurn); [Link](mbQuitNTryAgain); } public void actionPerformed(ActionEvent click) { //declares action that will appear once click button or panel for the playing field Object source = [Link](); for(int i=1; i<=9; i++) { if(source == caEmpty[i] && turn < 10) { if(!(turn % 2 == 0)) caEmpty[i].setText("X"); //if player1 turn then this is the command for the 'x' character to show as pressed else caEmpty[i].setText("O"); //if player2 turn then this is the command for the 'o' character to show as pressed caEmpty[i].setEnabled(false);
[Link](); turn++; checkWin(); if(CPUGame && win == true) AI(); } } if(source == maNewGame || source == maInstruction || source == maAbout) { //declaring of action for the menu tab clearPanelSouth(); setDefaultLayout(); if(source == maNewGame) {//NewGame [Link](mbNewGame); } else if(source == maInstruction || source == maAbout) { if(source == maInstruction) {// Instructions that would appear message = "Instructions:\n\n" + "Your goal is to be the first player to get 3 X's or O's in a\n" + "row. (horizontally, diagonally, or vertically)\n" + Player1 + ": X\n" + Player2 + ": O\n"; } else {//About message = "About:\n\n" + "Title: Tic-Tac-Toe\n" + "Creator: Blmaster\n" + "Version: " + VERSION + "\n"; message = "About:\n\n" + "Title: Tic-Tac-Toe\n" + "Creator: GROUP 2\n" + "Version: Tic-Tac-toe 3.0 \n"; } [Link](message); [Link](txtMessage); } [Link](mbTop); } else if(source == ca || source == caCPU) { if(inGame) { option = askMessage("If you start a new game," + //this option will appear when you will start a new game and not continue your old game "your current game will be lost..." + "\n" + "Are you sure you want to continue?", "Quit Game?" ,JOptionPane.YES_NO_OPTION //option of yes or no will appear on message pop-up ); if(option == JOptionPane.YES_OPTION) inGame = false; } if(!inGame) { [Link](true); if(source == ca) {// 1 v 1 Game Player2 = tempPlayer2; player1Won = 0; player2Won = 0; [Link]("1 v 1"); //text that would appear on the menu tab CPUGame = false; newGame(); } else {// 1 v CPU Game Player2 = "Computer"; player1Won = 0; player2Won = 0; [Link]("1 v CPU");
CPUGame = true; newGame(); } } } else if(source == caContinue) { checkTurn(); showGame(); } else if(source == caSetName) { askUserForPlayerNames(); } else if(source == maExit) { option = askMessage("Are you sure you want to exit?", "Exit Game", JOptionPane.YES_NO_OPTION); //message pop-up if will be exiting game if(option == JOptionPane.YES_OPTION) [Link](0); } else if(source == caTryAgain) { newGame(); [Link](false); } else if(source == caQuit) { quit(); } [Link](false); [Link](true); } //-------------------END OF ACTION PERFORMED METHOD-------------------------// } /* LAYOUT OF THE GAME: THE WINDOW: (mbMenu/mbMain) mbMenu: (THE MENU) mbMain: (mbTop/mbBottom) mbTop: (mbPlayingField/INSTRUCTIONS/ABOUT/NEW GAME) mbBottom:(STATUS BAR/BACK BUTTON) */
------------------------------------------(7) POCKETCALCU ------------------------------------------package javaapplication2; import [Link].*; import [Link]; public class PocketCalc extends Applet { TextField txtDisp; public final int OP_NONE = 0; public final int OP_ADD = 1; public final int OP_SUB = 2; public final int OP_MUL = 3;
public final int OP_DIV = 4; public final int OP_NEG = 5; public final int OP_SQRT = 6; public final int OP_EQ = 7; public final int OP_C = 8; public final int OP_AC = 9; public final int DECSEP = -1; String msDecimal; int mnOp = OP_NONE; boolean mbNewNumber = true; boolean mbDecimal = false; double mdReg = 0.0; public void init() { CalcButton btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9; CalcButton btnDecSep, btnNeg, btnSqrt, btnPlus, btnMinus; CalcButton btnTimes, btnDiv, btnEqual, btnClear, btnAllClear; setLayout(null); setFont(new Font("Century Gothic", [Link], 13)); setBackground(new Color(0xFF, 0x00, 0xFF)); btn0 = new CalcButton("0", OP_NONE, 0); add(btn0); [Link](64, 144, 96, 24); btn1 = new CalcButton("1", OP_NONE, 1); add(btn1); [Link](64, 112, 40, 24); btn2 = new CalcButton("2", OP_NONE, 2); add(btn2); [Link](120, 112, 40, 24); btn3 = new CalcButton("3", OP_NONE, 3); add(btn3); [Link](176, 112, 40, 24); btn4 = new CalcButton("4", OP_NONE, 4); add(btn4); [Link](64, 80, 40, 24); btn5 = new CalcButton("5", OP_NONE, 5); add(btn5);
[Link](120, 80, 40, 24); btn6 = new CalcButton("6", OP_NONE, 6); add(btn6); [Link](176, 80, 40, 24); btn7 = new CalcButton("7", OP_NONE, 7); add(btn7); [Link](64, 48, 40, 24); btn8 = new CalcButton("8", OP_NONE, 8); add(btn8); [Link](120, 48, 40, 24); btn9 = new CalcButton("9", OP_NONE, 9); add(btn9); [Link](176, 48, 40, 24); btnDecSep = new CalcButton("", OP_NONE, DECSEP); add(btnDecSep); [Link](176, 144, 40, 24); btnNeg = new CalcButton("+/-", OP_NEG, 0); add(btnNeg); [Link](8, 48, 40, 24); btnSqrt = new CalcButton("Sqrt", OP_SQRT, 0); add(btnSqrt); [Link](8, 80, 40, 24); btnPlus = new CalcButton("+", OP_ADD, 0); add(btnPlus); [Link](232, 112, 40, 56); btnMinus = new CalcButton("-", OP_SUB, 0); add(btnMinus); [Link](288, 112, 40, 24); btnTimes = new CalcButton("", OP_MUL, 0); add(btnTimes); [Link](232, 80, 40, 24); btnDiv = new CalcButton("", OP_DIV, 0); add(btnDiv); [Link](288, 80, 40, 24);
btnEqual = new CalcButton("=", OP_EQ, 0); add(btnEqual); [Link](288, 144, 40, 24); btnClear = new CalcButton("C", OP_C, 0); add(btnClear); [Link](8, 112, 40, 24); btnAllClear = new CalcButton("AC", OP_AC, 0); add(btnAllClear); [Link](8, 144, 40, 24); txtDisp = new TextField("0", 80); [Link](false); add(txtDisp); [Link](64, 8, 268, 27); String sOneTenth = (new Double(0.1)).toString(); msDecimal = [Link]([Link]()-2).substring(0, 1); } public static void main(String args[]) { Frame frm = new Frame("Tamira's Calculator"); PocketCalc ex1 = new PocketCalc(); [Link](); [Link]("Center", ex1); [Link](); [Link](350, 210); [Link](); } public void append(int nValue) { String sDigit; if(nValue == DECSEP) if(!mbDecimal) { if(mbNewNumber) { [Link]("0"); mbNewNumber = false; } mbDecimal = true; sDigit = msDecimal; }
else return; else sDigit = (new Integer(nValue)).toString(); if(mbNewNumber) { [Link](sDigit); mbNewNumber = false; } else [Link]([Link]() + sDigit); repaint(); } public void doOp(int nNewOp) { double dDisp; dDisp = (new Double([Link]())).doubleValue(); switch(nNewOp) { case OP_NEG: case OP_SQRT: case OP_C: case OP_AC: switch(nNewOp) { case OP_NEG: [Link]((new Double(-dDisp)).toString()); break; case OP_SQRT: [Link]((new Double([Link](dDisp))).toString()); mbNewNumber = true; mbDecimal = false; break; case OP_C: mbNewNumber = true; mbDecimal = false; [Link]("0"); break; case OP_AC: mnOp = OP_NONE; mbNewNumber = true; mbDecimal = false; mdReg = 0.0; [Link]("0");
break; } break; case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_EQ: switch(mnOp) { case OP_ADD: mdReg = mdReg + dDisp; break; case OP_SUB: mdReg = mdReg - dDisp; break; case OP_MUL: mdReg = mdReg * dDisp; break; case OP_DIV: mdReg = mdReg / dDisp; break; case OP_EQ: case OP_NONE: mdReg = dDisp; break; } mnOp = nNewOp; mbNewNumber = true; mbDecimal = false; [Link]((new Double(mdReg)).toString()); break; } } } class CalcButton extends Button { int mnOp; int mnValue; CalcButton(String sText, int nOp, int nValue) { super(sText); mnOp = nOp; mnValue = nValue;
} public boolean action(Event evt, Object arg) { PocketCalc par = (PocketCalc)getParent(); if(mnOp == par.OP_NONE) [Link](mnValue); else { [Link](mnOp); } return true; } }
----------------------------------------(8) GAME ----------------------------------------A. MAIN FINALE APPLET import [Link].*; import [Link].*; import [Link].*; import [Link].*;
public class Main extends Applet implements Runnable { // sa image Image img; MediaTracker tr; // Declaration of the variable private int speed; // Thread
boolean isStoped = true; // Deklaration der Objektreferenzen private Player player; // Refference for the object private Ball redball; // Refference for the red ball private Ball blueball; // Refference for the blue ball
// Thread Thread th; // Audioclip inatach nmin sa classes AudioClip shotnoise; // eto ung initialization sa tunog ng gun AudioClip hitnoise; // eto ung initialization sa tunog ng miss AudioClip outnoise; // eto ung initialization sa tunog ng error Font f = new Font ("Serif", [Link], 20); Cursor c; // Variable sa double buffering private Image dbImage; private Graphics dbg; // Init - Method public void init () { c = new Cursor (Cursor.CROSSHAIR_CURSOR); [Link] (c); Color superblue = new Color (0, 0, 255); // sets the backgound color pero ayaw nming gmitin to.. peace^^V img=getImage(getCodeBase(),"[Link]"); //font setFont (f); // Speeds the ball in the best limit hnggang 15 lng if (getParameter ("speed") != null) { speed = [Link](getParameter("speed")); } else speed = 15; // di2 nkapaloob ung source kung saan nmin inaste ang audioclip na mula sa classes hitnoise = getAudioClip (getCodeBase() , "[Link]"); // Variable for the Cursor
[Link](); [Link](); shotnoise = getAudioClip (getCodeBase() , "[Link]"); [Link](); [Link](); outnoise = getAudioClip (getCodeBase() , "[Link]"); [Link](); [Link](); // Initializing the object player = new Player (); redball = new Ball (10, 190, 250, 1, -1, 4, [Link], outnoise, player); blueball = new Ball (10, 190, 150, 1, 1, 3, [Link], outnoise, player); } // Start - Method public void start () { //Threads th = new Thread (this); [Link] (); } // Stop - Method magsstop ang applet di2 public void stop () { [Link](); } // pra sa mouse event public boolean mouseDown (Event e, int x, int y) { if (!isStoped) { // Test kung mahihit ang ball if ([Link] (x, y)) { // kapg nahit ang red ball tu2nog ito mula sa source na ipinaste nmin sa classes [Link](); [Link] (); }
// kapg nahit ang blue ball tu2nog ito mula sa source na ipinaste nmin sa classes if ([Link] (x, y)) { // di2 tutunog [Link](); //di2 rin tutunog kpg na hit ang bola [Link] (); } else { [Link](); } } else if (isStoped && [Link] == 2) { isStoped = false; init (); } return true; } // Implementing the Run method public void run () { // implementing the thread [Link]().setPriority(Thread.MIN_PRIORITY); while (true) { if ([Link]() >= 0 && !isStoped) { [Link](); [Link](); } repaint(); try {
// Stops the Threads for milliseconds [Link] (speed); } catch (InterruptedException ex) { // do nothing } // This is for the ThreadPriority for maximum priority [Link]().setPriority(Thread.MAX_PRIORITY); } } // Paint - Method public void paint (Graphics g) { // pra sa backgound tr=new MediaTracker(this); img=getImage(getCodeBase(),"[Link]"); [Link](img,0); [Link](img,0,0,this); if ([Link]() >= 0) { // Sets the color [Link] ([Link]); // di2 ung location ng score at lives sa taas na bahagi [Link] ("Score: " + [Link](), 10, 40); [Link] ("Lives: " + [Link](), 300, 40); [Link](g); [Link](g); if (isStoped) { [Link] ([Link]); [Link] ("Doubleclick on Applet to start Game!", 40, 200); } } else if ([Link]() < 0) {
[Link] ([Link]); // location kung saan ilalagay ung drawstring kpg na gameover na [Link] ("Game over!", 130, 100); [Link] ("You scored " + [Link]() + " Points!", 90, 140); if ([Link]() < 300) [Link] ("Galingan mo pa!", 100, 190); else if ([Link]() < 600 && [Link]() >= 300) [Link] ("Hindi na masama..:D", 100, 190); else if ([Link]() < 900 && [Link]() >= 600) [Link] ("Hmmmm.. Pwede na..:D", 100, 190); else if ([Link]() < 1200 && [Link]() >= 900) [Link] ("Galing mo!!", 90, 190); else if ([Link]() < 1500 && [Link]() >= 1200) [Link] ("Whoah!! Idol.. hahaha!", 90, 190); else if ([Link]() >= 1500) [Link] ("Yesssss!! Panalo..!!",100, 190); [Link] ("Doubleclick on the Applet, to play again!", 20, 220); isStoped = true; } } // Update - Method public void update (Graphics g) { // Initializing the DoubleBuffers if (dbImage == null) { dbImage = createImage ([Link]().width, [Link]().height); dbg = [Link] (); } [Link] (getBackground ()); [Link] (0, 0, [Link]().width, [Link]().height); [Link] (getForeground()); paint (dbg); // Stopped the variable
[Link] (dbImage, 0, 0, this); } } B. CLASS HTML <html> <body background="[Link] <h1><u><div align="center">Shot the ball!</div></u></h1> </p> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3> <p align = center> <APPLET codebase="classes" code="[Link]" width=380 height=380></APPLET> </p> <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT> <param name = "speed" value = 15> </body> </html> C. BALL FINALE APPLET import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class Ball { //di2 nakaploob ang funtion ng bola na kung saan di2 nklahad ung itsura at position ng dlwang bola sa applet private int pos_x; private int pos_y; private int x_speed; // Variable for die X // Variable for die Y
private int y_speed; private int radius; private int first_x; private int first_y; private int maxspeed; // Declaration of the constant (kung ilalagay sa html 380 x 380 ang size) private final int x_leftout = 10; private final int x_rightout = 370; private final int y_upout = 45; private final int y_downout = 370; Color color; // AudioClip out AudioClip out; // Refference in the player object Player player; // Randomize the flow of the objcet which is the ball ^^ Random rnd = new Random (); //initialization public Ball (int radius, int x, int y, int vx, int vy, int ms, Color color, AudioClip out, Player player) { // Initializing the variable [Link] = radius; pos_x = x; pos_y = y; first_x = x; first_y = y; x_speed = vx; y_speed = vy; maxspeed = ms; [Link] = color; // Start x - Position // Start y - Position
[Link] = out; [Link] = player; } // Move - Method pra sa bola public void move () { pos_x += x_speed; pos_y += y_speed; isOut(); } public void ballWasHit () { // Position ng bola pos_x = first_x; pos_y = first_y; x_speed = ([Link] ()) % maxspeed; } public boolean userHit (int maus_x, int maus_y) { double x = maus_x - pos_x; double y = maus_y - pos_y; // for the distance double distance = [Link] ((x*x) + (y*y)); if (distance < 15) { [Link] (10*[Link](x_speed) + 10); return true; } else return false; } private boolean isOut ()
{ // Ball im Linken Aus if (pos_x < x_leftout) { // Sets x - Position pos_x = first_x; pos_y = first_y; // Audioclips [Link](); x_speed = ([Link] ()) % maxspeed; [Link](); return true; } else if (pos_x > x_rightout) { // Sets der x - Position pos_x = first_x; pos_y = first_y; //Audioclips [Link](); x_speed = ([Link] ()) % maxspeed; [Link](); return true; } else if (pos_y < y_upout) { // Sets the x - Position pos_x = first_x; pos_y = first_y;
// Audioclips [Link](); x_speed = ([Link] ()) % maxspeed; [Link](); return true; } else if (pos_y > y_downout) { // Sets x - Position pos_x = first_x; pos_y = first_y; // Audioclips [Link](); x_speed = ([Link] ()) % maxspeed; [Link](); return true; } else return false; } public void DrawBall (Graphics g) { [Link] (color); [Link] (pos_x - radius, pos_y - radius, 2 * radius, 2 * radius); } } ------------------------------------------(9) GRADING SYSTEM -------------------------------------------
Graphics graphics;
int txt;;
");
Label prelimq1Label = new Label("Prelim Quiz 1: ",[Link]); TextField prelimq1Field = new TextField(10);
Label prelimq2Label = new Label("Prelim Quiz 2: ",[Link]); TextField prelimq2Field = new TextField(10);
",[Link]);
",[Link]);
//-----------------lines breaks-------------------------------Label ln1 = new Label("______________________________________",[Link]); Label ln2 = new Label("______________________________________",[Link]); Label ln3 = new Label("______________________________________",[Link]); Label ln4 = new Label("______________________________________",[Link]); Label ln5 = new Label("______________________________________",[Link]);
//-------------------------midterm--------------------
Label midtermq1Label = new Label("Midterm Quiz 1: ",[Link]); TextField midtermq1Field = new TextField(10);
",[Link]);
",[Link]);
Exam: ",[Link]);
//----------------------finals-----------------
Label finalq1Label = new Label("Final Quiz 1: ",[Link]); TextField finalq1Field = new TextField(10);
Label finalq2Label = new Label("Final Quiz 2: ",[Link]); TextField finalq2Field = new TextField(10);
",[Link]);
",[Link]);
Button computeButton = new Button(" Compute "); Button clearButton = new Button(" Clear ");
",[Link]);
Label midtermgLabel = new Label("Midterm Grade: ",[Link]); TextField midtermgField = new TextField(10);
",[Link]);
Label gradeLabel = new Label("Total Grade: ",[Link]); TextField gradeField = new TextField(10);
Label statusLabel = new Label("Status: ",[Link]); TextField statusField = new TextField("enter the data",20);
add(ln1);
add(ln3);
add(gradeField); [Link]([Link]);
} // end init
//declare object strings String strprelimq1 = new String([Link]()); String strprelimq2 = new String([Link]()); String strprelimcs = new String([Link]()); String strprelimex = new String([Link]());
String strmidtermq1 = new String([Link]()); String strmidtermq2 = new String([Link]()); String strmidtermcs = new String([Link]()); String strmidtermex = new String([Link]());
String strfinalq1 = new String([Link]()); String strfinalq2 = new String([Link]()); String strfinalcs = new String([Link]()); String strfinalex = new String([Link]());
if ([Link]()==computeButton)
} if ([Link]("")) { [Link]("0"); }
//---------------midterm------------------------
// Converting input to values int prelimq1 = [Link]([Link]()); int prelimq2 = [Link]([Link]()); int prelimcs = [Link]([Link]()); int prelimex = [Link]([Link]());
int midtermq1 = [Link]( [Link]()); int midtermq2 = [Link]( [Link]()); int midtermcs = [Link]( [Link]()); int midtermex = [Link]( [Link]());
int finalq1 = [Link]([Link]()); int finalq2 = [Link]([Link]()); int finalcs = [Link]([Link]()); int finalex = [Link]([Link]());
// Calculations
double grade = (prelimg * 0.3) + (midtermg * 0.3) + (finalg * 0.4); // Output grade [Link]("" + [Link](prelimg)); [Link]("" + [Link](midtermg)); [Link]("" + [Link](finalg));
[Link]("" + [Link](grade));
} // end if computeButton
if ([Link]()==clearButton) { [Link]("");
} // end class