true

Find the best tutors and institutes for Java Training

Find Best Java Training Classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Java Training Updates

Ask a Question

Post a Lesson

All

All

Lessons

Discussion

Lesson Posted on 08 Jul IT Courses/Java/Core Java

Puzzle Game coding

Venkatesh Kammampati

I am an experienced in teaching JAVA and Quantitative Aptitude with JOB Assistance. Strong in Analytical...

import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.Random; import... read more

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import java.util.Random;
public class GameOfFifteen extends JPanel
{
private int size;
private int nbTiles;
private int dimension;
private static final Color FOREGROUND_COLOR=new Color(239,83,80);
private static final Random RANDOM=new Random();
private int[] tiles;
private int tileSize;
private int blankPos;
private int margin;
private int gridSize;
private boolean gameOver;
public GameOfFifteen(int size, int dimension, int margin)
{
super();
this.size = size;
this.dimension = dimension;
this.margin = margin;
nbTiles=size*size-1;
tiles=new int[size*size];
gridSize=(dimension-2*margin);
tileSize=gridSize/size;
setPreferredSize(new Dimension(dimension,dimension+margin));
setBackground(Color.WHITE);
setForeground(FOREGROUND_COLOR);
setFont(new Font("SansSerif",Font.BOLD,60));
gameOver=true;
addMouseListener(new MouseAdapter(){

public void mousePressed(MouseEvent e)
{

if(gameOver)
{
newGame();
}
else
{
int dir=0;
int ex=e.getX()-margin;
int ey=e.getY()-margin;
if(ex<0||ex>gridSize||ey<0||ey>gridSize)
return;
int c1=ex/tileSize;
int r1=ey/tileSize;
int c2=blankPos%size;
int r2=blankPos/size;
int clickPos=r1*size+c1;
if(c1==c2 && Math.abs(r1-r2)>0)

dir=(r1-r2)>0 ? size:-size;

else if(r1==r2 && Math.abs(c1-c2)>0)
dir=(c1-c2)>0? 1:-1;

if(dir!=0)
{
do {
int newBlankPos=blankPos+dir;
tiles[blankPos]=tiles[newBlankPos];
blankPos=newBlankPos;
}while(blankPos!=clickPos);
tiles[blankPos]=0;
}
gameOver=isSolved();
}
repaint();
}
});
newGame();

}
private void newGame() {
do {
reset();
shuffle();
}while(!isSolvable());
gameOver=false;
}
private void reset() {
for(int i=0;i<tiles.length;i++) {
tiles[i]=(i+1)%tiles.length;
}
blankPos=tiles.length-1;
}
private void shuffle()
{
int n=nbTiles;
while(n>1)
{
int r=RANDOM.nextInt(n--);
int tmp=tiles[r];
tiles[r]=tiles[n];
tiles[n]=tmp;
}
}
private boolean isSolvable()
{
int countInversions=0;
for(int i=0;i<nbTiles;i++)
{
for(int j=0;j<i;j++)
{
if(tiles[j]>tiles[i])
countInversions++;
}
}
return countInversions%2==0;
}
private boolean isSolved()
{
if(tiles[tiles.length-1]!=0)
return false;
for(int i=nbTiles-1;i>=0;i--)
{
if(tiles[i]!=i+1)
return false;
}
return true;
}
private void drawGrid(Graphics2D g)
{
for(int i=0;i<tiles.length;i++)
{
int r=i/size;
int c=i%size;
int x=margin+c*tileSize;
int y=margin+r*tileSize;
if(tiles[i]==0) {
if(gameOver) {
g.setColor(FOREGROUND_COLOR);
drawCenteredString(g,"|///",x,y);
}
continue;
}
g.setColor(getForeground());
g.fillRoundRect(x, y, tileSize, tileSize, 25, 25);
g.setColor(Color.BLACK);
g.drawRoundRect(x,y,tileSize,tileSize,25,25);
g.setColor(Color.WHITE);
drawCenteredString(g,String.valueOf(tiles[i]),x,y);
}
}
private void drawStartMessage(Graphics2D g) {
if(gameOver) {
g.setFont(getFont().deriveFont(Font.BOLD,18));
g.setColor(FOREGROUND_COLOR);
String s="Click to start new game";
g.drawString(s, (getWidth()-g.getFontMetrics().stringWidth(s))/2, getHeight()-margin);
}
}
private void drawCenteredString(Graphics2D g,String s,int x,int y)
{
FontMetrics fm=g.getFontMetrics();
int asc=fm.getAscent();
int desc=fm.getDescent();
g.drawString(s,x+(tileSize-fm.stringWidth(s))/2,y+(asc+(tileSize-(asc+desc))/2));
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2D=(Graphics2D)g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
drawGrid(g2D);
drawStartMessage(g2D);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(() ->
{
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Game of Fifteen");
frame.setResizable(false);
frame.add(new GameOfFifteen(4,550,30),BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}

read less
Comments
Dislike Bookmark

Lesson Posted on 04 Jul IT Courses/Java/Core Java

COMPILATION AND INTERPRETATION

Khushi Agarwal

1- Year Online Teaching Experience 1- Year It Industry Exposure Technical Skills Core Java - Basic...

Compilation and Interpertation Process javac (compiler) java(interpreter)high level code - > compile - > bytecode - > interperted - > machine code Bytecode is intermediate code generated by compiler, this is same will be for all the systems/computersthat... read more

Compilation and Interpertation Process

                          javac (compiler)             java(interpreter)
high level code - > compile - > bytecode - > interperted - > machine code


Bytecode is intermediate code generated by compiler, this is same will be for all the systems/computers
that is why our java is portable and independent programming language.

COMMAND TO EXECUTE PROGRAM ON COMMAND PROMPT

ASSUMING WE CREATED A JAVA PROGRAM WITH CLASS NAME Calculator.java

1. javac Calculator.java // compilation is beginning, compiler generates bytecode, at once the code is compiled.

BYTECODE FILE IS SAVED AS .CLASS, for above example the file that is created is Calculator.class

2. java Calculator // interpertating is beginning, result will be generated, each and every line is checked and interperted(one - by - one)

JDK vs JRE vs JVM
JDK(JAVA DEVELOPMENT KIT) --> It holds jre, tools for the development of java application like compiler, interpreter,etc. It has physical existence in our machine.
JRE(JAVA RUNTIME ENVIRONMENT) --> it holds JVM + Java libraries and is physically present in our system.
JVM(JAVA VIRTUAL MACTINE) --> it is a virutal machine that helps to load code, verify code, and execute code.

read less
Comments
Dislike Bookmark

Lesson Posted on 23 May IT Courses/Java/Core Java

CONDITIONAL STATEMENT - IF ELSE

Khushi Agarwal

1- Year Online Teaching Experience 1- Year It Industry Exposure Technical Skills Core Java - Basic...

1. IF condition only if is true conditon is required. if(condition){//statements} 2. IF-ELSE condition 1. to check whether the condition will be true or false.syntax of if-else2. only 1 conditionif(condition){//statements}else{//statements} 3. if - else if we can add "else if" to execute multiple... read more

1. IF condition

only if is true conditon is required.

if(condition)
{
//statements
}


2. IF-ELSE condition

1. to check whether the condition will be true or false.
syntax of if-else
2. only 1 condition
if(condition)
{
//statements
}
else
{
//statements
}


3. if - else if

we can add "else if" to execute multiple conditions

syntax
if(condition)
{
//statements
}
else if(condition)
{
//statements
}
else if(condition)
{
//statement
}
else
{
//statement
}


4. Nested if-else condition
if(condition)
{
//statements
if(condition)
{
//statement
}
else
{
//statement
}
//statement
}
else
{
//statements
if(condition)
{
// statement
}
else if(condition)
{
//statement
}
else
{
//statement
}
}

read less
Comments
Dislike Bookmark

Looking for Java Training Classes

Find best Java Training Classes in your locality on UrbanPro.

FIND NOW

Answered on 08 Apr IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

What has been your experience using React.js as a developer?

Ajay Sharma

Tutor

According to a friend of mine who works on the same profile, he is very happy. He has plenty of opportunities as a React.js developer and considers it a technology which gives the users great performance.
Answers 1 Comments
Dislike Bookmark

Answered on 12 Feb IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

Manish Bhardwaj

Math Guru

JavaScript is easy to learn as well it will be used with python and java for further applications. Comparing Java and Java Script is like to compare orange and apple.
Answers 4 Comments
Dislike Bookmark

Answered on 24 Feb IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

Madhuchary

Yes
Answers 4 Comments
Dislike Bookmark

Answered on 25 Mar IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

What are the programming languages most popular in 2019?

Star Tuition

Professional Trainer with 15yrs. exp. Improvement In Scores Guaranteed.

Core java, php, python
Answers 2 Comments
Dislike Bookmark

Answered on 25 Mar IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

Is JavaScript hard to learn?

Star Tuition

Professional Trainer with 15yrs. exp. Improvement In Scores Guaranteed.

vevy easy to learn.
Answers 2 Comments
Dislike Bookmark

Answered on 13/12/2018 IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

What are the pro and cons of writing your own JavaScript framework instead of using the existing ones?

Mohd Umar

Get coached by Industry Professional

Writing any f/w requires a lot of work, design decisions, target architectures, plugabillity, how easy it will be to learn, threading and asynchronous handling and many others. Most of the time you'll have to identify the gaps in the existing f/w that you're trying to achieve in the new f/w. You'll have... read more

Writing any f/w requires a lot of work, design decisions, target architectures, plugabillity, how easy it will be to learn, threading and asynchronous handling and many others. Most of the time you'll have to identify the gaps in the existing f/w that you're trying to achieve in the new f/w. You'll have to interact with a lot of experienced developers to find out what they are missing in a given f/w and how likely is your f/w going to address those gaps.

read less
Answers 2 Comments
Dislike Bookmark

Looking for Java Training Classes

Find best Java Training Classes in your locality on UrbanPro.

FIND NOW

Answered on 08 Apr IT Courses/Java IT Courses/Java Script Training Tuition/BCA Tuition/Java Programming +1 IT Courses/Java/Core Java less

What reliable React js development companies you can suggest?

Ajay Sharma

Tutor

There are many. I have a friend working on the same profile in 3Pillar Global. He has always had positive reviews about them.
Answers 1 Comments
Dislike Bookmark

About UrbanPro

UrbanPro.com helps you to connect with the best Java Training Classes in India. Post Your Requirement today and get connected.

Overview

Questions 277

Lessons 43

Total Shares  

+ Follow 59,141 Followers

Related Topics

Top Contributors

Connect with Expert Tutors & Institutes for Core Java

x

Ask a Question

Please enter your Question

Please select a Tag

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more