Android Tutorial , Programming Tutorial, Php Tutorial, Learn Android, HTML Tutorial, Coding , Java Tutorial, GTU Programs, Learning Programming

Tuesday 27 December 2016

Slide Down Div using JQuery

jQuery slidedown() method is used to slide down an element.

In this example , when we click on the div then other div sliding slowly in down side and show on the web page.

Let's see the example :


File Name : index.html


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>  
<html>  
<head>  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>  
<script>   
$(document).ready(function(){  
    $("#flip").click(function(){  
        $("#panel").slideDown("slow");  
    });  
});  
</script>  
 <style>   
#panel, #flip {  
    padding: 5px;  
    text-align: center;  
    background-color: #33FFD4;  
    border: solid 3px #084236;  
}  
#panel {  
    padding: 50px;  
    display: none;  
}  
</style>  
</head>  
<body>  
<div id="flip">Click to slide down panel</div>  
<div id="panel">Hello World Good Morning...</div>  
</body>  
</html> 

Output :


Monday 19 December 2016

Responsive navbar using materialize css

In this tutorial , we are learning that how to create responsive navbar using materialize css.

Let's see the some class or tag description which is used in the example :


  • <nav> : it is used for create blank navbar on the top.
  • nav-wrapper  : it is used to set position of the element in navbar.
  • brand-logo center : it is used to set logo of the website on the center of the navbar.
  • right : it is used to set element from the right side of the navbar.


Let's see the code :

File name : index.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
 <head>
  <link rel="stylesheet" href="css/materialize.css" type="text/css">
  
  <script src="js/jquery.js"></script>
  <script src="js/materialize.min.js" type="text/javascript"></script>

 </head>
 <body>
  <nav>
   <div class = "nav-wrapper">
    <li class="brand-logo center">LOGO</li>
     <ul class="right">
      <li><a href="#">Menu 1 </a></li>
      <li><a href="#">Menu 2</a></li>
      <li><a href="#">Menu 3 </a></li>
     </ul>
   </div>
  </nav> 
 </body>
 </html>

Output :



Download CSS & JS File : Click Here

Sunday 18 December 2016

Tic Tac Toe game in Android

In this tutorial , we are learning that how to make tic tac toe game using Android.

This is one of the simplest game to entertainment between boaring time or lectures.

So, follow the steps to create a game very easily.

File Name : activity_main.xml

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!-- Let's see the design code
This is the main Layout of the activity .. To add all buttons in vertical format set orientation  -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3"
    android:orientation="vertical"
    android:background="#000000"
    tools:context=".MainActivity" >

    <!-- There are 3 sub Linear Layout added in the activity..
    This is the first row of the activity which has include 3 button, i will show you by changing color of the activity -->
    
    <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:weightSum="3"
     android:layout_weight="1"    
        >
        
        <!-- Now add 3 buttons in first row ... see the following code -->
        <Button 
            android:id="@+id/b1"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp" 
            android:textSize="72dp" 
            />
        
        <Button 
            android:id="@+id/b2"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
        <Button 
            android:id="@+id/b3"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
    </LinearLayout>

    <!-- Now copy the above layout code and paste it for adding second layout for second row.. -->
    
        <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:weightSum="3"
     android:background="#f00000" 
     android:layout_weight="1"    
        >
        
        <Button 
            android:id="@+id/b4"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
        
        <Button 
            android:id="@+id/b5"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
        <Button 
            android:id="@+id/b6"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
    </LinearLayout>
    
        <!-- Now add third linear layout row -->
        
            <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:weightSum="3"
     android:layout_weight="1"    
        >
        
        <Button 
            android:id="@+id/b7"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
        
        <Button 
            android:id="@+id/b8"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
        <Button 
            android:id="@+id/b9"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:textColor="#ffffff"
            android:layout_weight="1"
            android:layout_marginRight="5sp"
            android:textSize="72dp"
            />
    </LinearLayout>
</LinearLayout>


File Name : MainActivity.java



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package com.example.tictactoe;

import android.R.color;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

 Button b1,b2,b3,b4,b5,b6,b7,b8,b9;
 int turn;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  b1 = (Button)findViewById(R.id.b1);
  b2 = (Button)findViewById(R.id.b2);
  b3 = (Button)findViewById(R.id.b3);
  b4 = (Button)findViewById(R.id.b4);
  b5 = (Button)findViewById(R.id.b5);
  b6 = (Button)findViewById(R.id.b6);
  b7 = (Button)findViewById(R.id.b7);
  b8 = (Button)findViewById(R.id.b8);
  b9 = (Button)findViewById(R.id.b9);
  
  turn=1;
  
  b1.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
     if(b1.getText().toString().equals(""))
     {
      if(turn == 1)
      {
       turn = 2;
       b1.setText("X");
      }
      else if (turn == 2)
      {
       turn = 1;
       b1.setText("O");
      }
     }
    endGame(); 
   }
  });
  
  b2.setOnClickListener(new View.OnClickListener() {
     
     @Override
     public void onClick(View arg0) {
      // TODO Auto-generated method stub
     
      if(b2.getText().toString().equals(""))
      {
       if(turn == 1)
       {
        turn = 2;
        b2.setText("X");
       }
       else if (turn == 2)
       {
        turn = 1;
        b2.setText("O");
       }
      }
      
      endGame(); 
     }
    });
  
  b3.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b3.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b3.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b3.setText("O");
     }
    }
    endGame();
   }
  });
  
  b4.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b4.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b4.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b4.setText("O");
     }
    }
    endGame();
   }
  });
  
  b5.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b5.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b5.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b5.setText("O");
     }
    }
    endGame();
   }
  });
  
  b6.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b6.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b6.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b6.setText("O");
     }
    }
    endGame();
   }
  });
  
  b7.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b7.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b7.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b7.setText("O");
     }
    }
    endGame();
   }
  });
  
  b8.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b8.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b8.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b8.setText("O");
     }
    }
    endGame();
   }
  });
  
  b9.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    
    if(b9.getText().toString().equals(""))
    {
     if(turn == 1)
     {
      turn = 2;
      b9.setText("X");
     }
     else if (turn == 2)
     {
      turn = 1;
      b9.setText("O");
     }
    }
    endGame();
   }
  });
  
 }
 
 public void endGame()
 {
  String a,b,c,d,e,f,g,h,i;
  boolean end = false;
  
  
  a = b1.getText().toString();
  b = b2.getText().toString();
  c = b3.getText().toString();
  d = b4.getText().toString();
  e = b5.getText().toString();
  f = b6.getText().toString();
  g = b7.getText().toString();
  h = b8.getText().toString();
  i = b9.getText().toString();
  
  if(a.equals("X") && b.equals("X") && c.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b2.setBackgroundColor(Color.GRAY);
   b3.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(a.equals("X") && d.equals("X") && g.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b4.setBackgroundColor(Color.GRAY);
   b7.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(a.equals("X") && e.equals("X") && i.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(b.equals("X") && e.equals("X") && h.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b2.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b8.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(c.equals("X") && e.equals("X") && g.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b3.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b7.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(c.equals("X") && f.equals("X") && i.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b3.setBackgroundColor(Color.GRAY);
   b6.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(d.equals("X") && e.equals("X") && f.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b4.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b6.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(g.equals("X") && h.equals("X") && i.equals("X"))
  {
   Toast.makeText(getApplicationContext(), "Winner is X", Toast.LENGTH_SHORT).show();
   b7.setBackgroundColor(Color.GRAY);
   b8.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  
  
  if(a.equals("O") && b.equals("O") && c.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(a.equals("O") && d.equals("O") && g.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b4.setBackgroundColor(Color.GRAY);
   b7.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(a.equals("O") && e.equals("O") && i.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b1.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(b.equals("O") && e.equals("O") && h.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b2.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b8.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(c.equals("O") && e.equals("O") && g.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b3.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b7.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(c.equals("O") && f.equals("O") && i.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b3.setBackgroundColor(Color.GRAY);
   b6.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(d.equals("O") && e.equals("O") && f.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b4.setBackgroundColor(Color.GRAY);
   b5.setBackgroundColor(Color.GRAY);
   b6.setBackgroundColor(Color.GRAY);
   end = true;
  }
  if(g.equals("O") && h.equals("O") && i.equals("O"))
  {
   Toast.makeText(getApplicationContext(), "Winner is O", Toast.LENGTH_SHORT).show();
   b7.setBackgroundColor(Color.GRAY);
   b8.setBackgroundColor(Color.GRAY);
   b9.setBackgroundColor(Color.GRAY);
   end = true;
  }
  
  if(end)
  {
   b1.setEnabled(false);
   b2.setEnabled(false);
   b3.setEnabled(false);
   b4.setEnabled(false);
   b5.setEnabled(false);
   b6.setEnabled(false);
   b7.setEnabled(false);
   b8.setEnabled(false);
   b9.setEnabled(false);
  }
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

}



Output :

Tic Tac Toe Tic Tac Toe

Like us on Facebook

Site Visitor

Powered by Blogger.