=1&&q<=789)
122 | f=0;
123 | if(q>=790&&q<=2249)
124 | f=1;
125 | if(q>=2250&&q<=3709)
126 | f=2;
127 | if(q>=3710&&q<=5169)
128 | f=3;
129 | if(q>=5170&&q<=6629)
130 | f=4;
131 | if(q>=6630&&q<=8089)
132 | f=5;
133 | if(q>=8090&&q<=9549)
134 | f=6;
135 | if(q>=9550&&q<=11009)
136 | f=7;
137 | if(q>=11010&&q<=12469)
138 | f=8;
139 | if(q>=12470&&q<=13929)
140 | f=9;
141 | if(q>=13930&&q<=15389)
142 | f=10;
143 | if(q>=15390&&q<=16849)
144 | f=11;
145 | if(q>=16850&&q<=18309)
146 | f=12;
147 | if(q>=18310&&q<=19769)
148 | f=13;
149 | if(q>=19770&&q<=21229)
150 | f=14;
151 | if(q>=21230&&q<=22689)
152 | f=15;
153 | if(q>=22670&&q<=24149)
154 | f=16;
155 | if(q>=24150&&q<=25609)
156 | f=17;
157 | if(q>=25610&&q<=27069)
158 | f=18;
159 | if(q>=27070&&q<=28529)
160 | f=19;
161 | if(q>=28530&&q<=29989)
162 | f=20;
163 | if(q>=29990&&q<=31449)
164 | f=21;
165 | if(q>=31450&&q<=32909)
166 | f=22;
167 | if(q>=32910&&q<=34369)
168 | f=23;
169 | q=q+f;
170 | r=r+f;
171 | if(q%7-1==0)
172 | p=q;
173 | if(q%7-2==0)
174 | p=q-1;
175 | if(q%7-3==0)
176 | p=q-2;
177 | if(q%7-4==0)
178 | p=q-3;
179 | if(q%7-5==0)
180 | p=q-4;
181 | if(q%7-6==0)
182 | p=q-5;
183 | if(q%7==0)
184 | p=q-6;
185 | Font fobj1=new Font("Jokerman",Font.BOLD,18);
186 | g.setFont(fobj1);
187 | g.drawString("MON TUE WED THRU FRI SAT SUN",155,80);
188 | g.drawString("MONTH",10,120);
189 | g.drawString("YEAR",10,230);
190 | for(i=1;i<=6;i++)
191 | { for(j=1;j<=7;j++)
192 | { if(m==1)
193 | { if(0
6 | */
7 | public class Car_Game extends Applet implements KeyListener,MouseListener
8 | { int x=225,y=250,x1,y1,u=180,v=100,p=225,q=150,a=0,z=0,b,k,e=180,f=250,i=225,h=295,flag=0;
9 | int m1[]=new int[4];
10 | int m2[]=new int[4];
11 | public void init()
12 | { addMouseListener(this);
13 | addKeyListener(this);
14 | requestFocus();
15 | m1[0]=205;
16 | m2[0]=80;
17 | m1[1]=205;
18 | m2[1]=135;
19 | m1[2]=205;
20 | m2[2]=200;
21 | m1[3]=205;
22 | m2[3]=265;
23 | }
24 | public void mouseClicked(MouseEvent me)
25 | {}
26 | public void mouseEntered(MouseEvent me)
27 | {}
28 | public void mouseExited(MouseEvent me)
29 | {}
30 | public void mousePressed(MouseEvent me)
31 | { x1=me.getX();
32 | y1=me.getY();
33 | repaint();
34 | }
35 | public void mouseReleased(MouseEvent me)
36 | {}
37 | public void keyPressed(KeyEvent ke)
38 | { k=ke.getKeyCode();
39 | if(k==37&&z==5)
40 | a=-5;
41 | if(k==39&&z==5)
42 | a=+5;
43 | if(k==38)
44 | { b=5;
45 | z=5;
46 | }
47 | repaint();
48 | }
49 | public void keyReleased(KeyEvent ke)
50 | {}
51 | public void keyTyped(KeyEvent ke)
52 | {}
53 | public void paint(Graphics g)
54 | { try
55 | { Font fobj=new Font("Arial",Font.BOLD,14);
56 | g.setColor(Color.LIGHT_GRAY);
57 | g.fillRect(175,45,60,260);
58 | g.setColor(Color.white);
59 | g.fillRect(m1[0],m2[0],5,20);
60 | g.fillRect(m1[1],m2[1],5,20);
61 | g.fillRect(m1[2],m2[2],5,20);
62 | g.fillRect(m1[3],m2[3],5,20);
63 | if(flag==0)
64 | { Color c1=new Color(10,240,10);
65 | Color c2=new Color(240,10,10);
66 | Color c3=new Color(10,10,240);
67 | setBackground(Color.white);
68 | g.setFont(fobj);
69 | g.setColor(Color.ORANGE);
70 | g.drawString("CAR GAME",170,20);
71 | if(x==180&&k==39)
72 | x=x+a;
73 | if(x==225&&k==37)
74 | x=x+a;
75 | g.setColor(c1);
76 | g.fillRect(x,y,5,5);
77 | g.setColor(c2);
78 | g.fillRect(u,v,5,5);
79 | g.fillRect(p,q,5,5);
80 | g.fillRect(e,f,5,5);
81 | g.fillRect(i,h,5,5);
82 | g.setColor(c3);
83 | g.drawLine(170,45,170,305);
84 | g.drawLine(240,45,240,305);
85 | g.drawLine(175,45,175,305);
86 | g.drawLine(235,45,235,305);
87 | Thread.sleep(80);
88 | if(x>181&&x<221)
89 | { x=x+a;
90 | repaint();
91 | }
92 | v=v+b;
93 | q=q+b;
94 | f=f+b;
95 | h=h+b;
96 | m2[0]=m2[0]+z;
97 | m2[1]=m2[1]+z;
98 | m2[2]=m2[2]+z;
99 | m2[3]=m2[3]+z;
100 | repaint();
101 | if(q==300)
102 | { q=50;
103 | repaint();
104 | }
105 | if(v==300)
106 | { v=50;
107 | repaint();
108 | }
109 | if(f==300)
110 | { f=50;
111 | repaint();
112 | }
113 | if(h==300)
114 | { h=50;
115 | repaint();
116 | }
117 | if(m2[0]==300)
118 | { m2[0]=50;
119 | repaint();
120 | }
121 | if(m2[1]==300)
122 | { m2[1]=50;
123 | repaint();
124 | }
125 | if(m2[2]==300)
126 | { m2[2]=50;
127 | repaint();
128 | }
129 | if(m2[3]==300)
130 | { m2[3]=50;
131 | repaint();
132 | }
133 | if(x==180&&y==250&&u==180&&v==250)
134 | { flag=1;
135 | x1=10;
136 | y1=10;
137 | repaint();
138 | }
139 | else if(x==225&&y==250&&p==225&&q==250)
140 | { flag=1;
141 | x1=10;
142 | y1=10;
143 | repaint();
144 | }
145 | else if(x==180&&y==250&&e==180&&f==250)
146 | { flag=1;
147 | x1=10;
148 | y1=10;
149 | repaint();
150 | }
151 | else if(x==225&&y==250&&i==225&&h==250)
152 | { flag=1;
153 | x1=10;
154 | y1=10;
155 | repaint();
156 | }
157 | }
158 | else if(flag==1)
159 | { Color c11=new Color(10,240,10);
160 | Color c21=new Color(240,10,10);
161 | Color c31=new Color(10,10,240);
162 | setBackground(Color.white);
163 | g.setFont(fobj);
164 | g.setColor(Color.ORANGE);
165 | g.drawString("CAR GAME",170,20);
166 | g.setColor(c11);
167 | g.fillRect(x,y+5,5,5);
168 | g.setColor(c21);
169 | g.fillRect(u,v,5,5);
170 | g.fillRect(p,q,5,5);
171 | g.fillRect(e,f,5,5);
172 | g.fillRect(i,h,5,5);
173 | g.setColor(c31);
174 | g.drawLine(170,45,170,305);
175 | g.drawLine(240,45,240,305);
176 | g.drawLine(175,45,175,305);
177 | g.drawLine(235,45,235,305);
178 | g.setFont(fobj);
179 | g.drawString("GAME OVER",65,150);
180 | g.drawString("CLICK ON BOX",65,170);
181 | g.drawString("FOR RELOAD",65,190);
182 | g.setColor(Color.MAGENTA);
183 | g.fillRect(80,200,20,20);
184 | g.setColor(Color.WHITE);
185 | g.drawArc(85,205,10,10,90,270);
186 | g.drawLine(83,205,89,205);
187 | g.drawLine(89,205,89,212);
188 | if(x1>=80&&x1<=100&&y1>=200&&y1<=220)
189 | { flag=0;
190 | x=225;
191 | y=250;
192 | u=180;
193 | v=100;
194 | p=225;
195 | q=150;
196 | a=0;
197 | b=0;
198 | k=40;
199 | e=180;
200 | f=250;
201 | i=225;
202 | h=295;
203 | z=0;
204 | repaint();
205 | }
206 | else
207 | flag=1;
208 | }
209 | setSize(400,350);
210 | }
211 | catch(Exception e)
212 | {}
213 | }
214 | }
215 |
216 |
217 |
--------------------------------------------------------------------------------
/Color_Changer.java:
--------------------------------------------------------------------------------
1 | //Color Changer
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | /*
7 | */
8 | public class Color_Changer extends Applet implements AdjustmentListener
9 | { Scrollbar hsb1,hsb2,hsb3;
10 | int v1,v2,v3;
11 | public void init()
12 | { setLayout(null);
13 | hsb1=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
14 | hsb2=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
15 | hsb3=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
16 | add(hsb1);add(hsb2);add(hsb3);
17 | hsb1.addAdjustmentListener(this);
18 | hsb2.addAdjustmentListener(this);
19 | hsb3.addAdjustmentListener(this);
20 | hsb1.setBounds(10,30,800,30);
21 | hsb2.setBounds(10,90,800,30);
22 | hsb3.setBounds(10,150,800,30);
23 | }
24 | public void adjustmentValueChanged(AdjustmentEvent ae)
25 | { repaint();
26 | }
27 | public void paint(Graphics g)
28 | { setSize(830,400);
29 | g.drawString("Red Color",10,20);
30 | g.drawString("Green Color",10,80);
31 | g.drawString("Blue Color",10,140);
32 | g.drawString("Color Output",10,205);
33 | v1=hsb1.getValue();
34 | v2=hsb2.getValue();
35 | v3=hsb3.getValue();
36 | Color c=new Color(v1,v2,v3);
37 | g.setColor(c);
38 | g.fillRect(10,220,800,150);
39 | showStatus("RED COLOR="+v1+" GREEN COLOR="+v2+" BLUE COLOR="+v3);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Color_Picker.java:
--------------------------------------------------------------------------------
1 | //Color Picker
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | /*
7 | */
8 | public class Color_Picker extends Applet implements MouseListener
9 | { int i,j,k,z=0,y=0,x=0,a,x1,y1,r1,g1,b1,r2,g2,b2,x2,y2,h;
10 | TextField red,green,blue;
11 | public void init()
12 | { addMouseListener(this);
13 | r1=0;
14 | b1=0;
15 | g1=0;
16 | red=new TextField();
17 | green=new TextField();
18 | blue=new TextField();
19 | add(red);add(green);add(blue);
20 | setLayout(null);
21 | red.setBounds(360,100,80,25);
22 | green.setBounds(360,150,80,25);
23 | blue.setBounds(360,200,80,25);
24 | }
25 | public void mouseClicked(MouseEvent me)
26 | { x1=me.getX();
27 | y1=me.getY();
28 | z=1;
29 | repaint();
30 | }
31 | public void mousePressed(MouseEvent me)
32 | {}
33 | public void mouseReleased(MouseEvent me)
34 | {}
35 | public void mouseEntered(MouseEvent me)
36 | {}
37 | public void mouseExited(MouseEvent me)
38 | {}
39 | public void paint(Graphics g)
40 | { setSize(500,450);
41 | Font f=new Font("Arial",Font.BOLD,14);
42 | g.setFont(f);
43 | g.drawString("PICK YOUR COLOR",70,25);
44 | g.drawString("RED",300,120);
45 | g.drawString("GREEN",300,170);
46 | g.drawString("BLUE",300,220);
47 | g.setColor(Color.GRAY);
48 | g.fillRect(10,40,260,380);
49 | g.setColor(Color.WHITE);
50 | g.fillRect(15,45,250,370);
51 | for(i=0;i<256;i+=51)
52 | { for(j=0;j<256;j+=51)
53 | { for(k=0;k<256;k+=51)
54 | { Color c=new Color(i,j,k);
55 | g.setColor(Color.BLACK);
56 | g.fillRect(x+22,y+52,15,15);
57 | g.setColor(c);
58 | g.fillRect(x+21,y+51,15,15);
59 | if(k==255)
60 | { if(a==1)
61 | { x=-20;
62 | y=y+20;
63 | a=-1;
64 | }
65 | a++;
66 | }
67 | x=x+20;
68 | }
69 | }
70 | }
71 | x=0;y=0;
72 | r1=0;g1=0;b1=0;
73 | x2=22;y2=52;
74 | if(z==1)
75 | { for(i=0;i<18;i++)
76 | { if(i==3||i==6||i==9||i==12||i==15)
77 | { r1=r1+51;
78 | g1=0;
79 | }
80 | for(j=0;j<12;j++)
81 | { if(x1>=x2&&x1<=x2+15&&y1>=y2&&y1<=y2+15)
82 | { r2=r1;
83 | g2=g1;
84 | b2=b1;
85 | i=18;
86 | j=12;
87 | h=1;
88 | break;
89 | }
90 | else
91 | h=0;
92 | b1=b1+51;
93 | if(j==5||j==11)
94 | { b1=0;
95 | g1=g1+51;
96 | }
97 | x2=x2+20;
98 | if(j==11)
99 | { x2=22;
100 | y2=y2+20;
101 | }
102 | }
103 | }
104 | }
105 | z=0;
106 | if(h==1)
107 | { Color c2 = new Color(r2, g2, b2);
108 | g.setColor(Color.WHITE);
109 | g.fillRect(x2,y2,15,15);
110 | g.setColor(c2);
111 | g.fillRect(x2-1,y2-1,15,15);
112 | }
113 | g.setColor(Color.BLACK);
114 | g.drawString("YOU CHOOSE",350,280);
115 | Color c1=new Color(r2,g2,b2);
116 | g.setColor(c1);
117 | g.fillRect(350,300,90,90);
118 | red.setText(""+r2);
119 | green.setText(""+g2);
120 | blue.setText(""+b2);
121 | red.setEditable(false);
122 | green.setEditable(false);
123 | blue.setEditable(false);
124 | showStatus(" RED="+r2+" GREEN="+g2+" BLUE="+b2);
125 | }
126 | }
--------------------------------------------------------------------------------
/DXBall_Game.java:
--------------------------------------------------------------------------------
1 | //DXBall Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class DXBall_Game extends JApplet implements KeyListener
9 | { int x=238,y=333,k,a1=0,b1=0,a=2,b=0,c=0,d=0,x1=203,y1=333,e=0,z=0,s,f=0;
10 | private JPanel panel;
11 | public void init()
12 | { addKeyListener(this);
13 | requestFocus();
14 | y=326;
15 | panel = new JPanel()
16 | { protected void paintComponent(Graphics g)
17 | { super.paintComponent(g);
18 | try
19 | { showStatus(" SCORE = "+s);
20 | Color cobj=new Color(10,131,231);
21 | Font fobj=new Font("Arial",Font.BOLD,20);
22 | Font fobj1=new Font("Arial",Font.BOLD,25);
23 | setBackground(cobj);
24 | if(f==1)
25 | { setBackground(cobj);
26 | g.setColor(Color.WHITE);
27 | g.setFont(fobj);
28 | g.drawString("GAME OVER",130,170);
29 | }
30 | else
31 | { g.setColor(Color.WHITE);
32 | if(z==0)
33 | { g.setFont(fobj1);
34 | g.drawString("DXBALL GAME",110,100);
35 | }
36 | g.fillOval(x,y,5,5);
37 | g.fillRoundRect(x1,y1,80,5,5,5);
38 | Thread.sleep(15);
39 | if(y==333)
40 | { if(a==0&&b==0&&c==0&&d==0&&y1==y&&x>=x1&&x<=x1+80)
41 | { a1=5;
42 | b1=-5;
43 | a=1;
44 | }
45 | else if(a==1&&b==0&&c==0&&d==0&&y1==y&&x>=x1&&x<=x1+80)
46 | { a1=-5;
47 | b1=-5;
48 | b=1;
49 | }
50 | else if(a==1&&b==1&&c==1&&d==1&&x!=403&&y1==y&&x>=x1&&x<=x1+80)
51 | { a1=5;
52 | b1=-5;
53 | b=0;
54 | c=0;
55 | d=0;
56 | }
57 | else if(a==1&&b==1&&c==1&&d==1&&x==403&&y1==y&&x>=x1&&x<=x1+80)
58 | { a1=-5;
59 | b1=-5;
60 | c=0;
61 | d=0;
62 | }
63 | else if(a==1&&b==1&&c==1&&d==0&&x==3&&y1==y&&x>=x1&&x<=x1+80)
64 | { a1=5;
65 | b1=-5;
66 | b=0;
67 | c=0;
68 | d=0;
69 | }
70 | else if(a==1&&b==1&&c==1&&d==0&&x!=3&&y1==y&&x>=x1&&x<=x1+80)
71 | { a1=-5;
72 | b1=-5;
73 | b=1;
74 | c=0;
75 | }
76 | else
77 | f=1;
78 | }
79 | else if(x==403)
80 | { if(a==1&&b==0&&c==0&&d==0)
81 | { a1=-5;
82 | b1=-5;
83 | b=1;
84 | }
85 | else if(a==1&&b==1&&c==1&&d==1)
86 | { a1=-5;
87 | b1=5;
88 | d=0;
89 | b=0;
90 | c=0;
91 | }
92 | else if(a==1&&b==0&&c==1&&d==1)
93 | { a1=-5;
94 | b1=5;
95 | d=0;
96 | c=0;
97 | }
98 | else if(a==1&&b==0&&c==0&&d==1)
99 | { a1=-5;
100 | b1=-5;
101 | d=0;
102 | }
103 | else
104 | f=1;
105 | }
106 | else if(y==3)
107 | { if(a==1&&b==1&&c==0&&d==0)
108 | { a1=-5;
109 | b1=5;
110 | c=1;
111 | }
112 | else if(a==1&&b==1&&c==0&&d==1)
113 | { a1=5;
114 | b1=5;
115 | c=1;
116 | }
117 | else if(a==1&&b==0&&c==0&&d==0)
118 | { a1=5;
119 | b1=5;
120 | c=1;
121 | d=1;
122 | }
123 | else
124 | f=1;
125 | }
126 | else if(x==3)
127 | { if(a==1&&b==1&&c==1&&d==0)
128 | { a1=5;
129 | b1=5;
130 | a=0;
131 | b=0;
132 | c=0;
133 | }
134 | else if(a==1&&b==1&&c==0&&d==0)
135 | { a1=5;
136 | b1=-5;
137 | d=1;
138 | }
139 | else if(a==1&&b==0&&c==1&&d==0)
140 | { a1=-5;
141 | b1=5;
142 | b=1;
143 | d=1;
144 | }
145 | else
146 | f=1;
147 | }
148 | if(z>0)
149 | s++;
150 | x=x+a1;
151 | y=y+b1;
152 | if(x1==3&&k==39)
153 | x1=x1+e;
154 | else if(x1==323&&k==37)
155 | x1=x1+e;
156 | else if(x1>3&&x1<323)
157 | { x1=x1+e;
158 | repaint();
159 | }
160 | repaint();
161 | }
162 | }
163 | catch(Exception e)
164 | {}
165 | }
166 | };
167 | add(panel);
168 | }
169 | public void keyPressed(KeyEvent ke)
170 | { k=ke.getKeyCode();
171 | if(k==38)
172 | { if(z==0)
173 | { a=0;
174 | z++;
175 | y=333;
176 | }
177 | }
178 | if(k==37)
179 | { if(z==0)
180 | { a=0;
181 | z++;
182 | e=-5;
183 | y=333;
184 | }
185 | else
186 | e=-5;
187 | }
188 | if(k==39)
189 | { if(z==0)
190 | { a=0;
191 | z++;
192 | e=-5;
193 | y=333;
194 | }
195 | else
196 | e=5;
197 | }
198 | repaint();
199 | }
200 | public void keyReleased(KeyEvent ke)
201 | {}
202 | public void keyTyped(KeyEvent ke)
203 | {}
204 | public void paint(Graphics g)
205 | { setSize(410,350);
206 | super.paint(g);
207 | }
208 | }
209 |
210 |
--------------------------------------------------------------------------------
/Dashing_Ball.java:
--------------------------------------------------------------------------------
1 | //Dashing Ball
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Dashing_Ball extends JApplet implements KeyListener
9 | { int k,l=0,l1,l2,z=0,s=0;
10 | int x[]=new int[6];
11 | int y[]=new int[6];
12 | int a[]=new int[6];
13 | int b[]=new int[6];
14 | int c[]=new int[6];
15 | int d[]=new int[6];
16 | int e[]=new int[6];
17 | int f[]=new int[6];
18 | private JPanel panel;
19 | public void init()
20 | { addKeyListener(this);
21 | requestFocus();
22 | l1=280;
23 | l2=340;
24 | x[0]=200;
25 | y[0]=480;
26 | x[1]=280;
27 | y[1]=360;
28 | e[1]=5;
29 | f[1]=5;
30 | x[2]=70;
31 | y[2]=390;
32 | e[2]=-5;
33 | f[2]=5;
34 | x[3]=80;
35 | y[3]=360;
36 | e[3]=5;
37 | f[3]=-5;
38 | x[4]=710;
39 | y[4]=170;
40 | e[4]=-5;
41 | f[4]=5;
42 | x[5]=170;
43 | y[5]=290;
44 | e[5]=5;
45 | f[5]=5;
46 | panel = new JPanel()
47 | { protected void paintComponent(Graphics g)
48 | { super.paintComponent(g);
49 | try
50 | { if(s==0)
51 | repaint();
52 | Thread.sleep(10);
53 | if(z==1)
54 | { l1=l1+l;
55 | l2=l2+l;
56 | z=0;
57 | }
58 | if(l2<=0)
59 | { l1=-60;
60 | l2=0;
61 | }
62 | else if(l1>=500)
63 | { l1=500;
64 | l2=560;
65 | }
66 | setBackground(Color.BLACK);
67 | g.setColor(Color.white);
68 | g.fillRect(400,0,10,l1);
69 | g.fillRect(400,l2,10,500);
70 | g.setColor(Color.red);
71 | g.drawString("RED BALL",180,20);
72 | g.fillOval(x[0],y[0],20,20);
73 | g.setColor(Color.red);
74 | g.fillOval(x[1],y[1],20,20);
75 | g.setColor(Color.red);
76 | g.fillOval(x[2],y[2],20,20);
77 | g.setColor(Color.CYAN);
78 | g.drawString("BLUE BALL",560,20);
79 | g.fillOval(x[3],y[3],20,20);
80 | g.setColor(Color.cyan);
81 | g.fillOval(x[4],y[4],20,20);
82 | g.setColor(Color.cyan);
83 | g.fillOval(x[5],y[5],20,20);
84 | for(int i=0;i<=5;i++)
85 | { if(y[i]==480)
86 | { if(a[i]==0&&b[i]==0&&c[i]==0&&d[i]==0)
87 | { e[i]=5;
88 | f[i]=-5;
89 | a[i]=1;
90 | }
91 | else if(a[i]==1&&b[i]==0&&c[i]==0&&d[i]==0)
92 | { e[i]=-5;
93 | f[i]=-5;
94 | b[i]=1;
95 | }
96 | else if(a[i]==1&&b[i]==1&&c[i]==1&&d[i]==1)
97 | { e[i]=5;
98 | f[i]=-5;
99 | b[i]=0;
100 | c[i]=0;
101 | d[i]=0;
102 | }
103 | else if(a[i]==1&&b[i]==1&&c[i]==1&&d[i]==0)
104 | { e[i]=-5;
105 | f[i]=-5;
106 | c[i]=0;
107 | d[i]=0;
108 | }
109 | }
110 | else if(x[i]==380||x[i]==780)
111 | { if(a[i]==1&&b[i]==0&&c[i]==0&&d[i]==0)
112 | { e[i]=-5;
113 | f[i]=-5;
114 | b[i]=1;
115 | }
116 | else if(a[i]==1&&b[i]==1&&c[i]==1&&d[i]==1)
117 | { e[i]=-5;
118 | f[i]=5;
119 | d[i]=0;
120 | b[i]=0;
121 | c[i]=0;
122 | }
123 | else if(a[i]==0&&b[i]==0&&c[i]==0&&d[i]==0)
124 | { e[i]=-5;
125 | f[i]=5;
126 | a[i]=1;
127 | }
128 | else if(a[i]==1&&b[i]==0&&c[i]==1&&d[i]==1)
129 | { e[i]=-5;
130 | f[i]=5;
131 | d[i]=0;
132 | c[i]=0;
133 | }
134 | else if(a[i]==1&&b[i]==0&&c[i]==0&&d[i]==1)
135 | { e[i]=-5;
136 | f[i]=-5;
137 | d[i]=0;
138 | }
139 | else if(a[i]==1&&b[i]==1&&c[i]==0&&d[i]==1)
140 | { e[i]=-5;
141 | f[i]=-5;
142 | d[i]=0;
143 | }
144 | }
145 | else if(y[i]==0)
146 | { if(a[i]==1&&b[i]==1&&c[i]==0&&d[i]==0)
147 | { e[i]=-5;
148 | f[i]=5;
149 | c[i]=1;
150 | }
151 | else if(a[i]==1&&b[i]==1&&c[i]==0&&d[i]==1)
152 | { e[i]=5;
153 | f[i]=5;
154 | c[i]=1;
155 | }
156 | else if(a[i]==1&&b[i]==0&&c[i]==0&&d[i]==0)
157 | { e[i]=5;
158 | f[i]=5;
159 | c[i]=1;
160 | d[i]=1;
161 | }
162 | }
163 | else if(x[i]==0||x[i]==400)
164 | { if(a[i]==1&&b[i]==1&&c[i]==1&&d[i]==0)
165 | { e[i]=5;
166 | f[i]=5;
167 | a[i]=0;
168 | b[i]=0;
169 | c[i]=0;
170 | }
171 | else if(a[i]==1&&b[i]==1&&c[i]==0&&d[i]==0)
172 | { e[i]=5;
173 | f[i]=-5;
174 | d[i]=1;
175 | }
176 | else if(a[i]==1&&b[i]==0&&c[i]==1&&d[i]==0)
177 | { e[i]=-5;
178 | f[i]=5;
179 | b[i]=1;
180 | d[i]=1;
181 | }
182 | else if(a[i]==1&&b[i]==0&&c[i]==0&&d[i]==0)
183 | { e[i]=5;
184 | f[i]=5;
185 | a[i]=0;
186 | }
187 | }
188 | if(y[i]==5&&x[i]==5)
189 | { y[i]=10;
190 | x[i]=5;
191 | }
192 | if(y[i]==5&&x[i]==775)
193 | { y[i]=10;
194 | x[i]=775;
195 | }
196 | if(y[i]==475&&x[i]==5)
197 | { y[i]=470;
198 | x[i]=5;
199 | }
200 | if(y[i]==475&&x[i]==775)
201 | { y[i]=470;
202 | x[i]=775;
203 | }
204 | if(x[i]==405&&y[i]==475)
205 | { x[i]=405;
206 | y[i]=470;
207 | }
208 | if(x[i]==375&&y[i]==475)
209 | { x[i]=375;
210 | y[i]=470;
211 | }
212 | if(x[i]==405&&y[i]==5)
213 | { x[i]=405;
214 | y[i]=10;
215 | }
216 | if(x[i]==375&&y[i]==5)
217 | { x[i]=375;
218 | y[i]=10;
219 | }
220 | x[i]=x[i]+e[i];
221 | y[i]=y[i]+f[i];
222 | if(l1y[i]&&x[i]==380)
223 | { x[i]=x[i]+e[i];
224 | y[i]=y[i]+f[i];
225 | }
226 | else if(l1y[i]&&x[i]==400)
227 | { x[i]=x[i]+e[i];
228 | y[i]=y[i]+f[i];
229 | }
230 | }
231 | if(x[0]<390&&x[1]<390&&x[2]<390&&x[3]>390&&x[4]>390&&x[5]>390)
232 | { s=1;
233 | Thread.sleep(10000);
234 | }
235 | }
236 | catch (Exception e)
237 | {}
238 | }
239 | };
240 | add(panel);
241 | }
242 | public void keyPressed(KeyEvent ke)
243 | { k=ke.getKeyCode();
244 | if(k==38)
245 | { l=-10;
246 | z=1;
247 | }
248 | else if(k==40)
249 | { l=10;
250 | z=1;
251 | }
252 | repaint();
253 | }
254 | public void keyReleased(KeyEvent e)
255 | {}
256 | public void keyTyped(KeyEvent ke)
257 | {}
258 | public void paint(Graphics g)
259 | { super.paint(g);
260 | setSize(800, 500);
261 | }
262 |
263 | }
264 |
--------------------------------------------------------------------------------
/Day_of_the_Week.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Day_of_the_Week extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5;
6 | Button b1,b2;
7 | TextField t1,t2,t3,t4;
8 | int d1;
9 | String n1,str;
10 | public void init()
11 | { setLayout(null);
12 | l1=new Label("Week Day and its Name");
13 | l2=new Label("Day of the Week");
14 | l3=new Label("Name of the Day");
15 | l4=new Label("Name of the Day");
16 | l5=new Label("Day of the Week");
17 | b1=new Button("Find Name");
18 | b2=new Button("Find Day");
19 | t1=new TextField();
20 | t2=new TextField();
21 | t3=new TextField();
22 | t4=new TextField();
23 | add(t1);add(t2);add(t3);add(t4);
24 | add(b1);add(b2);
25 | add(l1);add(l2);add(l3);add(l4);add(l5);
26 | t3.setEditable(false);
27 | t4.setEditable(false);
28 | b1.addActionListener(this);
29 | b2.addActionListener(this);
30 | l1.setBounds(270,20,250,30);
31 | l2.setBounds(30,80,100,20);
32 | l3.setBounds(30,160,100,20);
33 | l4.setBounds(430,80,100,20);
34 | l5.setBounds(430,160,100,20);
35 | b1.setBounds(270,80,130,30);
36 | b2.setBounds(270,160,130,30);
37 | t1.setBounds(150,80,100,20);
38 | t2.setBounds(150,160,100,20);
39 | t3.setBounds(550,80,100,20);
40 | t4.setBounds(550,160,100,20);
41 | }
42 | public void actionPerformed(ActionEvent ae)
43 | { try
44 | { str=ae.getActionCommand();
45 | if(str.equals("Find Name"))
46 | { d1=Integer.parseInt(t1.getText());
47 | if(d1==1)
48 | t3.setText("Sunday");
49 | else if(d1==2)
50 | t3.setText("Monday");
51 | else if(d1==3)
52 | t3.setText("Tuesday");
53 | else if(d1==4)
54 | t3.setText("Wednesday");
55 | else if(d1==5)
56 | t3.setText("Thrusday");
57 | else if(d1==6)
58 | t3.setText("Friday");
59 | else if(d1==7)
60 | t3.setText("Saturday");
61 | else
62 | t3.setText("Wrong Input");
63 | }
64 | if(str.equals("Find Day"))
65 | { n1=t2.getText();
66 | n1=n1.toLowerCase();
67 | if(n1.equals("sunday"))
68 | t4.setText("1");
69 | else if(n1.equals("monday"))
70 | t4.setText("2");
71 | else if(n1.equals("tuesday"))
72 | t4.setText("3");
73 | else if(n1.equals("wednesday"))
74 | t4.setText("4");
75 | else if(n1.equals("thrusday"))
76 | t4.setText("5");
77 | else if(n1.equals("friday"))
78 | t4.setText("6");
79 | else if(n1.equals("saturday"))
80 | t4.setText("7");
81 | else
82 | t4.setText("Wrong Input");
83 | }
84 | }
85 | catch(Exception e)
86 | {}
87 | }
88 | public void paint(Graphics g)
89 | { setSize(700,250);
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/Design_Preview.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Design_Preview extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5,l6;
6 | Button b1;
7 | TextField t1,t2,t3,t4,t5;
8 | Checkbox c1;
9 | double q,r,p,d,np;
10 | String n1,str;
11 | public void init()
12 | { setLayout(null);
13 | l1=new Label("BILLING-SYSTEM");
14 | l2=new Label("Quantity");
15 | l3=new Label("Rate/Unit");
16 | l4=new Label("Payment");
17 | l5=new Label("Discount");
18 | l6=new Label("Net Payment");
19 | b1=new Button("Calculate Bill");
20 | t1=new TextField();
21 | t2=new TextField();
22 | t3=new TextField();
23 | t4=new TextField();
24 | t5=new TextField();
25 | c1=new Checkbox("Regular Customer");
26 | add(c1);
27 | add(t1);add(t2);add(t3);add(t4);add(t5);
28 | add(b1);
29 | add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);
30 | t3.setEditable(false);
31 | t4.setEditable(false);
32 | t5.setEditable(false);
33 | b1.addActionListener(this);
34 | l1.setBounds(230,20,250,30);
35 | l2.setBounds(30,80,100,20);
36 | l3.setBounds(30,120,100,20);
37 | l4.setBounds(30,160,100,20);
38 | l5.setBounds(30,200,100,20);
39 | l6.setBounds(30,240,100,20);
40 | b1.setBounds(340,80,100,30);
41 | t1.setBounds(150,80,100,20);
42 | t2.setBounds(150,120,100,20);
43 | t3.setBounds(150,160,100,20);
44 | t4.setBounds(150,200,100,20);
45 | t5.setBounds(150,240,100,20);
46 | c1.setBounds(340,130,130,20);
47 |
48 | }
49 | public void actionPerformed(ActionEvent ae)
50 | { try
51 | { q=Double.parseDouble(t1.getText());
52 | r=Double.parseDouble(t2.getText());
53 | p=q*r;
54 | if(c1.getState()==true)
55 | { if(p>=0&&p<400)
56 | d=p*0.02;
57 | else if(p>=400&&p<800)
58 | d=p*0.04;
59 | else if(p>=800&&p<1500)
60 | d=p*0.08;
61 | else if(p>=1500)
62 | d=p*0.1;
63 | }
64 | else
65 | d=0;
66 | np=p-d;
67 | t3.setText(""+p);
68 | t4.setText(""+d);
69 | t5.setText(""+np);
70 | }
71 | catch(Exception e)
72 | {}
73 | }
74 | public void paint(Graphics g)
75 | { setSize(500,290);
76 | }
77 | }
78 |
79 |
--------------------------------------------------------------------------------
/Digital_Clock_2.java:
--------------------------------------------------------------------------------
1 | //Digital Clock 2
2 | import java.awt.*;
3 | import java.applet.*;
4 | import java.util.*;
5 | /**/
7 | public class Digital_Clock_2 extends Applet
8 | { int a,j,temp;
9 | int t[]=new int[6];
10 | public void paint(Graphics g)
11 | { setSize(750,200);
12 | Calendar cal = new GregorianCalendar();
13 | GregorianCalendar date = new GregorianCalendar();
14 | int hour=cal.get(Calendar.HOUR);
15 | int minute =cal.get(Calendar.MINUTE);
16 | int second =cal.get(Calendar.SECOND);
17 | j=0;
18 | if(hour<10)
19 | { t[0]=0;
20 | t[1]=hour;
21 | j=2;
22 | }
23 | else
24 | { while(hour>0)
25 | { t[j]=hour%10;
26 | hour=hour/10;
27 | j++;
28 | }
29 | }
30 | if(minute<10)
31 | { t[2]=0;
32 | t[3]=minute;
33 | j=4;
34 | }
35 | else
36 | { while(minute>0)
37 | { t[j]=minute%10;
38 | minute=minute/10;
39 | j++;
40 | if(minute==0)
41 | { temp=t[2];
42 | t[2]=t[3];
43 | t[3]=temp;
44 | }
45 | }
46 | }
47 | if(second<10)
48 | { t[4]=0;
49 | t[5]=second;
50 | j=6;
51 | }
52 | else
53 | { while(second>0)
54 | { t[j]=second%10;
55 | second=second/10;
56 | j++;
57 | if(second==0)
58 | { temp=t[4];
59 | t[4]=t[5];
60 | t[5]=temp;
61 | }
62 | }
63 | }
64 | for(int i=0;i<6;i++)
65 | { if(i==0)
66 | a=0;
67 | else if(i==1)
68 | a=100;
69 | else if(i==2)
70 | a=250;
71 | else if(i==3)
72 | a=350;
73 | else if(i==4)
74 | a=500;
75 | else if(i==5)
76 | a=600;
77 | int x1[]={10+a,90+a,80+a,20+a};
78 | int y1[]={10,10,20,20};
79 | int x2[]={20+a,80+a,90+a,10+a};
80 | int y2[]={160,160,170,170};
81 | int x3[]={85+a,95+a,95+a,85+a};
82 | int y3[]={20,10,90,80};
83 | int x4[]={85+a,95+a,95+a,85+a};
84 | int y4[]={100,90,170,160};
85 | int x5[]={5+a,15+a,15+a,5+a};
86 | int y5[]={10,20,80,90};
87 | int x6[]={5+a,15+a,15+a,5+a};
88 | int y6[]={90,100,160,170};
89 | int x7[]={10+a,20+a,80+a,90+a,80+a,20+a};
90 | int y7[]={90,85,85,90,95,95};
91 | if(t[i]==0)
92 | { g.fillPolygon(x1,y1,4);
93 | g.fillPolygon(x2,y2,4);
94 | g.fillPolygon(x3,y3,4);
95 | g.fillPolygon(x4,y4,4);
96 | g.fillPolygon(x5,y5,4);
97 | g.fillPolygon(x6,y6,4);
98 | }
99 | else if(t[i]==1)
100 | { g.fillPolygon(x3,y3,4);
101 | g.fillPolygon(x4,y4,4);
102 | }
103 | else if(t[i]==2)
104 | { g.fillPolygon(x1,y1,4);
105 | g.fillPolygon(x2,y2,4);
106 | g.fillPolygon(x3,y3,4);
107 | g.fillPolygon(x6,y6,4);
108 | g.fillPolygon(x7,y7,6);
109 | }
110 | else if(t[i]==3)
111 | { g.fillPolygon(x1,y1,4);
112 | g.fillPolygon(x2,y2,4);
113 | g.fillPolygon(x3,y3,4);
114 | g.fillPolygon(x4,y4,4);
115 | g.fillPolygon(x7,y7,6);
116 | }
117 | else if(t[i]==4)
118 | { g.fillPolygon(x3,y3,4);
119 | g.fillPolygon(x4,y4,4);
120 | g.fillPolygon(x5,y5,4);
121 | g.fillPolygon(x7,y7,6);
122 | }
123 | else if(t[i]==5)
124 | { g.fillPolygon(x1,y1,4);
125 | g.fillPolygon(x2,y2,4);
126 | g.fillPolygon(x4,y4,4);
127 | g.fillPolygon(x5,y5,4);
128 | g.fillPolygon(x7,y7,6);
129 | }
130 | else if(t[i]==6)
131 | { g.fillPolygon(x1,y1,4);
132 | g.fillPolygon(x2,y2,4);
133 | g.fillPolygon(x4,y4,4);
134 | g.fillPolygon(x5,y5,4);
135 | g.fillPolygon(x6,y6,4);
136 | g.fillPolygon(x7,y7,6);
137 | }
138 | else if(t[i]==7)
139 | { g.fillPolygon(x1,y1,4);
140 | g.fillPolygon(x3,y3,4);
141 | g.fillPolygon(x4,y4,4);
142 | }
143 | else if(t[i]==8)
144 | { g.fillPolygon(x1,y1,4);
145 | g.fillPolygon(x2,y2,4);
146 | g.fillPolygon(x3,y3,4);
147 | g.fillPolygon(x4,y4,4);
148 | g.fillPolygon(x5,y5,4);
149 | g.fillPolygon(x6,y6,4);
150 | g.fillPolygon(x7,y7,6);
151 | }
152 | else if(t[i]==9)
153 | { g.fillPolygon(x1,y1,4);
154 | g.fillPolygon(x2,y2,4);
155 | g.fillPolygon(x3,y3,4);
156 | g.fillPolygon(x4,y4,4);
157 | g.fillPolygon(x5,y5,4);
158 | g.fillPolygon(x7,y7,6);
159 | }
160 | }
161 | g.fillRect(220,30,15,15);
162 | g.fillRect(220,130,15,15);
163 | g.fillRect(470,30,15,15);
164 | g.fillRect(470,130,15,15);
165 | try{
166 | Thread.sleep(500);
167 | }
168 | catch(Exception e)
169 | {}
170 | repaint();
171 | }
172 | }
--------------------------------------------------------------------------------
/Dodging_Disc.java:
--------------------------------------------------------------------------------
1 | //Dodging Disc
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /**/
9 | public class Dodging_Disc extends JApplet implements KeyListener,MouseListener
10 | { int x,y,x2,y2,x3=100,y3=100,x4=380,y4=100,i,j,c=0,d=0,s=0,s1=0,r1=1,k,k1=0,f=0;
11 | private JPanel panel;
12 | public void init()
13 | { addKeyListener(this);
14 | addMouseListener(this);
15 | requestFocus();
16 | panel = new JPanel()
17 | { protected void paintComponent(Graphics g)
18 | { super.paintComponent(g);
19 | try
20 | { if(f==0)
21 | { x3=x3+c;
22 | y3=y3+d;
23 | }
24 | if(x3<100)
25 | x3=100;
26 | if(y3<100)
27 | y3=100;
28 | if(x3>180)
29 | x3=180;
30 | if(y3>180)
31 | y3=180;
32 | Color c1=new Color(255,25,140);
33 | Color c2=new Color(255,255,255);
34 | Color c3=new Color(170,153,172);
35 | Color c4=new Color(255,121,188);
36 | Font fobj1=new Font("Arial",Font.BOLD,14);
37 | g.setColor(Color.BLACK);
38 | g.fillRect(86,66,149,169);
39 | g.setColor(c1);
40 | g.fillRect(88,68,145,165);
41 | g.setColor(c2);
42 | g.drawRect(90,70,140,160);
43 | g.setColor(c3);
44 | g.drawLine(91,90,229,90);
45 | g.setColor(c2);
46 | g.fillRect(95,95,130,130);
47 | g.setColor(c3);
48 | g.fillRect(96,96,128,128);
49 | g.setColor(Color.BLACK);
50 | g.fillRect(98,98,124,124);
51 | g.setColor(c2);
52 | g.drawLine(91,91,229,91);
53 | g.setColor(c1);
54 | g.fillRect(100,100,120,120);
55 | g.setColor(c4);
56 | g.fillRect(140,100,40,40);
57 | g.fillRect(100,140,40,40);
58 | g.fillRect(180,140,40,40);
59 | g.fillRect(140,180,40,40);
60 | g.setColor(c2);
61 | g.setFont(fobj1);
62 | g.drawString("DODGE BALL",115,85);
63 | g.setColor(Color.BLUE);
64 | g.fillOval(x3+5,y3+5,30,30);
65 | if(x3==x4&&y3==y4||x4>x3&&x4x3&&y3==y4||y4>y3&&y4y3&&x3==x4)
66 | { f=1;
67 | Font fobj=new Font("Arial",Font.BOLD,15);
68 | g.setFont(fobj);
69 | g.setColor(Color.BLUE);
70 | g.drawString("GAME OVER",120,280);
71 | g.setColor(Color.MAGENTA);
72 | g.fillRect(150,290,20,20);
73 | g.setColor(Color.WHITE);
74 | g.drawLine(165,295,165,305);
75 | g.drawLine(165,305,155,305);
76 | g.drawLine(155,305,155,300);
77 | g.drawLine(155,300,152,303);
78 | g.drawLine(155,300,157,303);
79 | if(x>=150&&x<=170&&y>=290&&y<=310)
80 | { f=0;
81 | x3=100;y3=100;x4=380;y4=100;c=0;d=0;s=0;s1=0;r1=1;k=41;k1=0;f=0;
82 | x=10;
83 | y=10;
84 | repaint();
85 | }
86 | else
87 | f=1;
88 | }
89 | if(f==0)
90 | { g.setColor(Color.GREEN);
91 | g.fillOval(x4+5,y4+5,30,30);
92 | if(r1==1||r1==2||r1==3)
93 | { if(x4==-60)
94 | { if(k1==0)
95 | { Random r=new Random();
96 | r1=1+r.nextInt(12);
97 | }
98 | if(r1==1)
99 | { y4=100;
100 | x4=380;
101 | k1=0;
102 | s1++;
103 | }
104 | else if(r1==2)
105 | { y4=140;
106 | x4=380;
107 | k1=0;
108 | s1++;
109 | }
110 | else if(r1==3)
111 | { y4=180;
112 | x4=380;
113 | k1=0;
114 | s1++;
115 | }
116 | else if(r1==4||r1==5||r1==6)
117 | { x4=380;
118 | k1=1;
119 | }
120 | else if(r1==7||r1==8||r1==9)
121 | { y4=-60;
122 | k1=1;
123 | }
124 | else if(r1==10||r1==11||r1==12)
125 | { y4=380;
126 | k1=1;
127 | }
128 | }
129 | else
130 | x4=x4-s;
131 | }
132 | else if(r1==4||r1==5||r1==6)
133 | { if(x4==380)
134 | { if(k1==0)
135 | { Random r=new Random();
136 | r1=1+r.nextInt(12);
137 | }
138 | if(r1==4)
139 | { y4=100;
140 | x4=-60;
141 | k1=0;
142 | s1++;
143 | }
144 | else if(r1==5)
145 | { y4=140;
146 | x4=-60;
147 | k1=0;
148 | s1++;
149 | }
150 | else if(r1==6)
151 | { y4=180;
152 | x4=-60;
153 | k1=0;
154 | s1++;
155 | }
156 | else if(r1==1||r1==2||r1==3)
157 | { x4=-60;
158 | k1=1;
159 | }
160 | else if(r1==7||r1==8||r1==9)
161 | { y4=-60;
162 | k1=1;
163 | }
164 | else if(r1==10||r1==11||r1==12)
165 | { y4=380;
166 | k1=1;
167 | }
168 | }
169 | else
170 | x4=x4+s;
171 | }
172 | if(r1==7||r1==8||r1==9)
173 | { if(y4==-60)
174 | { if(k1==0)
175 | { Random r=new Random();
176 | r1=1+r.nextInt(12);
177 | }
178 | if(r1==7)
179 | { y4=380;
180 | x4=100;
181 | k1=0;
182 | s1++;
183 | }
184 | else if(r1==8)
185 | { y4=380;
186 | x4=140;
187 | k1=0;
188 | s1++;
189 | }
190 | else if(r1==9)
191 | { y4=380;
192 | x4=180;
193 | k1=0;
194 | s1++;
195 | }
196 | else if(r1==4||r1==5||r1==6)
197 | { x4=380;
198 | k1=1;
199 | }
200 | else if(r1==1||r1==2||r1==3)
201 | { x4=-60;
202 | k1=1;
203 | }
204 | else if(r1==10||r1==11||r1==12)
205 | { y4=380;
206 | k1=1;
207 | }
208 | }
209 | else
210 | y4=y4-s;
211 | }
212 | else if(r1==10||r1==11||r1==12)
213 | { if(y4==380)
214 | { if(k1==0)
215 | { Random r=new Random();
216 | r1=1+r.nextInt(12);
217 | }
218 | if(r1==10)
219 | { y4=-60;
220 | x4=100;
221 | k1=0;
222 | s1++;
223 | }
224 | else if(r1==11)
225 | { y4=-60;
226 | x4=140;
227 | k1=0;
228 | s1++;
229 | }
230 | else if(r1==12)
231 | { y4=-60;
232 | x4=180;
233 | k1=0;
234 | s1++;
235 | }
236 | else if(r1==4||r1==5||r1==6)
237 | { x4=380;
238 | k1=1;
239 | }
240 | else if(r1==7||r1==8||r1==9)
241 | { y4=-60;
242 | k1=1;
243 | }
244 | else if(r1==1||r1==2||r1==3)
245 | { x4=-60;
246 | k1=1;
247 | }
248 | }
249 | else
250 | y4=y4+s;
251 | }
252 | Thread.sleep(47);
253 | showStatus(" SCORE="+(s1*10));
254 | c=0;
255 | d=0;
256 | repaint();
257 | }
258 | }
259 | catch(Exception e)
260 | {}
261 | }
262 | };
263 | add(panel);
264 | }
265 | public void mouseClicked(MouseEvent me)
266 | {}
267 | public void mouseEntered(MouseEvent me)
268 | {}
269 | public void mouseExited(MouseEvent me)
270 | {}
271 | public void mousePressed(MouseEvent me)
272 | { x=me.getX();
273 | y=me.getY();
274 | repaint();
275 | }
276 | public void mouseReleased(MouseEvent me)
277 | {}
278 | public void keyPressed(KeyEvent ke)
279 | { k=ke.getKeyCode();
280 | if(k==37)
281 | { c=-40;
282 | d=0;
283 | }
284 | else if(k==38)
285 | { c=0;
286 | d=-40;
287 | }
288 | else if(k==39)
289 | { c=40;
290 | d=0;
291 | }
292 | else if(k==40)
293 | { c=0;
294 | d=40;
295 | }
296 | else if(k==32)
297 | { s=20;
298 | c=0;
299 | d=0;
300 | x=10;
301 | y=10;
302 | }
303 | repaint();
304 | }
305 | public void keyReleased(KeyEvent ke)
306 | {}
307 | public void keyTyped(KeyEvent ke)
308 | {}
309 | public void paint(Graphics g)
310 | { super.paint(g);
311 | setSize(320,320);
312 | }
313 | }
314 |
315 |
--------------------------------------------------------------------------------
/Eight_Queen.java:
--------------------------------------------------------------------------------
1 | //Eight Queen
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Eight_Queen extends JApplet implements KeyListener
9 | { int x=20,y=20,x1,a=0,b=0,x2=20,y2=20,k,l,c=0;
10 | int x3[]=new int[8];
11 | int y3[]=new int[8];
12 | private JPanel panel;
13 | public void init()
14 | { addKeyListener(this);
15 | requestFocus();
16 | x1=x;
17 | panel = new JPanel()
18 | { protected void paintComponent(Graphics g)
19 | { super.paintComponent(g);
20 | g.setColor(Color.MAGENTA);
21 | Font f=new Font("Arial",Font.BOLD,14);
22 | g.setFont(f);
23 | g.drawString("EIGHT QUEEN",150,15);
24 | x=20;
25 | y=20;
26 | for(int i=1;i<9;i++)
27 | { for(int j=1;j<5;j++)
28 | { if(i%2==0)
29 | { g.setColor(Color.BLACK);
30 | g.fillRect(x,y,40,40);
31 | x=x+40;
32 | g.setColor(Color.RED);
33 | g.fillRect(x,y,40,40);
34 | x=x+40;
35 | }
36 | else
37 | { g.setColor(Color.RED);
38 | g.fillRect(x,y,40,40);
39 | x=x+40;
40 | g.setColor(Color.BLACK);
41 | g.fillRect(x,y,40,40);
42 | x=x+40;
43 | }
44 | }
45 | y=y+40;
46 | x=x1;
47 | }
48 | x2=x2+a;
49 | y2=y2+b;
50 | if(x2<20)
51 | x2=20;
52 | if(y2<20)
53 | y2=20;
54 | if(x2>300)
55 | x2=300;
56 | if(y2>300)
57 | y2=300;
58 | g.setColor(Color.BLUE);
59 | g.fillRect(x2,y2,40,40);
60 | if(k==32)
61 | { g.setColor(Color.GREEN);
62 | Font f1=new Font("Arial",Font.BOLD,27);
63 | g.setFont(f1);
64 | g.drawString("Q",x2+12,y2+25);
65 | x3[c]=x2+12;
66 | y3[c]=y2+25;
67 | c++;
68 | }
69 | for(l=0;l=2)
71 | { g.setColor(Color.ORANGE);
72 | g.fillRect(x2,y2,40,40);
73 | c--;
74 | }
75 | else if(x3[l]==x3[c-1]&&c>=2)
76 | { g.setColor(Color.ORANGE);
77 | g.fillRect(x2,y2,40,40);
78 | c--;
79 | }
80 | else if((x3[c-1]-x3[l])==(y3[c-1]-y3[l])&&c>=2)
81 | { g.setColor(Color.ORANGE);
82 | g.fillRect(x2,y2,40,40);
83 | c--;
84 | }
85 | else if((x3[c-1]-x3[l])==-(y3[c-1]-y3[l])&&c>=2)
86 | { g.setColor(Color.ORANGE);
87 | g.fillRect(x2,y2,40,40);
88 | c--;
89 | }
90 | }
91 | for(l=0;lb&&a>c)
43 | t4.setText(""+a);
44 | else if(b>a&&b>c)
45 | t4.setText(""+b);
46 | else if(c>a&&c>b)
47 | t4.setText(""+c);
48 | }
49 | catch(Exception e)
50 | {}
51 | }
52 | public void paint(Graphics g)
53 | { setSize(600,250);
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/Find_Green_balls_Game.java:
--------------------------------------------------------------------------------
1 | //Find Green balls Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /*
9 | */
10 | public class Find_Green_balls_Game extends JApplet implements KeyListener
11 | { int k,bx,by,rand1,rand2,a1,b1,i,l,f,c2;
12 | int a[]=new int[20];
13 | int b[]=new int[20];
14 | int c[]=new int[20];
15 | int c1[]=new int[20];
16 | int d[]=new int[20];
17 | int x[]=new int[20];
18 | int y[]=new int[20];
19 | int e[]=new int[20];
20 | int x1[]=new int[20];
21 | int y1[]=new int[20];
22 | double s,s1;
23 | boolean k1,k2,k3,k4;
24 | private JPanel panel;
25 | public void init()
26 | { addKeyListener(this);
27 | requestFocus();
28 | bx=200;
29 | by=200;
30 | x[0]=50;
31 | y[0]=100;
32 | x[1]=100;
33 | y[1]=100;
34 | x[2]=150;
35 | y[2]=100;
36 | x[3]=200;
37 | y[3]=100;
38 | x[4]=250;
39 | y[4]=100;
40 | x[5]=300;
41 | y[5]=100;
42 | x[6]=350;
43 | y[6]=100;
44 | x[7]=50;
45 | y[7]=300;
46 | x[8]=100;
47 | y[8]=300;
48 | x[9]=150;
49 | y[9]=300;
50 | x[10]=200;
51 | y[10]=300;
52 | x[11]=250;
53 | y[11]=300;
54 | x1[12]=300;
55 | y1[12]=300;
56 | l=12;
57 | panel = new JPanel()
58 | { protected void paintComponent(Graphics g)
59 | { try
60 | { super.paintComponent(g);
61 | Font fobj=new Font("Arial",Font.BOLD,16);
62 | setBackground(Color.black);
63 | g.setFont(fobj);
64 | if(f==0&&l!=0)
65 | { g.setColor(Color.gray);
66 | g.fillOval(bx-70,by-70,155,155);
67 | g.setColor(Color.pink);
68 | g.fillOval(bx,by,15,15);
69 | for(i=0;i<12;i++)
70 | { s=(x[i]+7-bx-8)*(x[i]+7-bx-8)+(y[i]+7-by-8)*(y[i]+7-by-8)-78*78;
71 | s1=(x[i]+7-bx-8)*(x[i]+7-bx-8)+(y[i]+7-by-8)*(y[i]+7-by-8)-48*48;
72 | if(x[i]<-20)
73 | x[i]=410;
74 | else if(x[i]>410)
75 | x[i]=-10;
76 | else if(y[i]<-20)
77 | y[i]=410;
78 | else if(y[i]>410)
79 | y[i]=-10;
80 | if(c[i]==0&&s>0)
81 | { Random r=new Random();
82 | rand1=1+r.nextInt(3);
83 | rand2=1+r.nextInt(3);
84 | if(rand1==1&&rand2==1)
85 | c[i]=-1;
86 | if(rand1==1)
87 | a[i]=0;
88 | else if(rand1==2)
89 | a[i]=1;
90 | else if(rand1==3)
91 | a[i]=-1;
92 | if(rand2==1)
93 | b[i]=0;
94 | else if(rand2==2)
95 | b[i]=1;
96 | else if(rand2==3)
97 | b[i]=-1;
98 | }
99 | else if(s<=0)
100 | { if(e[i]==0)
101 | { g.setColor(Color.green);
102 | g.fillOval(x[i],y[i],15,15);
103 | }
104 | if(c1[i]==1)
105 | { d[i]=Math.abs(x[i]-bx);
106 | if(d[i]<=50)
107 | { if(x[i]-bx<0)
108 | a[i]=-1;
109 | if(x[i]-bx>0)
110 | a[i]=1;
111 | if(x[i]-bx==0)
112 | a[i]=0;
113 | if(y[i]-by<0)
114 | b[i]=-1;
115 | if(y[i]-by>0)
116 | b[i]=1;
117 | if(y[i]-by==0)
118 | b[i]=0;
119 | }
120 | }
121 | if(c1[i]==0&&s1<=0)
122 | { a[i]=-1*a[i];
123 | b[i]=-1*b[i];
124 | c1[i]=1;
125 | }
126 | }
127 | else
128 | { if(e[i]==0)
129 | { g.setColor(Color.black);
130 | g.fillOval(x[i],y[i],15,15);
131 | }
132 | c1[i]=0;
133 | }
134 | x[i]=x[i]+a[i];
135 | y[i]=y[i]+b[i];
136 | if(bx>=x[i]-7&&bx<=x[i]+15&&by>=y[i]-7&&by<=y[i]+15)
137 | { e[i]=1;
138 | l--;
139 | x[i]=410;
140 | y[i]=410;
141 | c[i]=300;
142 | c1[i]=2;
143 | }
144 | }
145 | x1[0]=x1[0]+a1;
146 | y1[0]=y1[0]+b1;
147 | if(x1[0]<-20)
148 | x1[0]=410;
149 | else if(x1[0]>410)
150 | x1[0]=-10;
151 | else if(y1[0]<-20)
152 | y1[0]=410;
153 | else if(y1[0]>410)
154 | y1[0]=-10;
155 | s=(x1[0]+7-bx-8)*(x1[0]+7-bx-8)+(y1[0]+7-by-8)*(y1[0]+7-by-8)-78*78;
156 | if(s>0)
157 | { Random r=new Random();
158 | rand1=1+r.nextInt(3);
159 | rand2=1+r.nextInt(3);
160 | if(c2==0)
161 | { if(rand1==1)
162 | a1=0;
163 | else if(rand1==2)
164 | a1=1;
165 | else if(rand1==3)
166 | a1=-1;
167 | if(rand2==1)
168 | b1=0;
169 | else if(rand2==2)
170 | b1=1;
171 | else if(rand2==3)
172 | b1=-1;
173 | }
174 | g.setColor(Color.black);
175 | g.fillOval(x1[0],y1[0],15,15);
176 | }
177 | else if(s<=0)
178 | { if(x1[0]-bx<0)
179 | a1=1;
180 | if(x1[0]-bx>0)
181 | a1=-1;
182 | if(x1[0]-bx==0)
183 | a1=0;
184 | if(y1[0]-by<0)
185 | b1=1;
186 | if(y1[0]-by>0)
187 | b1=-1;
188 | if(y1[0]-by==0)
189 | b1=0;
190 | g.setColor(Color.red);
191 | g.fillOval(x1[0],y1[0],15,15);
192 | }
193 | if(bx>=x1[0]&&bx<=x1[0]+7&&by>=y1[0]&&by<=y1[0]+7)
194 | f=1;
195 | g.setColor(Color.MAGENTA);
196 | g.drawString("Enemies left: "+l,260,20);
197 | if(bx<=0)
198 | bx=0;
199 | else if(bx>=385)
200 | bx=385;
201 | else if(by<=0)
202 | by=0;
203 | else if(by>=385)
204 | by=385;
205 | for(i=0;i<12;i++)
206 | { c[i]++;
207 | if(c[i]==200)
208 | c[i]=0;
209 | }
210 | c2++;
211 | if(c2==200)
212 | c2=0;
213 | }
214 | if(f==1)
215 | { g.setFont(fobj);
216 | g.setColor(Color.MAGENTA);
217 | g.drawString("GAME OVER",150,200);
218 | }
219 | if(l==0)
220 | { g.setFont(fobj);
221 | g.setColor(Color.MAGENTA);
222 | g.drawString("YOU WIN",150,200);
223 | }
224 | Thread.sleep(35);
225 | repaint();
226 | }
227 | catch(Exception e)
228 | {}
229 | }
230 | };
231 | add(panel);
232 | }
233 | public void keyPressed(KeyEvent ke)
234 | { k=ke.getKeyCode();
235 | if(k==37)
236 | k1=true;
237 | if(k==38)
238 | k2=true;
239 | if(k==39)
240 | k3=true;
241 | if(k==40)
242 | k4=true;
243 | if(k1==true)
244 | bx=bx-4;
245 | if(k2==true)
246 | by=by-4;
247 | if(k3==true)
248 | bx=bx+4;
249 | if(k4==true)
250 | by=by+4;
251 | repaint();
252 | }
253 | public void keyReleased(KeyEvent ke)
254 | { k=ke.getKeyCode();
255 | if(k==37)
256 | k1=false;
257 | if(k==38)
258 | k2=false;
259 | if(k==39)
260 | k3=false;
261 | if(k==40)
262 | k4=false;
263 | repaint();
264 | }
265 | public void keyTyped(KeyEvent ke)
266 | {}
267 | public void paint(Graphics g)
268 | { setSize(400,400);
269 | super.paint(g);
270 | }
271 | }
--------------------------------------------------------------------------------
/Find_Sum_and_Reverse_of_the_Number.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Find_Sum_and_Reverse_of_the_Number extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4;
6 | Button b1,b2,b3;
7 | TextField t1,t2,t3;
8 | int n,s,r,t,t11,n1,s1,r1,t12,t111;
9 | String str;
10 | public void init()
11 | { setLayout(null);
12 | l1=new Label("Sum and Reverse of the Number");
13 | l2=new Label("Number");
14 | l3=new Label("Reverse");
15 | l4=new Label("Sum of Digits");
16 | b1=new Button("Reverse");
17 | b2=new Button("Sum of Digits");
18 | b3=new Button("Clear");
19 | t1=new TextField();
20 | t2=new TextField();
21 | t3=new TextField();
22 | add(t1);add(t2);add(t3);
23 | add(b1);add(b2);add(b3);
24 | add(l1);add(l2);add(l3);add(l4);
25 | t2.setEditable(false);
26 | t3.setEditable(false);
27 | b1.addActionListener(this);
28 | b2.addActionListener(this);
29 | b3.addActionListener(this);
30 | l1.setBounds(150,20,250,30);
31 | l2.setBounds(30,80,100,20);
32 | l3.setBounds(30,140,100,20);
33 | l4.setBounds(230,140,100,20);
34 | b1.setBounds(100,200,100,30);
35 | b2.setBounds(220,200,100,30);
36 | b3.setBounds(340,200,100,30);
37 | t1.setBounds(100,80,100,20);
38 | t2.setBounds(100,140,100,20);
39 | t3.setBounds(320,140,100,20);
40 | }
41 | public void actionPerformed(ActionEvent ae)
42 | { try
43 | { str=ae.getActionCommand();
44 | if(str.equals("Reverse"))
45 | { n=Integer.parseInt(t1.getText());
46 | s=n;
47 | while(s!=0)
48 | { t=s%10;
49 | s=s/10;
50 | t11=t11*10+t;
51 | }
52 | t2.setText(""+t11);
53 | }
54 | if(str.equals("Sum of Digits"))
55 | { n1=Integer.parseInt(t1.getText());
56 | s1=n1;
57 | while(s1!=0)
58 | { t12=s1%10;
59 | s1=s1/10;
60 | t111=t111+t12;
61 | }
62 | t3.setText(""+t111);
63 | }
64 | if(str.equals("Clear"))
65 | { t1.setText("");
66 | t2.setText("");
67 | t3.setText("");
68 | }
69 | n=0;
70 | s=0;
71 | r=0;
72 | t=0;
73 | t11=0;
74 | n1=0;
75 | s1=0;
76 | r1=0;
77 | t12=0;
78 | t111=0;
79 | }
80 | catch(Exception e)
81 | {}
82 | }
83 | public void paint(Graphics g)
84 | { setSize(500,250);
85 | }
86 | }
87 |
88 |
--------------------------------------------------------------------------------
/Flappy_Bird_Game.java:
--------------------------------------------------------------------------------
1 | //Flappy Bird Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /**/
9 | public class Flappy_Bird_Game extends JApplet implements KeyListener
10 | { int k,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,s,c,f;
11 | private JPanel panel;
12 | public void init()
13 | { addKeyListener(this);
14 | requestFocus();
15 | x1=500;
16 | x2=670;
17 | x3=840;
18 | x4=1010;
19 | x5=1180;
20 | x6=250;
21 | y6=250;
22 | Random r=new Random();
23 | y2=-150+r.nextInt(300);
24 | y3=-150+r.nextInt(300);
25 | y4=-150+r.nextInt(300);
26 | y5=-150+r.nextInt(300);
27 | panel = new JPanel()
28 | { protected void paintComponent(Graphics g)
29 | { super.paintComponent(g);
30 | try
31 | { g.setColor(Color.GRAY);
32 | g.fillRect(0,450,800,50);
33 | Color cobj=new Color(163,255,255);
34 | setBackground(cobj);
35 | g.setColor(Color.BLACK);
36 | g.fillRect(x1-1,-1,17,201+y1);
37 | g.fillRect(x1-1,300+y1,17,151-y1);
38 | g.fillRect(x2-1,0,17,201+y2);
39 | g.fillRect(x2-1,300+y2,17,151-y2);
40 | g.fillRect(x3-1,0,17,201+y3);
41 | g.fillRect(x3-1,300+y3,17,151-y3);
42 | g.fillRect(x4-1,0,17,201+y4);
43 | g.fillRect(x4-1,300+y4,17,151-y4);
44 | g.fillRect(x5-1,0,17,201+y5);
45 | g.fillRect(x5-1,300+y5,17,151-y5);
46 | g.setColor(Color.GREEN);
47 | g.fillRect(x1,0,15,200+y1);
48 | g.setColor(Color.BLACK);
49 | g.fillRect(x1-11,199+y1,37,12);
50 | g.setColor(Color.GREEN);
51 | g.fillRect(x1-10,200+y1,35,10);
52 | g.setColor(Color.BLACK);
53 | g.fillRect(x1-11,288+y1,37,12);
54 | g.setColor(Color.GREEN);
55 | g.fillRect(x1-10,289+y1,35,10);
56 | g.fillRect(x1,300+y1,15,150-y1);
57 | g.fillRect(x2,0,15,200+y2);
58 | g.setColor(Color.BLACK);
59 | g.fillRect(x2-11,199+y2,37,12);
60 | g.setColor(Color.GREEN);
61 | g.fillRect(x2-10,200+y2,35,10);
62 | g.setColor(Color.BLACK);
63 | g.fillRect(x2-11,288+y2,37,12);
64 | g.setColor(Color.GREEN);
65 | g.fillRect(x2-10,289+y2,35,10);
66 | g.fillRect(x2,300+y2,15,150-y2);
67 | g.fillRect(x3,0,15,200+y3);
68 | g.setColor(Color.BLACK);
69 | g.fillRect(x3-11,199+y3,37,12);
70 | g.setColor(Color.GREEN);
71 | g.fillRect(x3-10,200+y3,35,10);
72 | g.setColor(Color.BLACK);
73 | g.fillRect(x3-11,288+y3,37,12);
74 | g.setColor(Color.GREEN);
75 | g.fillRect(x3-10,289+y3,35,10);
76 | g.fillRect(x3,300+y3,15,150-y3);
77 | g.fillRect(x4,0,15,200+y4);
78 | g.setColor(Color.BLACK);
79 | g.fillRect(x4-11,199+y4,37,12);
80 | g.setColor(Color.GREEN);
81 | g.fillRect(x4-10,200+y4,35,10);
82 | g.setColor(Color.BLACK);
83 | g.fillRect(x4-11,288+y4,37,12);
84 | g.setColor(Color.GREEN);
85 | g.fillRect(x4-10,289+y4,35,10);
86 | g.fillRect(x4,300+y4,15,150-y4);
87 | g.fillRect(x5,0,15,200+y5);
88 | g.setColor(Color.BLACK);
89 | g.fillRect(x5-11,199+y5,37,12);
90 | g.setColor(Color.GREEN);
91 | g.fillRect(x5-10,200+y5,35,10);
92 | g.setColor(Color.BLACK);
93 | g.fillRect(x5-11,288+y5,37,12);
94 | g.setColor(Color.GREEN);
95 | g.fillRect(x5-10,289+y5,35,10);
96 | g.fillRect(x5,300+y5,15,150-y5);
97 | if(c==1&&f==0)
98 | { x1=x1-1;
99 | if(x1==-15)
100 | { x1=820;
101 | Random r=new Random();
102 | y1=-150+r.nextInt(300);
103 | }
104 | x2=x2-1;
105 | if(x2==-15)
106 | { x2=820;
107 | Random r=new Random();
108 | y2=-150+r.nextInt(300);
109 | }
110 | x3=x3-1;
111 | if(x3==-15)
112 | { x3=820;
113 | Random r=new Random();
114 | y3=-150+r.nextInt(300);
115 | }
116 | x4=x4-1;
117 | if(x4==-15)
118 | { x4=820;
119 | Random r=new Random();
120 | y4=-150+r.nextInt(300);
121 | }
122 | x5=x5-1;
123 | if(x5==-15)
124 | { x5=820;
125 | Random r=new Random();
126 | y5=-150+r.nextInt(300);
127 | }
128 | y6=y6+1;
129 | s++;
130 | }
131 | g.setColor(Color.BLACK);
132 | g.fillOval(x6-1,y6-1,17,17);
133 | g.setColor(Color.ORANGE);
134 | g.fillOval(x6,y6,15,15);
135 | g.setColor(Color.BLACK);
136 | g.fillOval(x6+6,y6-1,10,10);
137 | g.setColor(Color.WHITE);
138 | g.fillOval(x6+7,y6,8,8);
139 | g.setColor(Color.BLACK);
140 | g.fillOval(x6-5,y6+6,10,6);
141 | g.setColor(Color.WHITE);
142 | g.fillOval(x6-4,y6+7,8,4);
143 | g.setColor(Color.BLACK);
144 | g.fillOval(x6+10,y6+2,3,3);
145 | g.setColor(Color.RED);
146 | g.fillOval(x6+8,y6+9,11,4);
147 | if(x6>=x1&&x6<=x1+15&&y6>=0&&y6<=200+y1||x6>=x2&&x6<=x2+15&&y6>=0&&y6<=200+y2||x6>=x3&&x6<=x3+15&&y6>=0&&y6<=200+y3||x6>=x4&&x6<=x4+15&&y6>=0&&y6<=200+y4||x6>=x5&&x6<=x5+15&&y6>=0&&y6<=200+y5)
148 | f=1;
149 | if(x6>=x1&&x6<=x1+15&&y6>=300+y1&&y6<=450-y1||x6>=x2&&x6<=x2+15&&y6>=300+y2&&y6<=450-y2||x6>=x3&&x6<=x3+15&&y6>=300+y3&&y6<=450-y3||x6>=x4&&x6<=x4+15&&y6>=300+y4&&y6<=450-y4||x6>=x5&&x6<=x5+15&&y6>=300+y5&&y6<=450-y5)
150 | f=1;
151 | if(f==1)
152 | { Font fobj=new Font("Arial",Font.BOLD,24);
153 | g.setFont(fobj);
154 | g.setColor(Color.MAGENTA);
155 | g.drawString("GAME OVER",370,250);
156 | }
157 | Thread.sleep(10);
158 | repaint();
159 | showStatus("SCORE="+s/10);
160 | }
161 | catch(Exception e)
162 | {}
163 | }
164 | };
165 | add(panel);
166 | }
167 | public void keyTyped(KeyEvent ke)
168 | {}
169 | public void keyPressed(KeyEvent ke)
170 | {}
171 | public void keyReleased(KeyEvent ke)
172 | { k=ke.getKeyCode();
173 | if(k==38&&f==0)
174 | { y6=y6-50;
175 | k=40;
176 | c=1;
177 | }
178 | }
179 | public void paint(Graphics g)
180 | { super.paint(g);
181 | setSize(800,500);
182 | }
183 | }
184 |
185 |
--------------------------------------------------------------------------------
/Images of game and Application/Image1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image1.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image10.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image11.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image12.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image13.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image14.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image15.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image16.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image17.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image17.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image18.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image18.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image19.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image19.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image2.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image20.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image20.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image21.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image21.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image22.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image22.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image23.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image23.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image24.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image24.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image25.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image25.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image26.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image26.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image27.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image27.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image3.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image4.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image5.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image6.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image7.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image8.jpg
--------------------------------------------------------------------------------
/Images of game and Application/Image9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Shashank02051997/Java-Game-and-Application/7f3d9bceb47d2c7d6e3e3933126434508f63e500/Images of game and Application/Image9.jpg
--------------------------------------------------------------------------------
/Knights_Move_Game.java:
--------------------------------------------------------------------------------
1 | //Knights Move Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /*
9 | */
10 | public class Knights_Move_Game extends JApplet implements MouseListener
11 | { int x,y,bx,by,hx,hy,i,j,p,q,p1,q1,c,c1,c2,e,f;
12 | int a[][]=new int[8][8];
13 | private JPanel panel;
14 | public void init()
15 | { Random r=new Random();
16 | x=40+r.nextInt(300);
17 | y=40+r.nextInt(300);
18 | bx=30;
19 | by=30;
20 | for(i=0;i<8;i++)
21 | { for(j=0;j<8;j++)
22 | { if(x>=bx&&x<=bx+50&&y>=by&&y<=by+50)
23 | { p1=i+2;
24 | q1=j+1;
25 | i=8;
26 | j=8;
27 | }
28 | bx=bx+53;
29 | }
30 | bx=30;
31 | by=by+53;
32 | }
33 | addMouseListener(this);
34 | panel = new JPanel()
35 | { protected void paintComponent(Graphics g)
36 | { try
37 | { super.paintComponent(g);
38 | setBackground(Color.white);
39 | Font fobj=new Font("Arial",Font.BOLD,24);
40 | Color cobj=new Color(255,255,0);
41 | Color cobj1=new Color(60,138,30);
42 | g.setColor(cobj);
43 | g.fillRect(20,20,450,450);
44 | g.setColor(cobj1);
45 | bx=30;
46 | by=30;
47 | for(i=0;i<8;i++)
48 | { for(j=0;j<8;j++)
49 | { g.drawRect(bx,by,50,50);
50 | by=by+53;
51 | }
52 | by=30;
53 | bx=bx+53;
54 | }
55 | if(e==0||e%2==1)
56 | { bx=30;
57 | by=30;
58 | for(i=0;i<8;i++)
59 | { for(j=0;j<8;j++)
60 | { if(x>=bx&&x<=bx+50&&y>=by&&y<=by+50)
61 | { p=i;
62 | q=j;
63 | if(a[p][q]==0&&(p1==p+2&&q1==q+1||p1==p+2&&q1==q-1||p1==p+1&&q1==q+2||p1==p+1&&q1==q-2||p1==p-1&&q1==q+2||p1==p-1&&q1==q-2||p1==p-2&&q1==q+1||p1==p-2&&q1==q-1))
64 | { a[p][q]=1;
65 | c=0;
66 | p1=p;
67 | q1=q;
68 | }
69 | else
70 | c=1;
71 | i=8;
72 | j=8;
73 | }
74 | bx=bx+53;
75 | }
76 | bx=30;
77 | by=by+53;
78 | }
79 | }
80 | if(e%2==0&&e>0)
81 | { if(p1-2>=0&&p1-2<=7&&q1-1>=0&&q1-1<=7&&c2==0)
82 | { if(a[p1-2][q1-1]==0)
83 | { p=p1-2;
84 | q=q1-1;
85 | a[p][q]=1;
86 | c2=1;
87 | }
88 | }
89 | if(p1-2>=0&&p1-2<=7&&q1+1>=0&&q1+1<=7&&c2==0)
90 | { if(a[p1-2][q1+1]==0)
91 | { p=p1-2;
92 | q=q1+1;
93 | a[p][q]=1;
94 | c2=1;
95 | }
96 | }
97 | if(p1-1>=0&&p1-1<=7&&q1-2>=0&&q1-2<=7&&c2==0)
98 | { if(a[p1-1][q1-2]==0)
99 | { p=p1-1;
100 | q=q1-2;
101 | a[p][q]=1;
102 | c2=1;
103 | }
104 | }
105 | if(p1-1>=0&&p1-1<=7&&q1+2>=0&&q1+2<=7&&c2==0)
106 | { if(a[p1-1][q1+2]==0)
107 | { p=p1-1;
108 | q=q1+2;
109 | a[p][q]=1;
110 | c2=1;
111 | }
112 | }
113 | if(p1+1>=0&&p1+1<=7&&q1-2>=0&&q1-2<=7&&c2==0)
114 | { if(a[p1+1][q1-2]==0)
115 | { p=p1+1;
116 | q=q1-2;
117 | a[p][q]=1;
118 | c2=1;
119 | }
120 | }
121 | if(p1+1>=0&&p1+1<=7&&q1+2>=0&&q1+2<=7&&c2==0)
122 | { if(a[p1+1][q1+2]==0)
123 | { p=p1+1;
124 | q=q1+2;
125 | a[p][q]=1;
126 | c2=1;
127 | }
128 | }
129 | if(p1+2>=0&&p1+2<=7&&q1-1>=0&&q1-1<=7&&c2==0)
130 | { if(a[p1+2][q1-1]==0)
131 | { p=p1+2;
132 | q=q1-1;
133 | a[p][q]=1;
134 | c2=1;
135 | }
136 | }
137 | if(p1+2>=0&&p1+2<=7&&q1+1>=0&&q1+1<=7&&c2==0)
138 | { if(a[p1+2][q1+1]==0)
139 | { p=p1+2;
140 | q=q1+1;
141 | a[p][q]=1;
142 | c2=1;
143 | }
144 | }
145 | if(c2==0)
146 | f=1;
147 | p1=p;
148 | q1=q;
149 | c=0;
150 | }
151 | c2=0;
152 | hx=31;
153 | hy=31;
154 | for(i=0;i<8;i++)
155 | { for(j=0;j<8;j++)
156 | { if(a[i][j]==1)
157 | { g.setColor(Color.white);
158 | g.fillRect(hx,hy,48,48);
159 | g.setColor(Color.RED);
160 | if(i==p&&j==q&&c==0)
161 | { g.setFont(fobj);
162 | g.drawString("H",hx+14,hy+34);
163 | }
164 | if(i==p1&&j==q1&&c==1)
165 | { g.setFont(fobj);
166 | g.drawString("H",hx+14,hy+34);
167 | }
168 | }
169 | hx=hx+53;
170 | }
171 | hx=31;
172 | hy=hy+53;
173 | }
174 | Thread.sleep(1000);
175 | if(e%2==1)
176 | { e++;
177 | repaint();
178 | }
179 | if(f==1)
180 | { g.setFont(fobj);
181 | g.drawString("YOU WIN THE GAME",200,200);
182 | }
183 | }
184 | catch(Exception e)
185 | {}
186 | }
187 | };
188 | add(panel);
189 | }
190 | public void mouseClicked(MouseEvent me)
191 | {}
192 | public void mousePressed(MouseEvent me)
193 | { x=me.getX();
194 | y=me.getY();
195 | if(x>=30&&x<=450&&y>=30&&y<=450&&f==0)
196 | { bx=30;
197 | by=30;
198 | for(i=0;i<8;i++)
199 | { for(j=0;j<8;j++)
200 | { if(x>=bx&&x<=bx+50&&y>=by&&y<=by+50)
201 | { p=i;
202 | q=j;
203 | i=8;
204 | j=8;
205 | if(a[p][q]==0&&(p1==p+2&&q1==q+1||p1==p+2&&q1==q-1||p1==p+1&&q1==q+2||p1==p+1&&q1==q-2||p1==p-1&&q1==q+2||p1==p-1&&q1==q-2||p1==p-2&&q1==q+1||p1==p-2&&q1==q-1))
206 | { e++;
207 | repaint();
208 | }
209 | }
210 | bx=bx+53;
211 | }
212 | bx=30;
213 | by=by+53;
214 | }
215 | }
216 | }
217 | public void mouseReleased(MouseEvent me)
218 | {}
219 | public void mouseEntered(MouseEvent me)
220 | {}
221 | public void mouseExited(MouseEvent me)
222 | {}
223 | public void paint(Graphics g)
224 | { setSize(500,500);
225 | super.paint(g);
226 | }
227 | }
--------------------------------------------------------------------------------
/Mango_Masalla_Billing_System.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Mango_Masalla_Billing_System extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5,l6,l7,l8,l9;
6 | Button b1,b2;
7 | TextField t1,t2,t3,t4,t5,t6,t7,t8,t9;
8 | Checkbox c1;
9 | Checkbox c2,c3;
10 | CheckboxGroup cbg;
11 | double p,d,ch,a,b,c,tm,dis,np;
12 | String str;
13 | public void init()
14 | { setLayout(null);
15 | l1=new Label("MANGO MASALLA BILLING-SYSTEM");
16 | l2=new Label("Quantity");
17 | l3=new Label("Pizza(@60)");
18 | l4=new Label("Dossa(@50)");
19 | l5=new Label("Chowmein(@40)");
20 | l6=new Label("Amount (Rs.)");
21 | l7=new Label("Total Amount");
22 | l8=new Label("Discount");
23 | l9=new Label("Net Payment");
24 | b1=new Button("Calculate Bill");
25 | b2=new Button("Clear Entries");
26 | t1=new TextField();
27 | t2=new TextField();
28 | t3=new TextField();
29 | t4=new TextField();
30 | t5=new TextField();
31 | t6=new TextField();
32 | t7=new TextField();
33 | t8=new TextField();
34 | t9=new TextField();
35 | c1=new Checkbox("Owner");
36 | cbg=new CheckboxGroup();
37 | c2=new Checkbox("Regular",true,cbg);
38 | c3=new Checkbox("Staff",false,cbg);
39 | add(c1);add(c2);add(c3);
40 | add(t1);add(t2);add(t3);add(t4);add(t5);add(t6);add(t7);add(t8);add(t9);
41 | add(b1);add(b2);
42 | add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);add(l8);add(l9);
43 | t4.setEditable(false);
44 | t5.setEditable(false);
45 | t6.setEditable(false);
46 | t7.setEditable(false);
47 | t8.setEditable(false);
48 | t9.setEditable(false);
49 | b1.addActionListener(this);
50 | b2.addActionListener(this);
51 | l1.setBounds(200,10,250,30);
52 | l2.setBounds(150,50,100,20);
53 | l3.setBounds(30,80,100,20);
54 | l4.setBounds(30,120,100,20);
55 | l5.setBounds(30,160,100,20);
56 | l6.setBounds(420,50,100,20);
57 | l7.setBounds(300,200,100,20);
58 | l8.setBounds(300,240,100,20);
59 | l9.setBounds(300,280,100,20);
60 | b1.setBounds(100,340,100,30);
61 | b2.setBounds(290,340,100,30);
62 | t1.setBounds(150,80,100,20);
63 | t2.setBounds(150,120,100,20);
64 | t3.setBounds(150,160,100,20);
65 | t4.setBounds(420,80,100,20);
66 | t5.setBounds(420,120,100,20);
67 | t6.setBounds(420,160,100,20);
68 | t7.setBounds(420,200,100,20);
69 | t8.setBounds(420,240,100,20);
70 | t9.setBounds(420,280,100,20);
71 | c1.setBounds(150,200,130,20);
72 | c2.setBounds(150,240,130,20);
73 | c3.setBounds(150,280,130,20);
74 | }
75 | public void actionPerformed(ActionEvent ae)
76 | { try
77 | { str=ae.getActionCommand();
78 | if(str.equals("Calculate Bill"))
79 | { p=Double.parseDouble(t1.getText());
80 | d=Double.parseDouble(t2.getText());
81 | ch=Double.parseDouble(t3.getText());
82 | a=p*60;
83 | b=d*50;
84 | c=ch*40;
85 | tm=a+b+c;
86 | if(c1.getState()==true)
87 | { t4.setText(""+a);
88 | t5.setText(""+b);
89 | t6.setText(""+c);
90 | t7.setText(""+tm);
91 | t8.setText(""+tm);
92 | t9.setText("0");
93 | }
94 | else
95 | { if(c2.getState()==true)
96 | dis=tm*0.05;
97 | else if(c3.getState()==true)
98 | dis=tm*0.07;
99 | np=tm-dis;
100 | t4.setText(""+a);
101 | t5.setText(""+b);
102 | t6.setText(""+c);
103 | t7.setText(""+tm);
104 | t8.setText(""+dis);
105 | t9.setText(""+np);
106 | }
107 | }
108 | else if(str.equals("Clear Entries"))
109 | { t1.setText("");
110 | t2.setText("");
111 | t3.setText("");
112 | t4.setText("");
113 | t5.setText("");
114 | t6.setText("");
115 | t7.setText("");
116 | t8.setText("");
117 | t9.setText("");
118 | }
119 | }
120 | catch(Exception e)
121 | {}
122 | }
123 | public void paint(Graphics g)
124 | { setSize(550,400);
125 | }
126 | }
127 |
128 |
--------------------------------------------------------------------------------
/Metro_Ticket_Charges.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Metro_Ticket_Charges extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5;
6 | Button b1,b2,b3;
7 | TextField t1,t2,t3,t4;
8 | int a,b,c,f;
9 | String str;
10 | public void init()
11 | { setLayout(null);
12 | l1=new Label("Metro Ticket Charges");
13 | l2=new Label("No. of passengers aged 18 and above");
14 | l3=new Label("No. of passengers b/w 5 and 18");
15 | l4=new Label("No. of passengers below 5");
16 | l5=new Label("Total Fare");
17 | b1=new Button("Fare");
18 | b2=new Button("Clear");
19 | b3=new Button("Exit");
20 | t1=new TextField();
21 | t2=new TextField();
22 | t3=new TextField();
23 | t4=new TextField();
24 | add(t1);add(t2);add(t3);add(t4);
25 | add(b1);add(b2);add(b3);
26 | add(l1);add(l2);add(l3);add(l4);add(l5);
27 | t4.setEditable(false);
28 | b1.addActionListener(this);
29 | b2.addActionListener(this);
30 | b3.addActionListener(this);
31 | l1.setBounds(250,20,200,30);
32 | l2.setBounds(20,80,300,20);
33 | l3.setBounds(20,120,300,20);
34 | l4.setBounds(20,160,300,20);
35 | l5.setBounds(450,80,100,20);
36 | b1.setBounds(360,80,70,30);
37 | b2.setBounds(360,120,70,30);
38 | b3.setBounds(360,160,70,30);
39 | t1.setBounds(250,80,70,20);
40 | t2.setBounds(250,120,70,20);
41 | t3.setBounds(250,160,70,20);
42 | t4.setBounds(530,80,70,20);
43 | }
44 | public void actionPerformed(ActionEvent ae)
45 | { try
46 | { str=ae.getActionCommand();
47 | if(str.equals("Fare"))
48 | { a=Integer.parseInt(t1.getText());
49 | b=Integer.parseInt(t2.getText());
50 | c=Integer.parseInt(t3.getText());
51 | f=a*15+b*10+c*5;
52 | t4.setText(""+f);
53 | }
54 | else if(str.equals("Clear"))
55 | { t1.setText("");
56 | t2.setText("");
57 | t3.setText("");
58 | t4.setText("");
59 | }
60 | else if(str.equals("Exit"))
61 | System.exit(0);
62 | }
63 | catch(Exception e)
64 | {}
65 | }
66 | public void paint(Graphics g)
67 | { setSize(650,200);
68 | }
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/Mind_Reading_Game.java:
--------------------------------------------------------------------------------
1 | //Mind Reading Game
2 | /*
3 | PLAYING INSTRUCTIONS
4 | 1. Pick a number (between 10 and 99)
5 | 2. Add their digits together. (ie. 71=7+1)
6 | 3. Subtract the sum from the original number. (71-8=63)
7 | 4. Find your answer in the chart.
8 | 5. Look at the symbol.
9 | 6. Click the Cookie button!
10 | */
11 | import java.applet.*;
12 | import java.awt.*;
13 | import java.awt.event.*;
14 | import javax.swing.*;
15 | import java.util.Random;
16 | /**/
18 | public class Mind_Reading_Game extends JApplet implements MouseListener
19 | { int x,y,x2,y2,i,v,f;
20 | String s[]={"%","‡","#","$","&","∂","ß","¢","§","•","¥","π","©","Ø","µ","∆","¿","◊","M","R","C"};
21 | String a;
22 | private JPanel panel;
23 | public void init()
24 | { addMouseListener(this);
25 | requestFocus();
26 | y2=25;
27 | Random r=new Random();
28 | v=r.nextInt(21);
29 | a=s[v];
30 | panel = new JPanel()
31 | { protected void paintComponent(Graphics g)
32 | { super.paintComponent(g);
33 | try
34 | { setBackground(Color.white);
35 | Font fobj=new Font("Arial",Font.BOLD,24);
36 | Font fobj1=new Font("Arial",Font.BOLD,14);
37 | Font fobj2=new Font("Arial",Font.BOLD,44);
38 | Color cobj=new Color(101,80,33);
39 | Color cobj1=new Color(136,107,47);
40 | g.setFont(fobj);
41 | g.drawString("MIND",290,50);
42 | g.drawString("READING",270,90);
43 | g.drawString("COOKIE",280,130);
44 | g.setColor(cobj);
45 | g.fillOval(275,165,110,110);
46 | g.setColor(cobj1);
47 | g.fillOval(280,170,100,100);
48 | g.setColor(Color.gray);
49 | g.fillRect(280,310,100,50);
50 | g.setColor(Color.black);
51 | g.drawRect(279,309,101,51);
52 | g.setFont(fobj1);
53 | g.drawString("Instriuctions",290,325);
54 | g.drawString("READ FIRST",290,345);
55 | x2=20;
56 | if(x>=270&&x<=370&&y>=170&&y<=270)
57 | { g.setFont(fobj2);
58 | g.drawString(""+a,315,230);
59 | f=1;
60 | }
61 | if(f==0)
62 | { for(i=1;i<26;i++)
63 | { g.drawString(""+i+"=",x2,y2);
64 | if(i!=1&&i!=9&&i!=18)
65 | { Random r=new Random();
66 | v=r.nextInt(21);
67 | g.drawString(""+s[v],x2+30,y2);
68 | }
69 | else
70 | g.drawString(""+a,x2+30,y2);
71 | y2=y2+15;
72 | }
73 | if(i==26)
74 | { y2=25;
75 | x2=80;
76 | }
77 | for(i=26;i<51;i++)
78 | { g.drawString(""+i+"=",x2,y2);
79 | if(i!=27&&i!=36&&i!=45)
80 | { Random r=new Random();
81 | v=r.nextInt(21);
82 | g.drawString(""+s[v],x2+30,y2);
83 | }
84 | else
85 | g.drawString(""+a,x2+30,y2);
86 | y2=y2+15;
87 | }
88 | if(i==51)
89 | { y2=25;
90 | x2=140;
91 | }
92 | for(i=51;i<76;i++)
93 | { g.drawString(""+i+"=",x2,y2);
94 | if(i!=54&&i!=63&&i!=72)
95 | { Random r=new Random();
96 | v=r.nextInt(21);
97 | g.drawString(""+s[v],x2+30,y2);
98 | }
99 | else
100 | g.drawString(""+a,x2+30,y2);
101 | y2=y2+15;
102 | }
103 | if(i==76)
104 | { y2=25;
105 | x2=200;
106 | }
107 | for(i=76;i<100;i++)
108 | { g.drawString(""+i+"=",x2,y2);
109 | if(i!=81&&i!=99)
110 | { Random r=new Random();
111 | v=r.nextInt(21);
112 | g.drawString(""+s[v],x2+30,y2);
113 | }
114 | else
115 | g.drawString(""+a,x2+30,y2);
116 | y2=y2+15;
117 | }
118 | if(i==100)
119 | { y2=25;
120 | x2=260;
121 | }
122 | }
123 | }
124 | catch(Exception e)
125 | {}
126 | }
127 | };
128 | add(panel);
129 | }
130 | public void mouseClicked(MouseEvent me)
131 | { x=me.getX();
132 | y=me.getY();
133 | if(x>=270&&x<=370&&y>=170&&y<=270)
134 | repaint();
135 | }
136 | public void mousePressed(MouseEvent me)
137 | {}
138 | public void mouseReleased(MouseEvent me)
139 | {}
140 | public void mouseEntered(MouseEvent me)
141 | {}
142 | public void mouseExited(MouseEvent me)
143 | {}
144 | public void paint(Graphics g)
145 | { super.paint(g);
146 | setSize(400,400);
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/Pong_Game.java:
--------------------------------------------------------------------------------
1 | //Pong Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Pong_Game extends JApplet implements KeyListener
9 | { int x=238,y=333,k,a1=0,b1=0,a=2,b=0,c=0,d=0,x1=203,y1=343,x2,y2,e=0,z=0,s,f=0;
10 | private JPanel panel;
11 | public void init()
12 | { addKeyListener(this);
13 | requestFocus();
14 | y=326;
15 | y2=3;
16 | panel = new JPanel()
17 | { protected void paintComponent(Graphics g)
18 | { super.paintComponent(g);
19 | try
20 | { showStatus(" SCORE = "+s);
21 | Color cobj=new Color(10,131,231);
22 | Font fobj=new Font("Arial",Font.BOLD,20);
23 | Font fobj1=new Font("Arial",Font.BOLD,25);
24 | setBackground(cobj);
25 | if(f==1)
26 | { setBackground(cobj);
27 | g.setFont(fobj);
28 | g.setColor(Color.BLACK);
29 | g.drawString("GAME OVER",133,173);
30 | g.setColor(Color.WHITE);
31 | g.drawString("GAME OVER",130,170);
32 | }
33 | else
34 | { if(z==0)
35 | { g.setFont(fobj1);
36 | g.setColor(Color.BLACK);
37 | g.drawString("PONG GAME",123,133);
38 | g.setColor(Color.WHITE);
39 | g.drawString("PONG GAME",120,130);
40 | }
41 | g.setColor(Color.BLACK);
42 | g.fillOval(x+3,y+3,15,15);
43 | g.setColor(Color.WHITE);
44 | g.fillOval(x,y,15,15);
45 | x2=x;
46 | if(x>=368)
47 | x2=368;
48 | else if(x<=43)
49 | x2=43;
50 | g.setColor(Color.BLACK);
51 | g.fillOval(x+3,y+3,15,15);
52 | g.setColor(Color.WHITE);
53 | g.fillOval(x,y,15,15);
54 | g.setColor(Color.BLACK);
55 | g.fillRoundRect(x1+3,y1+3,80,5,5,5);
56 | g.fillRoundRect(x2-40+3,y2+3,80,5,5,5);
57 | g.setColor(Color.WHITE);
58 | g.fillRoundRect(x1,y1,80,5,5,5);
59 | g.fillRoundRect(x2-40,y2,80,5,5,5);
60 | if(x2==43)
61 | x2=3;
62 | Thread.sleep(15);
63 | if(y==333)
64 | { if(a==0&&b==0&&c==0&&d==0&&y1==y+10&&x>=x1&&x<=x1+80)
65 | { a1=5;
66 | b1=-5;
67 | a=1;
68 | }
69 | else if(a==1&&b==0&&c==0&&d==0&&y1==y+10&&x>=x1&&x<=x1+80)
70 | { a1=-5;
71 | b1=-5;
72 | b=1;
73 | }
74 | else if(a==1&&b==1&&c==1&&d==1&&x!=403&&y1==y+10&&x>=x1&&x<=x1+80)
75 | { a1=5;
76 | b1=-5;
77 | b=0;
78 | c=0;
79 | d=0;
80 | }
81 | else if(a==1&&b==1&&c==1&&d==1&&x==403&&y1==y+10&&x>=x1&&x<=x1+80)
82 | { a1=-5;
83 | b1=-5;
84 | c=0;
85 | d=0;
86 | }
87 | else if(a==1&&b==1&&c==1&&d==0&&x==3&&y1==y&&x>=x1&&x<=x1+80)
88 | { a1=5;
89 | b1=-5;
90 | b=0;
91 | c=0;
92 | d=0;
93 | }
94 | else if(a==1&&b==1&&c==1&&d==0&&x!=3&&y1==y+10&&x>=x1&&x<=x1+80)
95 | { a1=-5;
96 | b1=-5;
97 | b=1;
98 | c=0;
99 | }
100 | else
101 | f=1;
102 | }
103 | else if(x==403)
104 | { if(a==1&&b==0&&c==0&&d==0)
105 | { a1=-5;
106 | b1=-5;
107 | b=1;
108 | }
109 | else if(a==1&&b==1&&c==1&&d==1)
110 | { a1=-5;
111 | b1=5;
112 | d=0;
113 | b=0;
114 | c=0;
115 | }
116 | else if(a==1&&b==0&&c==1&&d==1)
117 | { a1=-5;
118 | b1=5;
119 | d=0;
120 | c=0;
121 | }
122 | else if(a==1&&b==0&&c==0&&d==1)
123 | { a1=-5;
124 | b1=-5;
125 | d=0;
126 | }
127 | else
128 | f=1;
129 | }
130 | else if(y==3)
131 | { if(a==1&&b==1&&c==0&&d==0&&y2==y&&x>=x2&&x<=x2+80)
132 | { a1=-5;
133 | b1=5;
134 | c=1;
135 | }
136 | else if(a==1&&b==1&&c==0&&d==1&&y2==y&&x>=x2&&x<=x2+80)
137 | { a1=5;
138 | b1=5;
139 | c=1;
140 | }
141 | else if(a==1&&b==0&&c==0&&d==0&&y2==y&&x>=x2&&x<=x2+80)
142 | { a1=5;
143 | b1=5;
144 | c=1;
145 | d=1;
146 | }
147 | else
148 | f=1;
149 | }
150 | else if(x==3)
151 | { if(a==1&&b==1&&c==1&&d==0)
152 | { a1=5;
153 | b1=5;
154 | a=0;
155 | b=0;
156 | c=0;
157 | }
158 | else if(a==1&&b==1&&c==0&&d==0)
159 | { a1=5;
160 | b1=-5;
161 | d=1;
162 | }
163 | else if(a==1&&b==0&&c==1&&d==0)
164 | { a1=-5;
165 | b1=5;
166 | b=1;
167 | d=1;
168 | }
169 | else
170 | f=1;
171 | }
172 | if(z>0)
173 | s++;
174 | x=x+a1;
175 | y=y+b1;
176 | if(x1==3&&k==39)
177 | x1=x1+e;
178 | else if(x1==323&&k==37)
179 | x1=x1+e;
180 | else if(x1>3&&x1<323)
181 | { x1=x1+e;
182 | repaint();
183 | }
184 | repaint();
185 | }
186 | }
187 | catch(Exception e)
188 | {}
189 | }
190 | };
191 | add(panel);
192 | }
193 | public void keyPressed(KeyEvent ke)
194 | { k=ke.getKeyCode();
195 | if(k==38)
196 | { if(z==0)
197 | { a=0;
198 | z++;
199 | y=333;
200 | }
201 | }
202 | if(k==37)
203 | { if(z==0)
204 | { a=0;
205 | z++;
206 | e=-5;
207 | y=333;
208 | }
209 | else
210 | e=-5;
211 | }
212 | if(k==39)
213 | { if(z==0)
214 | { a=0;
215 | z++;
216 | e=5;
217 | y=333;
218 | }
219 | else
220 | e=5;
221 | }
222 | repaint();
223 | }
224 | public void keyReleased(KeyEvent ke)
225 | {}
226 | public void keyTyped(KeyEvent ke)
227 | {}
228 | public void paint(Graphics g)
229 | { super.paint(g);
230 | setSize(410,360);
231 | }
232 | }
233 |
234 |
--------------------------------------------------------------------------------
/Quiz.java:
--------------------------------------------------------------------------------
1 | //Quiz
2 | import java.awt.*;
3 | import java.applet.*;
4 | import java.awt.event.*;
5 | /*
7 | */
8 | public class Quiz extends Applet implements ActionListener,ItemListener
9 | { String msg="",s1="",ans="";
10 | int c=0,q1,q2,q3,q4,q5,t=0;
11 | Label l1,l2,l3,l4,l5;
12 | Checkbox c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20;
13 | CheckboxGroup cbg,cbg1,cbg2,cbg3,cbg4;
14 | public void init()
15 | { setLayout(null);
16 | Button b1=new Button("Submit");
17 | add(b1);
18 | b1.addActionListener(this);
19 | l1=new Label("What is output of 5*1=?");
20 | l2=new Label("What is output of 5*2=?");
21 | l3=new Label("What is output of 5*3=?");
22 | l4=new Label("What is output of 5*4=?");
23 | l5=new Label("What is output of 5*5=?");
24 | cbg=new CheckboxGroup();
25 | cbg1=new CheckboxGroup();
26 | cbg2=new CheckboxGroup();
27 | cbg3=new CheckboxGroup();
28 | cbg4=new CheckboxGroup();
29 | c1=new Checkbox("5",false,cbg);
30 | c2=new Checkbox("10",false,cbg);
31 | c3=new Checkbox("15",false,cbg);
32 | c4=new Checkbox("20",false,cbg);
33 | c5=new Checkbox("10",false,cbg1);
34 | c6=new Checkbox("5",false,cbg1);
35 | c7=new Checkbox("15",false,cbg1);
36 | c8=new Checkbox("20",false,cbg1);
37 | c9=new Checkbox("15",false,cbg2);
38 | c10=new Checkbox("5",false,cbg2);
39 | c11=new Checkbox("15",false,cbg2);
40 | c12=new Checkbox("20",false,cbg2);
41 | c13=new Checkbox("20",false,cbg3);
42 | c14=new Checkbox("5",false,cbg3);
43 | c15=new Checkbox("15",false,cbg3);
44 | c16=new Checkbox("20",false,cbg3);
45 | c17=new Checkbox("25",false,cbg4);
46 | c18=new Checkbox("10",false,cbg4);
47 | c19=new Checkbox("15",false,cbg4);
48 | c20=new Checkbox("20",false,cbg4);
49 | add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);add(c7);add(c8);add(c9);add(c10);add(c11);add(c12);add(c13);add(c14);add(c15);add(c16);
50 | add(c17);add(c18);add(c19);add(c20);
51 | c1.addItemListener(this);
52 | c2.addItemListener(this);
53 | c3.addItemListener(this);
54 | c4.addItemListener(this);
55 | c5.addItemListener(this);
56 | c6.addItemListener(this);
57 | c7.addItemListener(this);
58 | c8.addItemListener(this);
59 | c9.addItemListener(this);
60 | c10.addItemListener(this);
61 | c11.addItemListener(this);
62 | c12.addItemListener(this);
63 | c13.addItemListener(this);
64 | c14.addItemListener(this);
65 | c15.addItemListener(this);
66 | c16.addItemListener(this);
67 | c17.addItemListener(this);
68 | c18.addItemListener(this);
69 | c19.addItemListener(this);
70 | c20.addItemListener(this);
71 | b1.setBounds(200,400,80,20);
72 | c1.setBounds(50,70,100,20);
73 | c2.setBounds(150,70,100,20);
74 | c3.setBounds(250,70,100,20);
75 | c4.setBounds(350,70,100,20);
76 | c5.setBounds(50,120,100,20);
77 | c6.setBounds(150,120,100,20);
78 | c7.setBounds(250,120,100,20);
79 | c8.setBounds(350,120,100,20);
80 | c9.setBounds(50,170,100,20);
81 | c10.setBounds(150,170,100,20);
82 | c11.setBounds(250,170,100,20);
83 | c12.setBounds(350,170,100,20);
84 | c13.setBounds(50,220,100,20);
85 | c14.setBounds(150,220,100,20);
86 | c15.setBounds(250,220,100,20);
87 | c16.setBounds(350,220,100,20);
88 | c17.setBounds(50,270,100,20);
89 | c18.setBounds(150,270,100,20);
90 | c19.setBounds(250,270,100,20);
91 | c20.setBounds(350,270,100,20);
92 | }
93 | public void itemStateChanged(ItemEvent ie)
94 | {
95 | repaint();
96 | c=1;
97 | }
98 | public void actionPerformed(ActionEvent ae)
99 | {
100 | String s=ae.getActionCommand();
101 | if(s.equals("Submit"))
102 | { t = q1 + q2 + q3 + q4 + q5;
103 | }
104 | repaint();
105 | }
106 | public void paint(Graphics g)
107 | { g.drawString(l1.getText(),50,60);
108 | g.drawString(l2.getText(),50,110);
109 | g.drawString(l3.getText(),50,160);
110 | g.drawString(l4.getText(),50,210);
111 | g.drawString(l5.getText(),50,260);
112 | g.drawString("Total Score = "+t,550,50);
113 | if(c==1)
114 | { if(cbg.getSelectedCheckbox().getLabel()=="5")
115 | q1=1;
116 | else
117 | q1=0;
118 | if(cbg1.getSelectedCheckbox().getLabel()=="10")
119 | q2=1;
120 | else
121 | q2=0;
122 | if(cbg2.getSelectedCheckbox().getLabel()=="15")
123 | q3=1;
124 | else
125 | q3=0;
126 | if(cbg3.getSelectedCheckbox().getLabel()=="20")
127 | q4=1;
128 | else
129 | q4=0;
130 | if(cbg4.getSelectedCheckbox().getLabel()=="25")
131 | q5=1;
132 | else
133 | q5=0;
134 |
135 | }
136 | showStatus(" "+q1+""+q2+" "+q3+""+q4+""+q5);
137 | }
138 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java-Game-and-Application
2 | Java Games and Application with awesome source code and better algorithm
3 |
--------------------------------------------------------------------------------
/Rapid_Roll_Game.java:
--------------------------------------------------------------------------------
1 | //Rapid Roll Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Rapid_Roll_Game extends JApplet implements KeyListener
9 | { int k,a=0,f=0,z=0,s=0,x=100,y=200,x1=90,y1=200,x2=130,y2=250,x3=50,y3=300,x4=110,y4=350,x5=70,y5=400,x6=30,y6=450,x7=150,y7=500;
10 | private JPanel panel;
11 | public void init()
12 | { addKeyListener(this);
13 | requestFocus();
14 | panel = new JPanel()
15 | { protected void paintComponent(Graphics g)
16 | { super.paintComponent(g);
17 | setBackground(Color.CYAN);
18 | try
19 | { Font fobj=new Font("Arial",Font.BOLD,26);
20 | Font fobj1=new Font("Arial",Font.ITALIC,20);
21 | if(f==1)
22 | { g.setFont(fobj);
23 | g.drawString("out!",80,170);
24 | }
25 | else
26 | { g.setColor(Color.RED);
27 | g.fillOval(x,y,10,10);
28 | g.setColor(Color.GRAY);
29 | g.fillRect(x1,y1+10,20,5);
30 | g.fillRect(x2,y2+10,20,5);
31 | g.fillRect(x3,y3+10,20,5);
32 | g.fillRect(x4,y4+10,20,5);
33 | g.fillRect(x5,y5+10,20,5);
34 | g.fillRect(x6,y6+10,20,5);
35 | g.fillRect(x7,y7+10,20,5);
36 | if(z==0)
37 | { g.setFont(fobj1);
38 | g.setColor(Color.MAGENTA);
39 | g.drawString("RAPIDROLL GAME",10,60);
40 | }
41 | else
42 | { if(x>=80&&x<=110&&y==y1)
43 | { y=y1;
44 | y=y-1;
45 | repaint();
46 | Thread.sleep(15);
47 | }
48 | else if(x>=120&&x<=150&&y==y2)
49 | { y=y2;
50 | y=y-1;
51 | repaint();
52 | Thread.sleep(15);
53 | }
54 | else if(x>=40&&x<=70&&y==y3)
55 | { y=y3;
56 | y=y-1;
57 | repaint();
58 | Thread.sleep(15);
59 | }
60 | else if(x>=100&&x<=130&&y==y4)
61 | { y=y4;
62 | y=y-1;
63 | repaint();
64 | Thread.sleep(15);
65 | }
66 | else if(x>=60&&x<=90&&y==y5)
67 | { y=y5;
68 | y=y-1;
69 | repaint();
70 | Thread.sleep(15);
71 | }
72 | else if(x>=20&&x<=50&&y==y6)
73 | { y=y6;
74 | y=y-1;
75 | repaint();
76 | Thread.sleep(15);
77 | }
78 | else if(x>=140&&x<=170&&y==y7)
79 | { y=y7;
80 | y=y-1;
81 | repaint();
82 | Thread.sleep(15);
83 | }
84 | else
85 | { y=y+1;
86 | a=0;
87 | Thread.sleep(15);
88 | repaint();
89 | }
90 | y1=y1-1;
91 | y2=y2-1;
92 | y3=y3-1;
93 | y4=y4-1;
94 | y5=y5-1;
95 | y6=y6-1;
96 | y7=y7-1;
97 | if(y1==-10)
98 | y1=400;
99 | if(y2==-10)
100 | y2=450;
101 | if(y3==-10)
102 | y3=500;
103 | if(y4==-10)
104 | y4=550;
105 | if(y5==-10)
106 | y5=600;
107 | if(y6==-10)
108 | y6=650;
109 | if(y7==-10)
110 | y7=700;
111 | if(y==0||y==355)
112 | f=1;
113 | s++;
114 | showStatus( "SCORE = "+s);
115 | }
116 | }
117 | }
118 | catch(Exception e)
119 | {}
120 | }
121 | };
122 | add(panel);
123 | }
124 | public void keyPressed(KeyEvent ke)
125 | { k=ke.getKeyCode();
126 | if(k==37)
127 | { x=x-2;
128 | z=1;
129 | }
130 | else if(k==39)
131 | { x=x+2;
132 | z=1;
133 | }
134 | repaint();
135 | }
136 | public void keyReleased(KeyEvent ke)
137 | {}
138 | public void keyTyped(KeyEvent ke)
139 | {}
140 | public void paint(Graphics g)
141 | { super.paint(g);
142 | setSize(200,350);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/Reach_to_Destination.java:
--------------------------------------------------------------------------------
1 | //Reach to Destination
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Reach_to_Destination extends JApplet implements KeyListener
9 | { int x=180,y=360,f=0;
10 | int a[]=new int[9];
11 | int b[]=new int[9];
12 | private JPanel panel;
13 | public void init()
14 | { addKeyListener(this);
15 | requestFocus();
16 | a[0]=300;
17 | b[0]=320;
18 | a[1]=100;
19 | b[1]=280;
20 | a[2]=321;
21 | b[2]=240;
22 | a[3]=80;
23 | b[3]=200;
24 | a[4]=261;
25 | b[4]=160;
26 | a[5]=150;
27 | b[5]=120;
28 | a[6]=240;
29 | b[6]=80;
30 | a[7]=20;
31 | b[7]=40;
32 | panel = new JPanel()
33 | { protected void paintComponent(Graphics g)
34 | { super.paintComponent(g);
35 | try
36 | { if(f==1)
37 | g.drawString("GAME OVER",120,180);
38 | else if(f==2)
39 | g.drawString("YOU WIN",120,180);
40 | else
41 | { setBackground(Color.CYAN);
42 | g.setColor(Color.BLUE);
43 | g.fillOval(x,y,10,10);
44 | g.setColor(Color.RED);
45 | g.fillRect(a[0],b[0]+10,40,5);
46 | g.fillRect(a[1],b[1]+10,40,5);
47 | g.fillRect(a[2],b[2]+10,40,5);
48 | g.fillRect(a[3],b[3]+10,40,5);
49 | g.fillRect(a[4],b[4]+10,40,5);
50 | g.fillRect(a[5],b[5]+10,40,5);
51 | g.fillRect(a[6],b[6]+10,40,5);
52 | g.fillRect(a[7],b[7]+10,40,5);
53 | if(x>=a[0]-5&&x<=a[0]+40&&y==b[0])
54 | { x=x-1;
55 | if(x<=1)
56 | x=2;
57 | repaint();
58 | Thread.sleep(50);
59 | }
60 | else if(x>=a[1]-5&&x<=a[1]+40&&y==b[1])
61 | { x=x+2;
62 | if(x>=350)
63 | x=348;
64 | repaint();
65 | Thread.sleep(50);
66 | }
67 | else if(x>=a[2]-5&&x<=a[2]+40&&y==b[2])
68 | { x=x+3;
69 | if(x>=351)
70 | x=348;
71 | repaint();
72 | Thread.sleep(50);
73 | }
74 | else if(x>=a[3]-5&&x<=a[3]+40&&y==b[3])
75 | { x=x-1;
76 | if(x<=1)
77 | x=2;
78 | repaint();
79 | Thread.sleep(50);
80 | }
81 | else if(x>=a[4]-5&&x<=a[4]+40&&y==b[4])
82 | { x=x-3;
83 | if(x<=0)
84 | x=3;
85 | repaint();
86 | Thread.sleep(50);
87 | }
88 | else if(x>=a[5]-5&&x<=a[5]+40&&y==b[5])
89 | { x=x+2;
90 | if(x>=350)
91 | x=348;
92 | repaint();
93 | Thread.sleep(50);
94 | }
95 | else if(x>=a[6]-5&&x<=a[6]+40&&y==b[6])
96 | { x=x-2;
97 | if(x<=0)
98 | x=2;
99 | repaint();
100 | Thread.sleep(50);
101 | }
102 | else if(x>=a[7]-5&&x<=a[7]+40&&y==b[7])
103 | { x=x+1;
104 | if(x>=350)
105 | x=349;
106 | repaint();
107 | Thread.sleep(50);
108 | }
109 | else if(y==360)
110 | repaint();
111 | else if(y==0)
112 | f=2;
113 | else
114 | f=1;
115 | a[0]=a[0]-1;
116 | a[1]=a[1]+2;
117 | a[2]=a[2]+3;
118 | a[3]=a[3]-1;
119 | a[4]=a[4]-3;
120 | a[5]=a[5]+2;
121 | a[6]=a[6]-2;
122 | a[7]=a[7]+1;
123 | if(a[0]==-40)
124 | a[0]=360;
125 | if(a[1]==360)
126 | a[1]=-40;
127 | if(a[2]==360)
128 | a[2]=-39;
129 | if(a[3]==-40)
130 | a[3]=360;
131 | if(a[4]==-39)
132 | a[4]=360;
133 | if(a[5]==360)
134 | a[5]=-40;
135 | if(a[6]==-40)
136 | a[6]=360;
137 | if(a[7]==360)
138 | a[7]=-40;
139 | Thread.sleep(50);
140 | repaint();
141 | }
142 | }
143 | catch(Exception e)
144 | {}
145 | }
146 | };
147 | add(panel);
148 | }
149 | public void keyPressed(KeyEvent ke)
150 | { int k=ke.getKeyCode();
151 | if(k==37)
152 | { x=x-1;
153 | if(x<=1)
154 | x=2;
155 | }
156 | else if(k==38)
157 | { y=y-40;
158 | if(y==-40)
159 | y=0;
160 | }
161 | else if(k==39)
162 | { x=x+1;
163 | if(x>=350)
164 | x=348;
165 | }
166 | else if(k==40)
167 | { y=y+40;
168 | if(y==400)
169 | y=360;
170 | }
171 | repaint();
172 | }
173 | public void keyReleased(KeyEvent ke)
174 | {}
175 | public void keyTyped(KeyEvent ke)
176 | {}
177 | public void paint(Graphics g)
178 | { setSize(358,380);
179 | super.paint(g);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/Shadow_Game.java:
--------------------------------------------------------------------------------
1 | //Shadow Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /**/
9 | public class Shadow_Game extends JApplet implements MouseListener
10 | { int c,c1,c2,s,x1,x2,f;
11 | int tx[]={-10,500,500};
12 | int ty[]={500,200,500};
13 | int sx[]={315,355,398,355};
14 | int sy[]={230,285,259,200};
15 | private JPanel panel;
16 | public void init()
17 | { addMouseListener(this);
18 | x1=-15;
19 | x2=-320;
20 | panel = new JPanel()
21 | { protected void paintComponent(Graphics g)
22 | { try
23 | { super.paintComponent(g);
24 | if(f==0)
25 | { if(c%2==0)
26 | { Color cobj1=new Color(205,205,205);
27 | setBackground(cobj1);
28 | g.setColor(Color.black);
29 | g.fillPolygon(sx,sy,4);
30 | g.setColor(Color.white);
31 | g.fillPolygon(tx,ty,3);
32 | g.fillOval(335,235,10,10);
33 | g.fillOval(350,225,10,10);
34 | g.setColor(Color.gray);
35 | Font fobj=new Font("Arial",Font.BOLD,17);
36 | g.setFont(fobj);
37 | g.drawString("SCORE = "+s,250,15);
38 | }
39 | if(c%2==1)
40 | { Color cobj2=new Color(55,55,55);
41 | setBackground(cobj2);
42 | g.setColor(Color.white);
43 | g.fillPolygon(sx,sy,4);
44 | g.setColor(Color.black);
45 | g.fillPolygon(tx,ty,3);
46 | g.fillOval(335,235,10,10);
47 | g.fillOval(350,225,10,10);
48 | g.setColor(Color.gray);
49 | Font fobj=new Font("Arial",Font.BOLD,17);
50 | g.setFont(fobj);
51 | g.drawString("SCORE = "+s,250,15);
52 | }
53 | if(c1==0)
54 | { g.setColor(Color.black);
55 | g.fillRect(x1,0,15,500);
56 | }
57 | if(c1==1)
58 | { g.setColor(Color.white);
59 | g.fillRect(x1,0,15,500);
60 | }
61 | if(c2==0)
62 | { g.setColor(Color.black);
63 | g.fillRect(x2,0,15,500);
64 | }
65 | if(c2==1)
66 | { g.setColor(Color.white);
67 | g.fillRect(x2,0,15,500);
68 | }
69 | x1++;
70 | x2++;
71 | if(x1>510)
72 | { x1=-155;
73 | Random r=new Random();
74 | c1=r.nextInt(2);
75 | s++;
76 | }
77 | if(x2>510)
78 | { x2=-155;
79 | Random r=new Random();
80 | c2=r.nextInt(2);
81 | s++;
82 | }
83 | if(x1==320&&c1==0&&c%2==1)
84 | { f=1;
85 | Thread.sleep(2000);
86 | }
87 | if(x1==320&&c1==1&&c%2==0)
88 | { f=1;
89 | Thread.sleep(2000);
90 | }
91 | if(x2==320&&c2==0&&c%2==1)
92 | { f=1;
93 | Thread.sleep(2000);
94 | }
95 | if(x2==320&&c2==1&&c%2==0)
96 | { f=1;
97 | Thread.sleep(2000);
98 | }
99 | Thread.sleep(3);
100 | repaint();
101 | }
102 | if(f==1)
103 | { setBackground(Color.gray);
104 | Font fobj1=new Font("Arial",Font.BOLD,22);
105 | g.setFont(fobj1);
106 | g.setColor(Color.white);
107 | g.drawString("GAME OVER",210,220);
108 | g.drawString("SCORE = "+s,210,250);
109 | }
110 | //showStatus(" x1="+x1+" f="+f);
111 | }
112 | catch(Exception e)
113 | {}
114 | }
115 | };
116 | add(panel);
117 | }
118 | public void mouseClicked(MouseEvent me)
119 | { c++;
120 | repaint();
121 | }
122 | public void mousePressed(MouseEvent me)
123 | {}
124 | public void mouseReleased(MouseEvent me)
125 | {}
126 | public void mouseEntered(MouseEvent me)
127 | {}
128 | public void mouseExited(MouseEvent me)
129 | {}
130 | public void paint(Graphics g)
131 | { setSize(500,500);
132 | super.paint(g);
133 | }
134 | }
--------------------------------------------------------------------------------
/Shoot_the_Box.java:
--------------------------------------------------------------------------------
1 | //Shoot the Box
2 | import java.awt.*;
3 | import java.applet.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | public class Shoot_the_Box extends JApplet implements MouseListener,MouseMotionListener
8 | { int x,y,w,z,a,b,c,c1,x1,y1,e,f,s,count;
9 | double m,m1,i,j,i1,j1,a1,e1;
10 | private JPanel panel;
11 | public void init()
12 | { addMouseListener(this);
13 | addMouseMotionListener(this);
14 | a=90;
15 | b=290;
16 | x=100;
17 | y=300;
18 | e=300;
19 | f=100;
20 | panel = new JPanel()
21 | { protected void paintComponent(Graphics g)
22 | { super.paintComponent(g);
23 | try
24 | { Color c11=new Color(153,217,234);
25 | Color c21=new Color(0,162,232);
26 | Graphics2D g2 = (Graphics2D) g;
27 | g2.setPaint(new GradientPaint(0,0,c11,200,200,c21,true));
28 | Rectangle r1 = new Rectangle(0,0,500,400);
29 | g2.fill(r1);
30 | g.setColor(Color.BLACK);
31 | g.drawLine(100,0,100,400);
32 | g.drawLine(0,300,500,300);
33 | g.fillOval(a,b,20,20);
34 | g.drawRect(e,f,40,40);
35 | if(a>=e&&a<=e+40&&b>=f&&b<=f+40)
36 | { Font fo=new Font("Arial",Font.BOLD,24);
37 | g.setFont(fo);
38 | g.drawString("GOAL",150,50);
39 | s=1;
40 | }
41 | if(s==0)
42 | { if(w>=95&&w<=105&&z>=295&&z<=305&&c1==0)
43 | { g.drawLine(w,z,x,y);
44 | g.drawOval(x-7,y-5,12,12);
45 | i=y-290;
46 | j=x-90;
47 | m=i/j;
48 | Random r=new Random();
49 | y1=50+r.nextInt(100);
50 | x1=250+r.nextInt(100);
51 | i1=y1-100;
52 | j1=x1-300;
53 | m1=i1/j1;
54 | }
55 | if(c==1&&c1==0)
56 | { c=0;
57 | c1=1;
58 | count++;
59 | }
60 | if(c1==1)
61 | { if(x<=100)
62 | a=a+5;
63 | else if(x>100)
64 | a=a-5;
65 | a1=a;
66 | b=(int)(m*(a1-90))+290;
67 | if(x1<=300)
68 | e=e+1;
69 | else if(x1>300)
70 | e=e-1;
71 | e1=e;
72 | f=(int)(m1*(e1-300))+100;
73 | }
74 | Thread.sleep(60);
75 | repaint();
76 | }
77 | }
78 | catch(Exception e)
79 | {}
80 | }
81 | };
82 | add(panel);
83 | }
84 | public void mouseClicked(MouseEvent me)
85 | {}
86 | public void mouseEntered(MouseEvent me)
87 | {}
88 | public void mouseExited(MouseEvent me)
89 | {}
90 | public void mousePressed(MouseEvent me)
91 | { if(count==0)
92 | { w=100;
93 | z=300;
94 | }
95 | }
96 | public void mouseReleased(MouseEvent me)
97 | { if(count==0)
98 | { x=me.getX();
99 | y=me.getY();
100 | c=1;
101 | repaint();
102 | }
103 | }
104 | public void mouseMoved(MouseEvent me)
105 | {}
106 | public void mouseDragged(MouseEvent me)
107 | { if(count==0)
108 | { x=me.getX();
109 | y=me.getY();
110 | repaint();
111 | }
112 | }
113 | public void paint(Graphics g)
114 | { super.paint(g);
115 | setSize(500,400);
116 | }
117 | }
118 |
119 |
--------------------------------------------------------------------------------
/Snake_Game.java:
--------------------------------------------------------------------------------
1 | //Snake Game
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /**/
9 | public class Snake_Game extends JApplet implements KeyListener,MouseListener
10 | { int x=200,y=250,x1,y1,a=0,b=0,c=0,k,d=0,i=0,f=1,f1=260,f2=350,flag=0;
11 | int p[]=new int[1000];
12 | int q[]=new int[1000];
13 | private JPanel panel;
14 | public void paint(Graphics g)
15 | { super.paint(g);
16 | setSize(420,420);
17 | }
18 | public void init()
19 | { addKeyListener(this);
20 | addMouseListener(this);
21 | requestFocus();
22 | p[0]=195;
23 | q[0]=250;
24 | panel = new JPanel()
25 | { protected void paintComponent(Graphics g)
26 | { super.paintComponent(g);
27 | if(flag==0)
28 | { Color cobj=new Color(142,236,253);
29 | g.setColor(cobj);
30 | g.fillRect(20,20,390,390);
31 | g.setColor(Color.BLACK);
32 | g.drawRect(20,20,390,390);
33 | Color c1=new Color(10,240,10);
34 | try
35 | { if(k==37)
36 | { x=x+c;
37 | for(i=f;i>0;i--)
38 | { p[i]=p[i-1];
39 | q[i]=q[i-1];
40 | }
41 | p[0]=x-c;
42 | q[0]=y;
43 | }
44 | else if(k==38)
45 | { y=y-b;
46 | for(i=f;i>0;i--)
47 | { p[i]=p[i-1];
48 | q[i]=q[i-1];
49 | }
50 | p[0]=x;
51 | q[0]=y+b;
52 | }
53 | else if(k==39)
54 | { x=x+a;
55 | for(i=f;i>0;i--)
56 | { p[i]=p[i-1];
57 | q[i]=q[i-1];
58 | }
59 | p[0]=x-a;
60 | q[0]=y;
61 | }
62 | else if(k==40)
63 | { y=y-d;
64 | for(i=f;i>0;i--)
65 | { p[i]=p[i-1];
66 | q[i]=q[i-1];
67 | }
68 | p[0]=x;
69 | q[0]=y+d;
70 | }
71 | if(x>395)
72 | { flag=1;
73 | x1=10;
74 | y1=10;
75 | repaint();
76 | }
77 | if(y<25)
78 | { flag=1;
79 | x1=10;
80 | y1=10;
81 | repaint();
82 | }
83 | if(x<25)
84 | { flag=1;
85 | x1=10;
86 | y1=10;
87 | repaint();
88 | }
89 | if(y>395)
90 | { flag=1;
91 | x1=10;
92 | y1=10;
93 | repaint();
94 | }
95 | showStatus(" SCORE="+(f-1)*8);
96 | Font fobj=new Font("Arial",Font.BOLD,15);
97 | g.setFont(fobj);
98 | g.setColor(Color.BLUE);
99 | g.drawString("SNAKE GAME",180,14);
100 | g.setColor(c1);
101 | g.fillOval(x,y,10,10);
102 | for(i=0;i=190&&x1<=210&&y1>=200&&y1<=220)
176 | { flag=0;
177 | p[0]=195;q[0]=250;
178 | x=200;y=250;a=0;b=0;c=0;k=41;d=0;i=0;f=1;f1=260;f2=350;
179 | repaint();
180 | }
181 | else
182 | flag=1;
183 | }
184 | }
185 | };
186 | add(panel);
187 | }
188 | public void mouseClicked(MouseEvent me)
189 | {}
190 | public void mouseEntered(MouseEvent me)
191 | {}
192 | public void mouseExited(MouseEvent me)
193 | {}
194 | public void mousePressed(MouseEvent me)
195 | { x1=me.getX();
196 | y1=me.getY();
197 | repaint();
198 | }
199 | public void mouseReleased(MouseEvent me)
200 | {}
201 | public void keyPressed(KeyEvent ke)
202 | { k=ke.getKeyCode();
203 | if(k==37)
204 | { if(a>0)
205 | { k=39;
206 | b=0;
207 | d=0;
208 | repaint();
209 | }
210 | else
211 | { c=-5;
212 | b=0;
213 | d=0;
214 | repaint();
215 | }
216 | }
217 | if(k==38)
218 | { if(d<0)
219 | { k=40;
220 | a=0;
221 | c=0;
222 | repaint();
223 | }
224 | else
225 | { b=5;
226 | a=0;
227 | c=0;
228 | repaint();
229 | }
230 | }
231 | if(k==39)
232 | { if(c<0)
233 | { k=37;
234 | b=0;
235 | d=0;
236 | repaint();
237 | }
238 | else
239 | { a=5;
240 | b=0;
241 | d=0;
242 | repaint();
243 | }
244 | }
245 | if(k==40)
246 | { if(b>0)
247 | { k=38;
248 | a=0;
249 | c=0;
250 | repaint();
251 | }
252 | else
253 | { d=-5;
254 | a=0;
255 | c=0;
256 | repaint();
257 | }
258 | }
259 | }
260 | public void keyReleased(KeyEvent ke)
261 | {}
262 | public void keyTyped(KeyEvent ke)
263 | {}
264 | }
265 |
266 |
267 |
--------------------------------------------------------------------------------
/Snices_Game.java:
--------------------------------------------------------------------------------
1 | //Snices Game
2 | //Having some bugs
3 | import java.applet.*;
4 | import java.awt.*;
5 | import java.awt.event.*;
6 | import java.util.Random;
7 | import javax.swing.*;
8 | /*
10 | */
11 | public class Snices_Game extends JApplet implements KeyListener
12 | { int k,i,j,x,y,s1x,s1y,k1,s2x,s2y,k2,f,rand,rand1,c;
13 | int s1[][]=new int[100][100];
14 | int s2[][]=new int[100][100];
15 | private JPanel panel;
16 | public void init()
17 | { addKeyListener(this);
18 | requestFocus();
19 | for(i=0;i<100;i++)
20 | { for(j=0;j<100;j++)
21 | { s1[i][j]=0;
22 | s2[i][j]=0;
23 | }
24 | }
25 | c=30;
26 | s1x=45;
27 | s1y=20;
28 | s2x=45;
29 | s2y=55;
30 | s1[s1x][s1y]=1;
31 | s2[s2x][s2y]=2;
32 | panel = new JPanel()
33 | { protected void paintComponent(Graphics g)
34 | { try
35 | { super.paintComponent(g);
36 | setBackground(Color.BLACK);
37 | if(f==0)
38 | { if(k1==37&&k==39)
39 | k=k1;
40 | else if(k1==39&&k==37)
41 | k=k1;
42 | else if(k1==38&&k==40)
43 | k=k1;
44 | else if(k1==40&&k==38)
45 | k=k1;
46 | if(k==37)
47 | { s1y=s1y-1;
48 | if(s1y==-1)
49 | f=1;
50 | else if(s1[s1x][s1y]==0&&s2[s1x][s1y]!=2)
51 | s1[s1x][s1y]=1;
52 | else if(s1[s1x][s1y]==1||s2[s1x][s1y]==2)
53 | f=1;
54 | k1=k;
55 | }
56 | else if(k==39)
57 | { s1y=s1y+1;
58 | if(s1y==100)
59 | f=1;
60 | else if(s1[s1x][s1y]==0&&s2[s1x][s1y]!=2)
61 | s1[s1x][s1y]=1;
62 | else if(s1[s1x][s1y]==1||s2[s1x][s1y]==2)
63 | f=1;
64 | k1=k;
65 | }
66 | else if(k==38)
67 | { s1x=s1x-1;
68 | if(s1x==-1)
69 | f=1;
70 | else if(s1[s1x][s1y]==0&&s2[s1x][s1y]!=2)
71 | s1[s1x][s1y]=1;
72 | else if(s1[s1x][s1y]==1||s2[s1x][s1y]==2)
73 | f=1;
74 | k1=k;
75 | }
76 | else if(k==40)
77 | { s1x=s1x+1;
78 | if(s1x==100)
79 | f=1;
80 | else if(s1[s1x][s1y]==0&&s2[s1x][s1y]!=2)
81 | s1[s1x][s1y]=1;
82 | else if(s1[s1x][s1y]==1||s2[s1x][s1y]==2)
83 | f=1;
84 | k1=k;
85 | }
86 | if(k==37||k==38||k==39||k==40)
87 | { for(i=0;i<10;i++)
88 | { if(c==30||c==rand1)
89 | { Random r=new Random();
90 | rand=37+r.nextInt(4);
91 | if(k2==37&&rand==37||k2==38&&rand==38||k2==39&&rand==39||k2==40&&rand==40)
92 | i=0;
93 | else if(k2==37&&rand==39||k2==39&&rand==37||k2==38&&rand==40||k2==40&&rand==38)
94 | i=0;
95 | else
96 | { i=10;
97 | c=0;
98 | Random r1=new Random();
99 | rand1=15+r1.nextInt(16);
100 | }
101 | }
102 | }
103 | k2=rand;
104 | }
105 | if(k2==37)
106 | { if(s2[s2x][s2y-1]==2||s1[s2x][s2y-1]==1||s2y-1==0)
107 | { if(s2[s2x+1][s2y]==0&&s1[s2x+1][s2y]!=1)
108 | { s2[s2x+1][s2y]=2;
109 | s2x=s2x+1;
110 | }
111 | else if(s2[s2x-1][s2y]==0&&s1[s2x-1][s2y]!=1)
112 | { s2[s2x-1][s2y]=2;
113 | s2x=s2x-1;
114 | }
115 | else if(s2[s2x][s2y+1]==0)
116 | { s2[s2x][s2y+1]=2;
117 | s2y=s2y+1;
118 | }
119 | else
120 | f=1;
121 | }
122 | else if(s2[s2x][s2y-1]==0&&s1[s2x][s2y-1]!=1)
123 | { s2[s2x][s2y-1]=2;
124 | s2y=s2y-1;
125 | }
126 | }
127 | else if(k2==39)
128 | { if(s2[s2x][s2y+1]==2||s1[s2x][s2y+1]==1||s2y+1==99)
129 | { if(s2[s2x+1][s2y]==0&&s1[s2x+1][s2y]!=1)
130 | { s2[s2x+1][s2y]=2;
131 | s2x=s2x+1;
132 | }
133 | else if(s2[s2x-1][s2y]==0&&s1[s2x-1][s2y]!=1)
134 | { s2[s2x-1][s2y]=2;
135 | s2x=s2x-1;
136 | }
137 | else if(s2[s2x][s2y-1]==0)
138 | { s2[s2x][s2y-1]=2;
139 | s2y=s2y-1;
140 | }
141 | else
142 | f=1;
143 | }
144 | else if(s2[s2x][s2y+1]==0&&s1[s2x][s2y+1]!=1)
145 | { s2[s2x][s2y+1]=2;
146 | s2y=s2y+1;
147 | }
148 | }
149 | else if(k2==38)
150 | { if(s2[s2x-1][s2y]==2||s1[s2x-1][s2y]==1||s2x-1==0)
151 | { if(s2[s2x][s2y+1]==0&&s1[s2x][s2y+1]!=1)
152 | { s2[s2x][s2y+1]=2;
153 | s2y=s2y+1;
154 | }
155 | else if(s2[s2x][s2y-1]==0&&s1[s2x][s2y-1]!=1)
156 | { s2[s2x][s2y-1]=2;
157 | s2y=s2y-1;
158 | }
159 | else if(s2[s2x+1][s2y]==0)
160 | { s2[s2x+1][s2y]=2;
161 | s2x=s2x+1;
162 | }
163 | else
164 | f=1;
165 | }
166 | else if(s2[s2x-1][s2y]==0&&s1[s2x-1][s2y]!=1)
167 | { s2[s2x-1][s2y]=2;
168 | s2x=s2x-1;
169 | }
170 | }
171 | else if(k2==40)
172 | { if(s2[s2x+1][s2y]==2||s1[s2x+1][s2y]==1||s2x+1==99)
173 | { if(s2[s2x][s2y+1]==0&&s1[s2x][s2y+1]!=1)
174 | { s2[s2x][s2y+1]=2;
175 | s2y=s2y+1;
176 | }
177 | else if(s2[s2x][s2y-1]==0&&s1[s2x][s2y-1]!=1)
178 | { s2[s2x][s2y-1]=2;
179 | s2y=s2y-1;
180 | }
181 | else if(s2[s2x-1][s2y]==0)
182 | { s2[s2x-1][s2y]=2;
183 | s2x=s2x-1;
184 | }
185 | else
186 | f=1;
187 | }
188 | else if(s2[s2x+1][s2y]==0&&s1[s2x+1][s2y]!=1)
189 | { s2[s2x+1][s2y]=2;
190 | s2x=s2x+1;
191 | }
192 | }
193 | }
194 | x=0;
195 | y=0;
196 | for(i=0;i<100;i++)
197 | { for(j=0;j<100;j++)
198 | { if(s1[i][j]==1)
199 | { g.setColor(Color.BLUE);
200 | g.fillRect(x,y,5,5);
201 | }
202 | if(s2[i][j]==2)
203 | { g.setColor(Color.RED);
204 | g.fillRect(x,y,5,5);
205 | }
206 | x=x+5;
207 | }
208 | x=0;
209 | y=y+5;
210 | }
211 | if(f==1)
212 | { g.setColor(Color.WHITE);
213 | Font fobj=new Font("Arial",Font.BOLD,24);
214 | g.setFont(fobj);
215 | g.drawString("GAME OVER",200,250);
216 | }
217 | if(k==37||k==38||k==39||k==40)
218 | c++;
219 | Thread.sleep(30);
220 | repaint();
221 | }
222 | catch(Exception e)
223 | {}
224 | }
225 | };
226 | add(panel);
227 | }
228 | public void keyPressed(KeyEvent ke)
229 | { k=ke.getKeyCode();
230 | repaint();
231 | }
232 | public void keyReleased(KeyEvent ke)
233 | {}
234 | public void keyTyped(KeyEvent ke)
235 | {}
236 | public void paint(Graphics g)
237 | { setSize(500,500);
238 | super.paint(g);
239 | }
240 | }
--------------------------------------------------------------------------------
/String_Converter.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class String_Converter extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4;
6 | Button b1,b2;
7 | TextField t1,t2,t3;
8 | String str;
9 | public void init()
10 | { setLayout(null);
11 | l1=new Label("Conversion of String in Upper and Lower Case");
12 | l2=new Label("Enter any string in any case(lower or upper or mixed case)");
13 | l3=new Label("Lower Case");
14 | l4=new Label("Upper Case");
15 | b1=new Button("Change the Case");
16 | b2=new Button("Clear Entries");
17 | t1=new TextField();
18 | t2=new TextField();
19 | t3=new TextField();
20 | add(t1);add(t2);add(t3);
21 | add(b1);add(b2);
22 | add(l1);add(l2);add(l3);add(l4);
23 | t2.setEditable(false);
24 | t3.setEditable(false);
25 | b1.addActionListener(this);
26 | b2.addActionListener(this);
27 | l1.setBounds(150,20,400,30);
28 | l2.setBounds(100,80,400,20);
29 | l3.setBounds(30,200,100,20);
30 | l4.setBounds(30,240,100,20);
31 | b1.setBounds(120,150,120,30);
32 | b2.setBounds(270,150,120,30);
33 | t1.setBounds(100,110,300,20);
34 | t2.setBounds(130,200,300,20);
35 | t3.setBounds(130,240,300,20);
36 | }
37 | public void actionPerformed(ActionEvent ae)
38 | { try
39 | { str=ae.getActionCommand();
40 | if(str.equals("Change the Case"))
41 | { t2.setText(t1.getText().toLowerCase());
42 | t3.setText(t1.getText().toUpperCase());
43 | }
44 | if(str.equals("Clear Entries"))
45 | { t1.setText("");
46 | t2.setText("");
47 | t3.setText("");
48 | }
49 |
50 | }
51 | catch(Exception e)
52 | {}
53 | }
54 | public void paint(Graphics g)
55 | { setSize(500,300);
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/Sudoku.java:
--------------------------------------------------------------------------------
1 | //Sudoku
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import java.util.Random;
6 | import javax.swing.*;
7 | /**/
9 | public class Sudoku extends JApplet implements KeyListener
10 | { int m[]=new int[9];
11 | int a[][]=new int[9][9];
12 | int b[][]=new int[9][9];
13 | int b1[][]=new int[9][9];
14 | int x1,y1,x2,y2,x3=20,y3=20,x4,y4,i,j,c=0,d=0,h,v=0,z=0;
15 | int r1,p1,q1;
16 | char ch;
17 | private JPanel panel;
18 | public void init()
19 | { addKeyListener(this);
20 | requestFocus();
21 | int k=0;
22 | while(k<9)
23 | { int e=0;
24 | Random r=new Random();
25 | r1=1+r.nextInt(9);
26 | for(int l=0;l340)
122 | x3=340;
123 | if(y3>340)
124 | y3=340;
125 | g.setColor(cobj1);
126 | g.fillRect(0,0,400,400);
127 | g.setColor(Color.WHITE);
128 | g.setFont(fobj);
129 | g.drawString("SUDOKU",170,15);
130 | x1=40;
131 | y1=40;
132 | for(i=0;i<9;i++)
133 | { for(j=0;j<9;j++)
134 | { if(b1[i][j]==0)
135 | { g.setColor(cobj);
136 | g.fillRect(x1-20,y1-20,40,40);
137 | }
138 | x1=x1+40;
139 | }
140 | y1=y1+40;
141 | x1=40;
142 | }
143 | g.setColor(cobj2);
144 | g.fillRect(x3,y3,40,40);
145 | x1=40;
146 | y1=40;
147 | for(i=0;i<9;i++)
148 | { for(j=0;j<9;j++)
149 | { if(a[i][j]==0)
150 | { g.drawString("",x1,y1);
151 | }
152 | else
153 | { g.setColor(Color.WHITE);
154 | g.setFont(fobj);
155 | g.drawString(""+a[i][j],x1,y1);
156 | }
157 | x1=x1+40;
158 | }
159 | y1=y1+40;
160 | x1=40;
161 | }
162 | g.setColor(Color.WHITE);
163 | y1=20;
164 | y2=y1;
165 | for(i=1;i<11;i++)
166 | { g.drawLine(20,y1,380,y2);
167 | y1=y1+40;
168 | y2=y1;
169 | }
170 | x1=20;
171 | x2=20;
172 | for(i=1;i<11;i++)
173 | { g.drawLine(x1,20,x2,380);
174 | x1=x1+40;
175 | x2=x1;
176 | }
177 | z=0;
178 | for(i=0;i<9;i++)
179 | { for(j=0;j<9;j++)
180 | { if(a[i][j]==b[i][j])
181 | z++;
182 | else
183 | z=0;
184 | }
185 | }
186 | if(z==81)
187 | { v=1;
188 | repaint();
189 | }
190 | }
191 | }
192 | };
193 | add(panel);
194 | }
195 | public void keyPressed(KeyEvent ke)
196 | { int k=ke.getKeyCode();
197 | if(k==37)
198 | { c=-40;
199 | d=0;
200 | h=0;
201 | ch='0';
202 | }
203 | else if(k==38)
204 | { c=0;
205 | d=-40;
206 | h=0;
207 | ch='0';
208 | }
209 | else if(k==39)
210 | { c=40;
211 | d=0;
212 | h=0;
213 | ch='0';
214 | }
215 | else if(k==40)
216 | { c=0;
217 | d=40;
218 | h=0;
219 | ch='0';
220 | }
221 | repaint();
222 | }
223 | public void keyReleased(KeyEvent ke)
224 | {}
225 | public void keyTyped(KeyEvent ke)
226 | { ch=ke.getKeyChar();
227 | c=0;
228 | d=0;
229 | x4=20;
230 | y4=20;
231 | repaint();
232 | }
233 | public void paint(Graphics g)
234 | { super.paint(g);
235 | setSize(400,400);
236 | }
237 | }
238 |
--------------------------------------------------------------------------------
/Swan.java:
--------------------------------------------------------------------------------
1 | //Swan
2 | import java.applet.*;
3 | import java.awt.*;
4 | import java.awt.event.*;
5 | import javax.swing.*;
6 | /**/
8 | public class Swan extends JApplet
9 | { private JPanel panel;
10 | public void init()
11 | { panel = new JPanel()
12 | { protected void paintComponent(Graphics g)
13 | { super.paintComponent(g);
14 | setBackground(Color.white);
15 | try
16 | { Font fobj=new Font("Chiller",Font.BOLD,22);
17 | g.setFont(fobj);
18 | g.drawString("Made By - SHASHANK SINGHAL",180,380);
19 | Color c1=new Color(173,240,255);
20 | g.setColor(c1);
21 | g.fillOval(98+20,52,280,265);
22 | Color c2=new Color(93,198,222);
23 | g.setColor(c2);
24 | g.fillOval(249-90,201-120,205,210);
25 | Color c3=new Color(46,131,150);
26 | g.setColor(c3);
27 | g.fillOval(261-80,247-50,169,81);
28 | Color c4=new Color(147,179,186);
29 | g.setColor(c4);
30 | int t1x[]={149,137,165};
31 | int t1y[]={119,148,130};
32 | g.fillPolygon(t1x,t1y,3);
33 | Color c5=new Color(112,138,143);
34 | g.setColor(c5);
35 | int t2x[]={159,137,165};
36 | int t2y[]={127,148,130};
37 | g.fillPolygon(t2x,t2y,3);
38 | Color c6=new Color(206,217,219);
39 | g.setColor(c6);
40 | int q1x[]={158,174,161,144};
41 | int q1y[]={103,101,135,120};
42 | g.fillPolygon(q1x,q1y,4);
43 | Color c7=new Color(184,194,196);
44 | g.setColor(c7);
45 | int q2x[]={158,174,161,144};
46 | int q2y[]={107,101,135,120};
47 | g.fillPolygon(q2x,q2y,4);
48 | Color c8=new Color(148,171,176);
49 | g.setColor(c8);
50 | int q3x[]={193,166,164,169};
51 | int q3y[]={99,105,117,127};
52 | g.fillPolygon(q3x,q3y,4);
53 | Color c9=new Color(232,244,247);
54 | g.setColor(c9);
55 | int q4x[]={210,193,171,190};
56 | int q4y[]={150,99,100,133};
57 | g.fillPolygon(q4x,q4y,4);
58 | Color c10=new Color(187,230,240);
59 | g.setColor(c10);
60 | int q5x[]={206,185,171,189};
61 | int q5y[]={213,99,102,136};
62 | g.fillPolygon(q5x,q5y,4);
63 | Color c11=new Color(250,254,255);
64 | g.setColor(c11);
65 | int q6x[]={174,174,161,144};
66 | int q6y[]={100,121,135,120};
67 | g.fillPolygon(q6x,q6y,4);
68 | Color c12=new Color(233,234,237);
69 | g.setColor(c12);
70 | int q7x[]={174,175,159,148};
71 | int q7y[]={116,123,134,124};
72 | g.fillPolygon(q7x,q7y,4);
73 | Color c13=new Color(222,248,255);
74 | g.setColor(c13);
75 | int q8x[]={177,211,207,191};
76 | int q8y[]={229,208,142,132};
77 | g.fillPolygon(q8x,q8y,4);
78 | Color c14=new Color(186,223,232);
79 | g.setColor(c14);
80 | int q9x[]={186,196,207,203};
81 | int q9y[]={202,195,144,139};
82 | g.fillPolygon(q9x,q9y,4);
83 | Color c15=new Color(136,213,227);
84 | g.setColor(c15);
85 | int q10x[]={194,188,244,221};
86 | int q10y[]={241,197,160,240};
87 | g.fillPolygon(q10x,q10y,4);
88 | Color c16=new Color(103,179,191);
89 | g.setColor(c16);
90 | int q11x[]={213,214,244,221};
91 | int q11y[]={237,195,160,240};
92 | g.fillPolygon(q11x,q11y,4);
93 | Color c17=new Color(235,251,255);
94 | g.setColor(c17);
95 | int q12x[]={176,216,208,197};
96 | int q12y[]={229,248,143,174};
97 | g.fillPolygon(q12x,q12y,4);
98 | Color c18=new Color(162,217,232);
99 | g.setColor(c18);
100 | int q13x[]={217,216,207,205};
101 | int q13y[]={253,248,140,174};
102 | g.fillPolygon(q13x,q13y,4);
103 | Color c19=new Color(210,241,247);
104 | g.setColor(c19);
105 | int q14x[]={212,175,270,231};
106 | int q14y[]={239,228,162,244};
107 | g.fillPolygon(q14x,q14y,4);
108 | Color c20=new Color(160,213,222);
109 | g.setColor(c20);
110 | int q15x[]={214,213,270,231};
111 | int q15y[]={229,228,162,244};
112 | g.fillPolygon(q15x,q15y,4);
113 | Color c21=new Color(240,252,255);
114 | g.setColor(c21);
115 | int q16x[]={193,213,257,221};
116 | int q16y[]={232,197,159,240};
117 | g.fillPolygon(q16x,q16y,4);
118 | Color c22=new Color(178,224,237);
119 | g.setColor(c22);
120 | int q17x[]={208,213,257,221};
121 | int q17y[]={236,229,159,240};
122 | g.fillPolygon(q17x,q17y,4);
123 | Color c23=new Color(219,244,255);
124 | g.setColor(c23);
125 | int q18x[]={217,255,311,178};
126 | int q18y[]={255,253,209,229};
127 | g.fillPolygon(q18x,q18y,4);
128 | Color c24=new Color(223,228,230);
129 | g.setColor(c24);
130 | int q19x[]={211,253,267,177};
131 | int q19y[]={256,254,244,228};
132 | g.fillPolygon(q19x,q19y,4);
133 | Color c25=new Color(198,220,230);
134 | g.setColor(c25);
135 | int q20x[]={308,219,275,309};
136 | int q20y[]={154,225,234,210};
137 | g.fillPolygon(q20x,q20y,4);
138 | Color c26=new Color(148,208,222);
139 | g.setColor(c26);
140 | int q21x[]={319,274,270,309};
141 | int q21y[]={194,218,240,211};
142 | g.fillPolygon(q21x,q21y,4);
143 | Color c27=new Color(234,246,252);
144 | g.setColor(c27);
145 | int q22x[]={321,224,284,268};
146 | int q22y[]={157,224,214,242};
147 | g.fillPolygon(q22x,q22y,4);
148 | Color c28=new Color(163,194,207);
149 | g.setColor(c28);
150 | int q23x[]={323,270,284,268};
151 | int q23y[]={156,224,214,242};
152 | g.fillPolygon(q23x,q23y,4);
153 | Color c29=new Color(245,253,255);
154 | g.setColor(c29);
155 | int q24x[]={288,224,268,273};
156 | int q24y[]={148,224,199,215};
157 | g.fillPolygon(q24x,q24y,4);
158 | }
159 | catch(Exception e)
160 | {}
161 | }
162 | };
163 | add(panel);
164 | }
165 | public void paint(Graphics g)
166 | { super.paint(g);
167 | setSize(450,400);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/Talk_it.java:
--------------------------------------------------------------------------------
1 | //Talk it
2 | import javax.speech.*;
3 | import java.util.*;
4 | import javax.speech.synthesis.*;
5 | import java.awt.*;
6 | import java.applet.*;
7 | import java.awt.event.*;
8 | /**/
10 | public class Talk_it extends Applet implements ActionListener
11 | { String str,speaktext,voiceName;
12 | TextArea input;
13 | public void init()
14 | { setSize(300,400);
15 | input=new TextArea(20,35);
16 | Button b1=new Button("Speak now");
17 | add(input);add(b1) ;
18 | b1.addActionListener(this);
19 | }
20 | public void actionPerformed(ActionEvent ae)
21 | { str=ae.getActionCommand();
22 | if(str.equals("Speak now"))
23 | { dospeak(input.getText());
24 | }
25 | }
26 | public void dospeak(String speak)
27 | { speaktext=speak;
28 | try
29 | { System.setProperty("mbrola.base", "D:\\mbrola");
30 | SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
31 | Synthesizer synthesizer = Central.createSynthesizer(desc);
32 | synthesizer.allocate();
33 | synthesizer.resume();
34 | desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
35 | Voice[] voices = desc.getVoices();
36 | Voice voice = null;
37 | for (int i=0; i
7 | */
8 | public class The_Maze_Game extends JApplet implements KeyListener
9 | { int a[][]=new int[20][20];
10 | int x1,y1,x2,y2,i,j,p1=9,q1=0,e1,e2,t,f=0;
11 | private JPanel panel;
12 | public void init()
13 | { addKeyListener(this);
14 | requestFocus();
15 | for(i=0;i<20;i++)
16 | { for(j=0;j<20;j++)
17 | { if(i==1&&j==1||i==1&&j==2||i==1&&j==3||i==1&&j==5||i==1&&j==6||i==1&&j==7||i==1&&j==8||i==1&&j==9||i==1&&j==10||i==1&&j==11||i==1&&j==12||i==1&&j==13||i==1&&j==14||i==1&&j==18||
18 | i==2&&j==1||i==2&&j==3||i==2&&j==6||i==2&&j==9||i==2&&j==14||i==2&&j==18||i==3&&j==1||i==3&&j==3||i==3&&j==4||i==3&&j==5||i==3&&j==6||i==3&&j==9||i==3&&j==11||i==3&&j==12||
19 | i==3&&j==14||i==3&&j==15||i==3&&j==16||i==3&&j==17||i==3&&j==18||i==4&&j==1||i==4&&j==5||i==4&&j==8||i==4&&j==9||i==4&&j==10||i==4&&j==11||i==4&&j==14||i==4&&j==18||i==5&&j==5||
20 | i==5&&j==8||i==5&&j==14||i==5&&j==15||i==5&&j==16||i==5&&j==18||i==6&&j==2||i==6&&j==3||i==6&&j==4||i==6&&j==5||i==6&&j==8||i==6&&j==12||i==6&&j==13||i==6&&j==16||i==7&&j==2||
21 | i==7&&j==7||i==7&&j==8||i==7&&j==9||i==7&&j==10||i==7&&j==11||i==7&&j==12||i==7&&j==16||i==7&&j==18||i==7&&j==19||i==8&&j==2||i==8&&j==6||i==8&&j==14||i==8&&j==15||i==8&&j==16||
22 | i==8&&j==18||i==9&&j==0||i==9&&j==1||i==9&&j==2||i==9&&j==3||i==9&&j==4||i==9&&j==6||i==9&&j==7||i==9&&j==8||i==9&&j==9||i==9&&j==10||i==9&&j==11||i==9&&j==14||i==9&&j==18||
23 | i==10&&j==4||i==10&&j==6||i==10&&j==12||i==10&&j==14||i==10&&j==18||i==11&&j==1||i==11&&j==3||i==11&&j==4||i==11&&j==6||i==11&&j==7||i==11&&j==8||i==11&&j==9||i==11&&j==10||i==11&&j==12||
24 | i==11&&j==14||i==11&&j==18||i==12&&j==1||i==12&&j==3||i==12&&j==6||i==12&&j==12||i==12&&j==14||i==12&&j==15||i==12&&j==16||i==12&&j==17||i==12&&j==18||i==13&&j==1||i==13&&j==3||i==13&&j==6||
25 | i==13&&j==9||i==13&&j==10||i==13&&j==11||i==13&&j==12||i==14&&j==1||i==14&&j==2||i==14&&j==3||i==14&&j==5||i==14&&j==6||i==14&&j==9||i==14&&j==16||i==14&&j==17||i==14&&j==18||i==15&&j==2||
26 | i==15&&j==9||i==15&&j==10||i==15&&j==11||i==15&&j==12||i==15&&j==13||i==15&&j==14||i==15&&j==16||i==15&&j==18||i==16&&j==2||i==16&&j==3||i==16&&j==4||i==16&&j==5||i==16&&j==6||i==16&&j==7||
27 | i==16&&j==8||i==16&&j==9||i==16&&j==12||i==16&&j==14||i==16&&j==15||i==16&&j==16||i==16&&j==18||i==17&&j==2||i==17&&j==12||i==18&&j==1||i==18&&j==2||i==18&&j==4||i==18&&j==5||i==18&&j==6||
28 | i==18&&j==7||i==18&&j==8||i==18&&j==9||i==18&&j==10||i==18&&j==11||i==18&&j==12||i==18&&j==13||i==18&&j==14||i==18&&j==15||i==18&&j==16||i==18&&j==17||i==18&&j==18)
29 | a[i][j]=1;
30 | else
31 | a[i][j]=2;
32 | }
33 | }
34 | a[9][0]=0;
35 | panel = new JPanel()
36 | { protected void paintComponent(Graphics g)
37 | { super.paintComponent(g);
38 | Color cobj=new Color(153,253,170);
39 | Font fobj=new Font("Arial",Font.BOLD,24);
40 | if(f==0)
41 | { x1 = 40;
42 | y1=40;
43 | for(i=0;i<20;i++)
44 | { for(j=0;j<20;j++)
45 | { if(a[i][j]==0)
46 | { g.setColor(cobj);
47 | g.fillRect(x1, y1, 20, 20);
48 | }
49 | else if(a[i][j]==1)
50 | { g.setColor(Color.WHITE);
51 | g.fillRect(x1, y1, 20, 20);
52 | }
53 | else if(a[i][j]==2)
54 | { g.setColor(Color.GRAY);
55 | g.fillRect(x1, y1, 20, 20);
56 | }
57 | x1=x1+20;
58 | }
59 | y1=y1+20;
60 | x1=40;
61 | }
62 | }
63 | if(a[7][19]==0)
64 | { f=1;
65 | g.setFont(fobj);
66 | g.setColor(Color.MAGENTA);
67 | g.drawString("YOU WIN",200,250);
68 | repaint();
69 | }
70 | }
71 | };
72 | add(panel);
73 | }
74 | public void keyPressed(KeyEvent ke)
75 | { int k=ke.getKeyCode();
76 | if(k==39)
77 | { if(q1==19)
78 | e1=0;
79 | else
80 | e1=-1;
81 | if(a[p1][q1-e1]==1)
82 | { t=a[p1][q1];
83 | a[p1][q1]=a[p1][q1-e1];
84 | a[p1][q1-e1]=t;
85 | q1=q1-e1;
86 | }
87 | }
88 | else if(k==40)
89 | { if(p1==19)
90 | e2=0;
91 | else
92 | e2=-1;
93 | if(a[p1-e2][q1]==1)
94 | { t=a[p1][q1];
95 | a[p1][q1]=a[p1-e2][q1];
96 | a[p1-e2][q1]=t;
97 | p1=p1-e2;
98 | }
99 | }
100 | else if(k==37)
101 | { if(q1==0)
102 | e1=0;
103 | else
104 | e1=1;
105 | if(a[p1][q1-e1]==1)
106 | { t=a[p1][q1];
107 | a[p1][q1]=a[p1][q1-e1];
108 | a[p1][q1-e1]=t;
109 | q1=q1-e1;
110 | }
111 | }
112 | else if(k==38)
113 | { if(p1==0)
114 | e2=0;
115 | else
116 | e2=1;
117 | if(a[p1-e2][q1]==1)
118 | { t=a[p1][q1];
119 | a[p1][q1]=a[p1-e2][q1];
120 | a[p1-e2][q1]=t;
121 | p1=p1-e2;
122 | }
123 | }
124 | repaint();
125 | }
126 | public void keyReleased(KeyEvent ke)
127 | {}
128 | public void keyTyped(KeyEvent ke)
129 | {}
130 | public void paint(Graphics g)
131 | { super.paint(g);
132 | setSize(470,470);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/The_Pizza_Cafe.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class The_Pizza_Cafe extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5,l6,l7,l8;
6 | Button b1,b2;
7 | TextField t1,t2,t3,t4,t5;
8 | Checkbox c1,c2,c3;
9 | Checkbox c4,c5;
10 | String str;
11 | int q,r,costoftoppings,amt,a,b,c;
12 | CheckboxGroup cbg;
13 | public void init()
14 | { setLayout(null);
15 | l1=new Label("Cafe Coffee Day");
16 | l2=new Label("Customer Name");
17 | l3=new Label("Quantity");
18 | l4=new Label("Rate");
19 | l5=new Label("Cost of Toppings");
20 | l6=new Label("Amount");
21 | l7=new Label("Pizza Type");
22 | l8=new Label("Toppings");
23 | b1=new Button("Calculate Rate");
24 | b2=new Button("Calculate Amount");
25 | t1=new TextField();
26 | t2=new TextField();
27 | t3=new TextField();
28 | t4=new TextField();
29 | t5=new TextField();
30 | c1=new Checkbox("Cheese");
31 | c2=new Checkbox("Capsicum");
32 | c3=new Checkbox("Pepperoni");
33 | cbg=new CheckboxGroup();
34 | c4=new Checkbox("Regular",true,cbg);
35 | c5=new Checkbox("Plain",false,cbg);
36 | add(c1);add(c2);add(c3);add(c4);add(c5);
37 | add(t1);add(t2);add(t3);add(t4);add(t5);
38 | add(b1);add(b2);
39 | add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);add(l8);
40 | t3.setEditable(false);
41 | t4.setEditable(false);
42 | t5.setEditable(false);
43 | b1.addActionListener(this);
44 | b2.addActionListener(this);
45 | l1.setBounds(250,20,200,30);
46 | l2.setBounds(30,80,100,20);
47 | l3.setBounds(30,130,100,20);
48 | l4.setBounds(30,180,100,20);
49 | l5.setBounds(30,230,100,20);
50 | l6.setBounds(30,280,100,20);
51 | l7.setBounds(300,80,100,20);
52 | l8.setBounds(330,150,100,20);
53 | b1.setBounds(100,330,130,30);
54 | b2.setBounds(300,330,130,30);
55 | t1.setBounds(150,80,100,20);
56 | t2.setBounds(150,130,100,20);
57 | t3.setBounds(150,180,100,20);
58 | t4.setBounds(150,230,100,20);
59 | t5.setBounds(150,280,100,20);
60 | c1.setBounds(330,180,120,20);
61 | c2.setBounds(330,210,120,20);
62 | c3.setBounds(330,240,120,20);
63 | c4.setBounds(370,80,100,20);
64 | c5.setBounds(370,100,100,20);
65 |
66 | }
67 | public void actionPerformed(ActionEvent ae)
68 | { try
69 | { str=ae.getActionCommand();
70 | if(str.equals("Calculate Rate"))
71 | { if(c4.getState()==true)
72 | t3.setText("90 Rs");
73 | else if(c5.getState()==true)
74 | t3.setText("120 Rs");
75 | }
76 | if(str.equals("Calculate Amount"))
77 | { a=0;b=0;c=0;
78 | q=Integer.parseInt(t2.getText());
79 | if(c4.getState()==true)
80 | { t3.setText("90 Rs");
81 | r=90;
82 | }
83 | else if(c5.getState()==true)
84 | { t3.setText("120 Rs");
85 | r=120;
86 | }
87 | if(c1.getState()==true)
88 | a=20;
89 | if(c2.getState()==true)
90 | b=20;
91 | if(c3.getState()==true)
92 | c=20;
93 | costoftoppings=a+b+c;
94 | t4.setText(""+costoftoppings);
95 | amt=q*r+costoftoppings;
96 | t5.setText(""+amt);
97 | }
98 | }
99 | catch(Exception e)
100 | {}
101 | }
102 | public void paint(Graphics g)
103 | { setSize(500,400);
104 | }
105 | }
106 |
107 |
--------------------------------------------------------------------------------
/Workers_payment_calculator.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | import java.awt.event.*;
4 | public class Workers_payment_calculator extends Applet implements ActionListener
5 | { Label l1,l2,l3,l4,l5,l6,l7;
6 | Button b1;
7 | TextField t1,t2,t3,t4,t5;
8 | int days,wage,ded,pay,netpay;
9 | public void init()
10 | { setLayout(null);
11 | l1=new Label("Worker's Payment Calculator");
12 | l2=new Label("Days Worked");
13 | l3=new Label("Wage Rate(Rs.)");
14 | l4=new Label("Deduction(Rs.)");
15 | l5=new Label("Payment");
16 | l6=new Label("Net Payment");
17 | l7=new Label("");
18 | b1=new Button("Get Payment");
19 | t1=new TextField();
20 | t2=new TextField();
21 | t3=new TextField();
22 | t4=new TextField();
23 | t5=new TextField();
24 | add(t1);add(t2);add(t3);add(t4);add(t5);
25 | add(b1);
26 | add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);
27 | t4.setEditable(false);
28 | t5.setEditable(false);
29 | b1.addActionListener(this);
30 | l1.setBounds(150,20,200,30);
31 | l2.setBounds(30,80,100,20);
32 | l3.setBounds(30,130,100,20);
33 | l4.setBounds(30,180,100,20);
34 | l5.setBounds(300,130,100,20);
35 | l6.setBounds(300,180,100,20);
36 | l7.setBounds(230,230,200,20);
37 | b1.setBounds(300,80,100,20);
38 | t1.setBounds(150,80,100,20);
39 | t2.setBounds(150,130,100,20);
40 | t3.setBounds(150,180,100,20);
41 | t4.setBounds(450,130,100,20);
42 | t5.setBounds(450,180,100,20);
43 | }
44 | public void actionPerformed(ActionEvent ae)
45 | { try
46 | { days=Integer.parseInt(t1.getText());
47 | wage=Integer.parseInt(t2.getText());
48 | ded=Integer.parseInt(t3.getText());
49 | pay=days*wage;
50 | netpay=pay-ded;
51 | if(pay>=ded)
52 | { l7.setText("");
53 | t4.setText(""+pay);
54 | t5.setText(""+netpay);
55 | }
56 | else
57 | { l7.setText("There is recovery of Rs = " + -1*netpay);
58 | t4.setText("");
59 | t5.setText("");
60 | }
61 |
62 | }
63 | catch(Exception e)
64 | {}
65 | }
66 | public void paint(Graphics g)
67 | { setSize(600,250);
68 | }
69 | }
70 |
71 |
--------------------------------------------------------------------------------