Best Blogger Tips

Sunday 23 September 2012

TIC TAC TOE Game code in java!

0 comments
//code start
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class TicTacToe implements ActionListener {
 final String VERSION = "1.0";
//Setting up ALL the variables
 JFrame window = new JFrame("Tic-Tac-Toe " + VERSION);
 
 JMenuBar mnuMain = new JMenuBar();
 JMenuItem  mnuNewGame = new JMenuItem("New Game"), 
     mnuInstruction = new JMenuItem("Instructions"),
     mnuExit = new JMenuItem("Exit"), 
     mnuAbout = new JMenuItem("About");
 
 JButton  btn1v1 = new JButton("Player vs Player"),
    btn1vCPU = new JButton("Player vs CPU"),
    btnBack = new JButton("<--back");
 JButton btnEmpty[] = new JButton[10];
 

DIGITAL CLOCK CODE IN JAVA!

0 comments

Synchronized digital clock.

//code Start
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Random;

import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;


public class DigitalClock extends JPanel implements Runnable {

 static JMenuBar mainBar;
 static JMenu open,about;
 static JMenuItem exit,aboutme;
 
 Thread t;
 Random rand = new Random();
 
 
 public void paintComponent(Graphics g){
  
  super.paintComponent(g);
  g.setFont(new Font("Serif",Font.BOLD,50));
  //g.setColor(new Color(rand.nextInt(255), rand.nextInt(255),rand.nextInt(255)));
  g.setColor(new Color((0), (0),(255)));
  g.drawString(time(), 27, 62);
 }
 
 //Constructor to INITIALIZE THE CLOCK
 public DigitalClock() {
  Start();//Start The CLock 
  }
 
 public String time() {
  Calendar cal = Calendar.getInstance();
  int hour = cal.get(Calendar.HOUR_OF_DAY);
  int min = cal.get(Calendar.MINUTE);
  int second = cal.get(Calendar.SECOND);
  
  String time = includeZero(hour)+":"+includeZero(min)+":"+includeZero(second);
  
  return time;
 }
 
 public String includeZero(int number){
  
  String num=(number < 10) ? ("0"+number) : (""+number);
  return num;
 }
 
 
 
 public static void main(String[] args) {
  JFrame.setDefaultLookAndFeelDecorated(true);
  try {
   UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
  } catch (Exception e) {
   // TODO: handle exception
  }
  
  
  SwingUtilities.invokeLater(new Runnable() {
   
   
   
   
   @Override
   public void run() {
    JFrame frame=new JFrame("Clock");
    
   
    
    
    frame.add(new DigitalClock());
    frame.setSize(250, 150);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    
    mainBar = new JMenuBar();
    frame.setJMenuBar(mainBar);
    
    open = new JMenu("Open");
    mainBar.add(open);
    about = new JMenu("About");
    mainBar.add(about);
    exit = new JMenuItem("Exit");
    open.add(exit);
    aboutme = new JMenuItem("About me");
    about.add(aboutme);
    
    exit.addActionListener(new ActionListener() {
     
     @Override
     public void actionPerformed(ActionEvent arg0) {
      System.exit(0);
      
     }
    });
    
    
    aboutme.addActionListener(new ActionListener() {
     
     @Override
     public void actionPerformed(ActionEvent arg0) {
     JDialog dialog = new JDialog();
     dialog.setTitle("About Me");
     dialog.setVisible(true);
     dialog.setSize(400, 400);
     dialog.setLocation(790, 300);
     dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     dialog.setLayout(null);
     Label label =new Label( "Created by : Zeeshan Jamal");
     label.setBounds(0, 0, 200, 20);
     
     dialog.add(label);
       
      
     }
    });
   }
  });
  
 
  
 }

 
 public void Start() {
 if (t==null){
 t= new Thread(this);
 t.start();
 
 
 }
 }
 public void run(){
  while (t == Thread.currentThread()){
   repaint();
   try {
    Thread.sleep(1000);
    
   } catch (Exception e) {
    System.out.println(e.getLocalizedMessage());
   }
  }
  
 }

}
//code end


Monday 17 September 2012

Cool Unsynchronized Code for a digital clock in java!

0 comments
java digital clock code
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


class clock extends JFrame
{
 int sec = 0;
    int min = 0;
    int hour = 0;
   
 
 public clock(){
  super("Clock");
  setVisible(true);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setSize(90, 80);
  setLocationRelativeTo(null);
  setLayout(new FlowLayout());
  JTextField fr = new JTextField(10);
  
  fr.setFont(new Font("Serif",Font.BOLD,19));
  fr.setEditable(false);
  add(fr);
             for(hour=1;hour<24;hour++)
             {
                 for(min=0;min<60;min++)
                 {
                     for(sec=0;sec<60;sec++)
                     {
                      
                      
                         fr.setText("          "+hour+":"+ min+":"+sec);
                         try{Thread.sleep(1000);}
                         catch(Exception e){}
                       
                     }

                 }
             }

         
  
 }
 
 
 
    public static void main(String args[])
    {
     
     new clock();   
    }
}



Saturday 1 September 2012

Get Access to Weird SMS application for just 5$!

0 comments
This application is one amongst the best miracles in the cyber world. You would be wondering about what the heck is this stuff offering to cyber citizens that other SMS applications don't!
Take a break for a while, sit relax, and have patience! I will be telling you very shortly.
It is a massive fun for the pakistani citizens, because this application is developed in Pakistan and it is only accessible within Pakistan and few other Asian countries. This application is hosted on cloud and it's visitors are increasing rapidly. It is one of the best practical implementation of javascript and jsp technologies. Also includes other technologies like agax in traces.

What you can do with this site:

YES THIS IS THE BIGGEST QUESTION THAT EVERYONE WANTS TO ASK! I will go straightforward! YOU CAN SEND SMS TO ANY NUMBER (it's look common, because every free sms sending site sends sms to any number but take a look at next statement) FROM ANY NUMBER(Now that's look quite weird!:))YES FROM ANY NUMBER! EVEN FROM YOUR FATHER's NUMBER TO YOUR MOTHER's NUMBER, FROM YOUR FRIEND's NUMBER to Your FRIEND's NUMBER.HAHAHAH...QUITE EXCITING! HUH!...APSOLUTELY FREE

Get Access to the site:

Because of the current circumstances of the country! This site is posing the risk Because of the weird facility it provides! That's why i am giving away the for Only 5$ as terms and policies applied by the folks.
 

| Bloggers Broadcast © 2010. All Rights Reserved | Back To Top |

Your Text Link Here