Objective:
Create a graphical game of minesweeper IN JAVA. The board should consist of 10x10 buttons.
Of the 100 spaces there should be at least 20 randomly placed mines. If the button is clicked and
it is not a mine then it clears itself. If a space has been cleared then it should indicate how many
of its eight neighbors are mines. If a space is clicked and it is a mine then the game is over and
the player is asked if they want to play again. Finally, if all the non-mine spaces have been
clicked then the player is prompted that they won.
Solution
2 files need to be made.
First Game.Java which will have the gaming logic and User Interface and Main.Java which will
have have the main method and object of Game.java Number of rows and cols is customizable so
user can change that as and when needed.
import java.awt.*;
import java.awt.Dimension;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Game extends JFrame implements ActionListener, ContainerListener {
int fw, fh, blockr, blockc, var1, var2, num_of_mine, detectedmine = 0, savedlevel = 1,
savedblockr, savedblockc, savednum_of_mine = 10;
int[] r = {-1, -1, -1, 0, 1, 1, 1, 0};
int[] c = {-1, 0, 1, 1, 1, 0, -1, -1};
JButton[][] blocks;
int[][] countmine;
int[][] colour;
ImageIcon[] ic = new ImageIcon[14];
JPanel panelb = new JPanel();
JPanel panelmt = new JPanel();
JTextField tf_mine, tf_time;
JButton reset = new JButton(\"\");
Random ranr = new Random();
Random ranc = new Random();
boolean check = true, starttime = false;
Point framelocation;
Stopwatch sw;
MouseHendeler mh;
Point p;
Game() {
super(\"Game\");
setLocation(400, 300);
setic();
setpanel(1, 0, 0, 0);
setmanue();
sw = new Stopwatch();
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
sw.stop();
setpanel(savedlevel, savedblockr, savedblockc, savednum_of_mine);
} catch (Exception ex) {
setpanel(savedlevel, savedblockr, savedblockc, savednum_of_mine);
}
reset();
}
});
setDefaultCloseOperation(EXIT_ON_CLOSE);
show();
}
public void reset() {
check = true;
starttime = false;
for (int i = 0; i < blockr; i++) {
for (int j = 0; j < blockc; j++) {
colour[i][j] = \'w\';
}
}
}
public void setpanel(int level, int setr, int setc, int setm) {
if (level == 1) {
fw = 200;
fh = 300;
blockr = 10;
blockc = 10;
num_of_mine = 10;
} else if (level == 2) {
fw = 320;
fh = 416;
blockr = 16;
blockc = 16;
num_of_mine = 70;
} else if (level == 3) {
fw = 400;
fh = 520;
blockr = 20;
blockc = 20;
num_of_mine = 150;
} else if (level == 4) {
fw = (20 * setc);
fh = (24 * setr);
blockr = setr;
blockc = setc;
num_of_mine = setm;
}
savedblockr = blockr;
savedblockc = blockc;
savednum_of_mine = num_of_mine;
setSize(fw, fh);
setResizable(false);
detectedmine = num_of_mine;
p = this.getLocation();
blocks = new JButton[blockr][blockc];
countmine = new int[blockr][blockc];
colour = new int[blockr][blockc];
mh = new MouseHendeler();
getContentPane().removeAll();
panelb.removeAll();
tf_mine = new JTe.
Need help writing the code for a basic java tic tac toe game Tic.pdfhainesburchett26321
Need help writing the code for a basic java tic tac toe game
// Tic-Tac-Toe: Complete the FIX-ME\'s to have a working version of Tic-Tac-Toe.
// Note: the basis of the game is a two-dimensional \'board\' array, with 3 rows
// and 3 columns. A value of +1 indicates an \'X\' on the board; and a value of
// -1 indicates an \'O\'
// Group Member names:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.*;
public class TicTacToe implements ActionListener{
// FIX ME #5: set CPU_PAUSE to true when ready to play
final boolean CPU_PAUSE = true; // does the CPU pause to think?
JButton [][] buttons = new JButton[3][3];
int [][] board = new int[3][3];
JLabel status = new JLabel(\"Player\'s turn\", JLabel.CENTER);
JFrame frame = new JFrame();
JPanel buttonPanel = new JPanel();
JPanel labelPanel = new JPanel();
Timer timer = null;
// draw X or O depending on \'x\' values
void refresh(int [][] x) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (x[i][j] == 1) {
buttons[i][j].setForeground(Color.blue);
buttons[i][j].setText(\"X\");
} else if (x[i][j] == -1) {
buttons[i][j].setForeground(Color.pink);
buttons[i][j].setText(\"O\");
} else {
buttons[i][j].setText(\" \");
}
}
}
}
boolean have_winner(int checkVal) {
boolean winner = false;
// FIX ME #1: if there are three \'checkVal\' values in-a-row across,
// then set \'winner\' to true
// FIX ME #2: if there are three \'checkVal\' values in-a-row vertically,
// then set \'winner\' to true
int checkSum = 0;
if (checkSum == 3 * checkVal){
winner = true;
}
// FIX ME #3: if there are three \'checkVal\' values in-a-row diagonally,
// then set \'winner\' to true
return winner;
}
boolean playerMove(ActionEvent e) {
JButton btn = (JButton) e.getSource();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (btn.equals(buttons[i][j])) {
if (board[i][j] != 0) {
return false;
}
board[i][j] = 1;
refresh(board);
return true;
}
}
}
return false;
}
boolean board_is_full() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (board[i][j] == 0) return false;
}
}
return true;
}
ActionListener refreshListener = new ActionListener(){
int delayCount = 0;
public void actionPerformed(ActionEvent event){
delayCount++;
if (delayCount > 5) {
delayCount = 0;
timer.stop();
enableButtons(false);
}
if (delayCount % 2 == 0) {
refresh(board);
} else {
int [][] x = new int[3][3];
refresh(x);
}
}
};
void enableButtons(boolean enable) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
buttons[i][j].setEnabled(enable);
}
}
}
ActionListener computerMove = new ActionListener(){
public void actionPerformed(ActionEvent event){
/* FIX ME #4: The computer moves by placing an \'O\' on the board
* (i.e.), assigning a -1 to a valid element of the board array
* The computer can play randomly, by randomly selecting a
* row and column to play .
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfformaxekochi
Tic Tac Toe game with GUI please don\'t copy and paste from google. I really need the help.
Solution
Answer:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class TicTacToe extends JPanel
{
JButton buttons[] = new JButton[9];
int alternate = 0;//if this number is a even, then put a X. If it\'s odd, then put an O
public TicTacToe()
{
setLayout(new GridLayout(3,3));
initializebuttons();
}
public void initializebuttons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i] = new JButton();
buttons[i].setText(\"\");
buttons[i].addActionListener(new buttonListener());
add(buttons[i]); //adds this button to JPanel (note: no need for JPanel.add(...)
//because this whole class is a JPanel already
}
}
public void resetButtons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i].setText(\"\");
}
}
// when a button is clicked, it generates an ActionEvent. Thus, each button needs an
ActionListener. When it is clicked, it goes to this listener class that I have created and goes to the
actionPerformed method. There (and in this class), we decide what we want to do.
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton buttonClicked = (JButton)e.getSource(); //get the particular button that was clicked
if(alternate%2 == 0)
buttonClicked.setText(\"X\");
else
buttonClicked.setText(\"O\");
if(checkForWin() == true)
{
JOptionPane.showConfirmDialog(null, \"Game Over.\");
resetButtons();
}
alternate++;
}
public boolean checkForWin()
{
/** Reference: the button array is arranged like this as the board
* 0 | 1 | 2
* 3 | 4 | 5
* 6 | 7 | 8
*/
//horizontal win check
if( checkAdjacent(0,1) && checkAdjacent(1,2) ) //no need to put \" == true\" because the
default check is for true
return true;
else if( checkAdjacent(3,4) && checkAdjacent(4,5) )
return true;
else if ( checkAdjacent(6,7) && checkAdjacent(7,8))
return true;
//vertical win check
else if ( checkAdjacent(0,3) && checkAdjacent(3,6))
return true;
else if ( checkAdjacent(1,4) && checkAdjacent(4,7))
return true;
else if ( checkAdjacent(2,5) && checkAdjacent(5,8))
return true;
//diagonal win check
else if ( checkAdjacent(0,4) && checkAdjacent(4,8))
return true;
else if ( checkAdjacent(2,4) && checkAdjacent(4,6))
return true;
else
return false;
}
public boolean checkAdjacent(int a, int b)
{
if ( buttons[a].getText().equals(buttons[b].getText()) && !buttons[a].getText().equals(\"\") )
return true;
else
return false;
}
}
public static void main(String[] args)
{
JFrame window = new JFrame(\"Tic-Tac-Toe\");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().add(new TicTacToe());
window.setBounds(300,200,300,300);
window.setVisible(true);
}
}.
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from
JPanel. Therefore, the panel you are asked to add to the center of the content pane is the \"game\"
object. 2. In part 4, at the end of the function, call validate(). This is not mentioned in the book,
but it is mentioned in the framework comments.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Game extends JPanel
{
private JButton [][] squares;
private TilePuzzle game;
public Game( int newSide )
{
game = new TilePuzzle( newSide );
setUpGameGUI( );
}
public void setUpGame( int newSide )
{
game.setUpGame( newSide );
setUpGameGUI( );
}
public void setUpGameGUI( )
{
removeAll( ); // remove all components
setLayout( new GridLayout( game.getSide( ),
game.getSide( ) ) );
squares = new JButton[game.getSide( )][game.getSide( )];
ButtonHandler bh = new ButtonHandler( );
// for each button: generate button label,
// instantiate button, add to container,
// and register listener
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j] = new JButton( game.getTiles( )[i][j] );
add( squares[i][j] );
squares[i][j].addActionListener( bh );
}
}
setSize( 300, 300 );
setVisible( true );
}
private void update( int row, int col )
{
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j].setText( game.getTiles( )[i][j] );
}
}
if ( game.won( ) )
{
JOptionPane.showMessageDialog( Game.this,
\"Congratulations! You won!\ Setting up new game\" );
// int sideOfPuzzle = 3 + (int) ( 4 * Math.random( ) );
// setUpGameGUI( );
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent ae )
{
for( int i = 0; i < game.getSide( ); i++ )
{
for( int j = 0; j < game.getSide( ); j++ )
{
if ( ae.getSource( ) == squares[i][j] )
{
if ( game.tryToPlay( i, j ) )
update( i, j );
return;
} // end if
} // end inner for loop
} // outer for loop
} // end actionPerformed method
} // end ButtonHandler class
} // end Game class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NestedLayoutPractice extends JFrame
{
private Container contents;
private Game game;
private BorderLayout bl;
private JLabel bottom;
// ***** Task 1: declare a JPanel named top
// also declare three JButton instance variables
// that will be added to the JPanel top
// these buttons will determine the grid size of the game:
// 3-by-3, 4-by-4, or 5-by-5
// Part 1 student code starts here:
// Part 1 student code ends here.
public NestedLayoutPractice()
{
super(\"Practicing layout managers\");
contents = getContentPane();
// ***** Task 2:
// instantiate the BorderLayout manager bl
// Part 2 student code starts here:
// set the layout manager of the content pane contents to bl:
game = new Game(3); // instantiating the GamePanel object
// add panel (game) to the center of the content pane
// Part 2 student code ends here.
bottom = new JLabel(.
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
In Java using Eclipse, I\'m suppose to write a class that encapsulates a tic tac toe board using two
dimensional arrays. It should only involve the human player vs. the computer, and should
randomly select who should use \'X\' or \'O\' and whether the human player or the computer
should go first. Verify that all moves by the human player are to a valid space on the tic-tac-toe
board, and an incorrect choice should not halt or terminate the game. Below is my Java program
that is currently a work in progress. Can you help me remodify it? Thanks.
import java.util.Scanner;
public class LeavinesTicTacToe
{
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
final int SIZE = 3;
char[][] board = new char[SIZE][SIZE]; // game board
resetBoard(board); // initialize the board (with \' \' for all cells)
// First, welcome message and display the board.
System.out.println(\"===== WELCOME TO THE TIC-TAC-TOE GAME!! =====\ \");
showBoard(board);
// Then ask the user which symbol (x or o) he/she wants to play.
System.out.print(\" Which symbol do you want to play, \\\"x\\\" or \\\"o\\\"? \");
char userSymbol = sc.next().toLowerCase().charAt(0);
char compSymbol = (userSymbol == \'x\') ? \'o\' : \'x\';
// Also ask whether or not the user wants to go first.
System.out.println();
System.out.print(\" Do you want to go first (y/n)? \");
char ans = sc.next().toLowerCase().charAt(0);
int turn; // 0 -- the user, 1 -- the computer
int remainCount = SIZE * SIZE; // empty cell count
// THE VERY FIRST MOVE.
if (ans == \'y\') {
turn = 0;
userPlay(board, userSymbol); // user puts his/her first tic
}
else {
turn = 1;
compPlay(board, compSymbol); // computer puts its first tic
}
// Show the board, and decrement the count of remaining cells.
showBoard(board);
remainCount--;
// Play the game until either one wins.
boolean done = false;
int winner = -1; // 0 -- the user, 1 -- the computer, -1 -- draw
while (!done && remainCount > 0) {
// If there is a winner at this time, set the winner and the done flag to true.
done = isGameWon(board, turn, userSymbol, compSymbol); // Did the turn won?
if (done)
winner = turn; // the one who made the last move won the game
else {
// No winner yet. Find the next turn and play.
turn = (turn + 1 ) % 2;
if (turn == 0)
userPlay(board, userSymbol);
else
compPlay(board, compSymbol);
// Show the board after one tic, and decrement the rem count.
showBoard(board);
remainCount--;
}
}
// Winner is found. Declare the winner.
if (winner == 0)
System.out.println(\"\ ** YOU WON. CONGRATULATIONS!! **\");
else if (winner == 1)
System.out.println(\"\ ** YOU LOST.. Maybe next time :) **\");
else
System.out.println(\"\ ** DRAW... **\");
}
public static void resetBoard(char[][] brd)
{
for (int i = 0; i < brd.length; i++)
for (int j = 0; j < brd[0].length; j++)
brd[i][j] = \' \';
}
public static void showBoard(char[][] brd)
{
int numRow = brd.length;
int numCol = brd[0].length;
System.out.println();
// First write the column he.
java code please Add event handlers to the buttons in your TicTacToe.pdfezzi97
java code please Add event handlers to the buttons in your TicTacToe GUI so that label of the
first button clicked changes to X, the second button clicked changes to O, the third button clicked
changes to X, etc. Clicking a button that already contains an X or O should have no effect. The
Game Status label at the bottom should start out saying \"Player 1\'s turn\", and then change to
\"Player 2\'s turn\" after the first click, then back to \"Player 1\'s turn\" and so on. You do not
need to recognize when the game has ended, but that might be a good challenge to take on if you
have some extra time.
Solution
A)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TicGUI extends JFrame
{
JFrame frame = new JFrame(\"TicTacToe\");
JButton[][] buttons = new JButton[3][3];
JButton start = new JButton(\"Start\");
JButton reset = new JButton(\"Reset\");
JOptionPane turn;
int moveCounter = 9;
boolean gameWon = false;
public TicGUI()
{
super();
frame.setSize(350, 450);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
}
private void checkWin(int row, int col)
{
if(buttons[row][0].getText()==buttons[row][1].getText()&&
buttons[row][1].getText()==buttons[row][2].getText())
{
gameWon = true;
System.out.println(buttons[row][0].getText()+ \" wins!!!\");
}
else if(buttons[0][col].getText()==buttons[1][col].getText()&&
buttons[1][col].getText()==buttons[2][col].getText())
{
gameWon = true;
System.out.println(buttons[row][0].getText()+ \" wins!!!\");
}
}
private void compTurn(int count)
{
int randomMove=count;
Random num = new Random();
randomMove = num.nextInt(randomMove)+1;
while(gameWon ==false)
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(buttons[i][j].isEnabled()==true)
{
randomMove;
if(randomMove==0 )
{
buttons[i][j].setText(\"O\");
buttons[i][j].setEnabled(false);
moveCounter--;
checkWin(i, j);
}
}
}
}
}
}
private void initialize()
{
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel menu = new JPanel(new BorderLayout());
JPanel game = new JPanel(new GridLayout(3,3));
frame.add(mainPanel);
mainPanel.setPreferredSize(new Dimension(215,315));
menu.setPreferredSize(new Dimension(300,50));
game.setPreferredSize(new Dimension(300,300));
mainPanel.add(menu, BorderLayout.NORTH);
mainPanel.add(game, BorderLayout.SOUTH);
menu.add(start, BorderLayout.WEST);
menu.add(reset, BorderLayout.EAST);
start.addActionListener(new myActionListener());
reset.addActionListener(new myActionListener());
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
buttons[i][j] = new JButton();
buttons[i][j].setText(\"\");
buttons[i][j].setVisible(true);
game.add(buttons[i][j]);
buttons[i][j].addActionListener(new myActionListener());
}
}
}
private class myActionListener implements ActionListener
{ //Implementing action listener for buttons
public void actionPerformed(ActionEvent a)
{
if(a.getSource() == buttons[0][0])
{
buttons[0][0].setText(\"X\");
buttons[0][0].s.
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdfinfomalad
Tic Tac Toe game with GUI written in java.
Solution
Answer:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class TicTacToe extends JPanel
{
JButton buttons[] = new JButton[9];
int alternate = 0;//if this number is a even, then put a X. If it\'s odd, then put an O
public TicTacToe()
{
setLayout(new GridLayout(3,3));
initializebuttons();
}
public void initializebuttons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i] = new JButton();
buttons[i].setText(\"\");
buttons[i].addActionListener(new buttonListener());
add(buttons[i]); //adds this button to JPanel (note: no need for JPanel.add(...)
//because this whole class is a JPanel already
}
}
public void resetButtons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i].setText(\"\");
}
}
// when a button is clicked, it generates an ActionEvent. Thus, each button needs an
ActionListener. When it is clicked, it goes to this listener class that I have created and goes to the
actionPerformed method. There (and in this class), we decide what we want to do.
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton buttonClicked = (JButton)e.getSource(); //get the particular button that was clicked
if(alternate%2 == 0)
buttonClicked.setText(\"X\");
else
buttonClicked.setText(\"O\");
if(checkForWin() == true)
{
JOptionPane.showConfirmDialog(null, \"Game Over.\");
resetButtons();
}
alternate++;
}
public boolean checkForWin()
{
/** Reference: the button array is arranged like this as the board
* 0 | 1 | 2
* 3 | 4 | 5
* 6 | 7 | 8
*/
//horizontal win check
if( checkAdjacent(0,1) && checkAdjacent(1,2) ) //no need to put \" == true\" because the
default check is for true
return true;
else if( checkAdjacent(3,4) && checkAdjacent(4,5) )
return true;
else if ( checkAdjacent(6,7) && checkAdjacent(7,8))
return true;
//vertical win check
else if ( checkAdjacent(0,3) && checkAdjacent(3,6))
return true;
else if ( checkAdjacent(1,4) && checkAdjacent(4,7))
return true;
else if ( checkAdjacent(2,5) && checkAdjacent(5,8))
return true;
//diagonal win check
else if ( checkAdjacent(0,4) && checkAdjacent(4,8))
return true;
else if ( checkAdjacent(2,4) && checkAdjacent(4,6))
return true;
else
return false;
}
public boolean checkAdjacent(int a, int b)
{
if ( buttons[a].getText().equals(buttons[b].getText()) && !buttons[a].getText().equals(\"\") )
return true;
else
return false;
}
}
public static void main(String[] args)
{
JFrame window = new JFrame(\"Tic-Tac-Toe\");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().add(new TicTacToe());
window.setBounds(300,200,300,300);
window.setVisible(true);
}
}.
Hello!This is Java assignment applet.Can someone help me writing.pdfjyothimuppasani1
Hello!
This is Java assignment applet.
Can someone help me writing a code how to exit the game when I press no in question( would
you like to play again?). Also if no one wins or draws i would like to pop up the question ( would
you like to play again?). I have the code below i would like someone to add it
Thanks in advance!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class TicTacToe extends Applet implements ActionListener{
// Array to store buttons
JButton button[][] = new JButton[3][3];
boolean isNewGame =false;
// To switch player either X or O
boolean isZero = true; //first turn is always 0
// Setup size
// Set layout to grid
// Create buttons through loop
// Add buttons to layout
// Add listener
public void init(){
setSize(500, 500);
setLayout(new GridLayout(3,3));
// if it is not a new game
if(isNewGame==false) {
// Adding buttons to layout
//initialize the Grid and add ActionListener to each Button
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
// init jButton
button[i][j] = new JButton(\"\");
// Setup Font and Size here
button[i][j].setFont(new Font(\"Lucida Grande\", Font.PLAIN, 28));
// Add is a method from applet to add buttons in layout
add(button[i][j]);
// Listener
button[i][j].addActionListener(this);
}
}
}
else {
// If we need to restart the game, then we only set text to empty
// Back to black color
// add listener
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
button[i][j].setText(\"\");
button[i][j].setForeground(Color.BLACK);
button[i][j].removeActionListener(this);
button[i][j].addActionListener(this);
}
}
}
}
// Go all the buttons in arrsy
// Check the event with button in array
// if player O is true, set button text O. Otherwise. X
// Remove Listerner. Why? only once you can click
// Change player by isZero
// Check for winner
public void actionPerformed(ActionEvent event){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++){
if((event.getSource() == button[i][j])){
if(isZero){
button[i][j].setText(\"O\");
}
else{
button[i][j].setText(\"X\");
}
button[i][j].removeActionListener(this); //you cannot click on one tile more than
once
isZero = !isZero;
checkForWinners(); //check if any winner after each move
}
}
}
public void checkForWinners(){
//3 horizontal lines
for(int i = 0; i < 3; i++){
if(button[i][0].getText().equals(button[i][1].getText())
&& button[i][1].getText().equals(button[i][2].getText())
&& !button[i][0].getText().equals(\"\")){
String player = button[i][0].getText();
button[i][0].setForeground(Color.RED);
button[i][1].setForeground(Color.RED);
button[i][2].setForeground(Color.RED);
int reply =JOptionPane.showConfirmDialog(null, player + \" wins!\"+\"\ Would like
to play again?\",\"Game over\",JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
isNewGame = true;
init();
return;
}
else {
System.exit(0);
return;
}
}
}
//3 vertical lines
for(int i = 0; i < 3; i++){
if(button[0][i].getText().equals(button[1][i].getText())
&& .
Need help writing the code for a basic java tic tac toe game Tic.pdfhainesburchett26321
Need help writing the code for a basic java tic tac toe game
// Tic-Tac-Toe: Complete the FIX-ME\'s to have a working version of Tic-Tac-Toe.
// Note: the basis of the game is a two-dimensional \'board\' array, with 3 rows
// and 3 columns. A value of +1 indicates an \'X\' on the board; and a value of
// -1 indicates an \'O\'
// Group Member names:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.*;
public class TicTacToe implements ActionListener{
// FIX ME #5: set CPU_PAUSE to true when ready to play
final boolean CPU_PAUSE = true; // does the CPU pause to think?
JButton [][] buttons = new JButton[3][3];
int [][] board = new int[3][3];
JLabel status = new JLabel(\"Player\'s turn\", JLabel.CENTER);
JFrame frame = new JFrame();
JPanel buttonPanel = new JPanel();
JPanel labelPanel = new JPanel();
Timer timer = null;
// draw X or O depending on \'x\' values
void refresh(int [][] x) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (x[i][j] == 1) {
buttons[i][j].setForeground(Color.blue);
buttons[i][j].setText(\"X\");
} else if (x[i][j] == -1) {
buttons[i][j].setForeground(Color.pink);
buttons[i][j].setText(\"O\");
} else {
buttons[i][j].setText(\" \");
}
}
}
}
boolean have_winner(int checkVal) {
boolean winner = false;
// FIX ME #1: if there are three \'checkVal\' values in-a-row across,
// then set \'winner\' to true
// FIX ME #2: if there are three \'checkVal\' values in-a-row vertically,
// then set \'winner\' to true
int checkSum = 0;
if (checkSum == 3 * checkVal){
winner = true;
}
// FIX ME #3: if there are three \'checkVal\' values in-a-row diagonally,
// then set \'winner\' to true
return winner;
}
boolean playerMove(ActionEvent e) {
JButton btn = (JButton) e.getSource();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (btn.equals(buttons[i][j])) {
if (board[i][j] != 0) {
return false;
}
board[i][j] = 1;
refresh(board);
return true;
}
}
}
return false;
}
boolean board_is_full() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (board[i][j] == 0) return false;
}
}
return true;
}
ActionListener refreshListener = new ActionListener(){
int delayCount = 0;
public void actionPerformed(ActionEvent event){
delayCount++;
if (delayCount > 5) {
delayCount = 0;
timer.stop();
enableButtons(false);
}
if (delayCount % 2 == 0) {
refresh(board);
} else {
int [][] x = new int[3][3];
refresh(x);
}
}
};
void enableButtons(boolean enable) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
buttons[i][j].setEnabled(enable);
}
}
}
ActionListener computerMove = new ActionListener(){
public void actionPerformed(ActionEvent event){
/* FIX ME #4: The computer moves by placing an \'O\' on the board
* (i.e.), assigning a -1 to a valid element of the board array
* The computer can play randomly, by randomly selecting a
* row and column to play .
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfformaxekochi
Tic Tac Toe game with GUI please don\'t copy and paste from google. I really need the help.
Solution
Answer:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class TicTacToe extends JPanel
{
JButton buttons[] = new JButton[9];
int alternate = 0;//if this number is a even, then put a X. If it\'s odd, then put an O
public TicTacToe()
{
setLayout(new GridLayout(3,3));
initializebuttons();
}
public void initializebuttons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i] = new JButton();
buttons[i].setText(\"\");
buttons[i].addActionListener(new buttonListener());
add(buttons[i]); //adds this button to JPanel (note: no need for JPanel.add(...)
//because this whole class is a JPanel already
}
}
public void resetButtons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i].setText(\"\");
}
}
// when a button is clicked, it generates an ActionEvent. Thus, each button needs an
ActionListener. When it is clicked, it goes to this listener class that I have created and goes to the
actionPerformed method. There (and in this class), we decide what we want to do.
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton buttonClicked = (JButton)e.getSource(); //get the particular button that was clicked
if(alternate%2 == 0)
buttonClicked.setText(\"X\");
else
buttonClicked.setText(\"O\");
if(checkForWin() == true)
{
JOptionPane.showConfirmDialog(null, \"Game Over.\");
resetButtons();
}
alternate++;
}
public boolean checkForWin()
{
/** Reference: the button array is arranged like this as the board
* 0 | 1 | 2
* 3 | 4 | 5
* 6 | 7 | 8
*/
//horizontal win check
if( checkAdjacent(0,1) && checkAdjacent(1,2) ) //no need to put \" == true\" because the
default check is for true
return true;
else if( checkAdjacent(3,4) && checkAdjacent(4,5) )
return true;
else if ( checkAdjacent(6,7) && checkAdjacent(7,8))
return true;
//vertical win check
else if ( checkAdjacent(0,3) && checkAdjacent(3,6))
return true;
else if ( checkAdjacent(1,4) && checkAdjacent(4,7))
return true;
else if ( checkAdjacent(2,5) && checkAdjacent(5,8))
return true;
//diagonal win check
else if ( checkAdjacent(0,4) && checkAdjacent(4,8))
return true;
else if ( checkAdjacent(2,4) && checkAdjacent(4,6))
return true;
else
return false;
}
public boolean checkAdjacent(int a, int b)
{
if ( buttons[a].getText().equals(buttons[b].getText()) && !buttons[a].getText().equals(\"\") )
return true;
else
return false;
}
}
public static void main(String[] args)
{
JFrame window = new JFrame(\"Tic-Tac-Toe\");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().add(new TicTacToe());
window.setBounds(300,200,300,300);
window.setVisible(true);
}
}.
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from
JPanel. Therefore, the panel you are asked to add to the center of the content pane is the \"game\"
object. 2. In part 4, at the end of the function, call validate(). This is not mentioned in the book,
but it is mentioned in the framework comments.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Game extends JPanel
{
private JButton [][] squares;
private TilePuzzle game;
public Game( int newSide )
{
game = new TilePuzzle( newSide );
setUpGameGUI( );
}
public void setUpGame( int newSide )
{
game.setUpGame( newSide );
setUpGameGUI( );
}
public void setUpGameGUI( )
{
removeAll( ); // remove all components
setLayout( new GridLayout( game.getSide( ),
game.getSide( ) ) );
squares = new JButton[game.getSide( )][game.getSide( )];
ButtonHandler bh = new ButtonHandler( );
// for each button: generate button label,
// instantiate button, add to container,
// and register listener
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j] = new JButton( game.getTiles( )[i][j] );
add( squares[i][j] );
squares[i][j].addActionListener( bh );
}
}
setSize( 300, 300 );
setVisible( true );
}
private void update( int row, int col )
{
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j].setText( game.getTiles( )[i][j] );
}
}
if ( game.won( ) )
{
JOptionPane.showMessageDialog( Game.this,
\"Congratulations! You won!\ Setting up new game\" );
// int sideOfPuzzle = 3 + (int) ( 4 * Math.random( ) );
// setUpGameGUI( );
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent ae )
{
for( int i = 0; i < game.getSide( ); i++ )
{
for( int j = 0; j < game.getSide( ); j++ )
{
if ( ae.getSource( ) == squares[i][j] )
{
if ( game.tryToPlay( i, j ) )
update( i, j );
return;
} // end if
} // end inner for loop
} // outer for loop
} // end actionPerformed method
} // end ButtonHandler class
} // end Game class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NestedLayoutPractice extends JFrame
{
private Container contents;
private Game game;
private BorderLayout bl;
private JLabel bottom;
// ***** Task 1: declare a JPanel named top
// also declare three JButton instance variables
// that will be added to the JPanel top
// these buttons will determine the grid size of the game:
// 3-by-3, 4-by-4, or 5-by-5
// Part 1 student code starts here:
// Part 1 student code ends here.
public NestedLayoutPractice()
{
super(\"Practicing layout managers\");
contents = getContentPane();
// ***** Task 2:
// instantiate the BorderLayout manager bl
// Part 2 student code starts here:
// set the layout manager of the content pane contents to bl:
game = new Game(3); // instantiating the GamePanel object
// add panel (game) to the center of the content pane
// Part 2 student code ends here.
bottom = new JLabel(.
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
In Java using Eclipse, I\'m suppose to write a class that encapsulates a tic tac toe board using two
dimensional arrays. It should only involve the human player vs. the computer, and should
randomly select who should use \'X\' or \'O\' and whether the human player or the computer
should go first. Verify that all moves by the human player are to a valid space on the tic-tac-toe
board, and an incorrect choice should not halt or terminate the game. Below is my Java program
that is currently a work in progress. Can you help me remodify it? Thanks.
import java.util.Scanner;
public class LeavinesTicTacToe
{
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
final int SIZE = 3;
char[][] board = new char[SIZE][SIZE]; // game board
resetBoard(board); // initialize the board (with \' \' for all cells)
// First, welcome message and display the board.
System.out.println(\"===== WELCOME TO THE TIC-TAC-TOE GAME!! =====\ \");
showBoard(board);
// Then ask the user which symbol (x or o) he/she wants to play.
System.out.print(\" Which symbol do you want to play, \\\"x\\\" or \\\"o\\\"? \");
char userSymbol = sc.next().toLowerCase().charAt(0);
char compSymbol = (userSymbol == \'x\') ? \'o\' : \'x\';
// Also ask whether or not the user wants to go first.
System.out.println();
System.out.print(\" Do you want to go first (y/n)? \");
char ans = sc.next().toLowerCase().charAt(0);
int turn; // 0 -- the user, 1 -- the computer
int remainCount = SIZE * SIZE; // empty cell count
// THE VERY FIRST MOVE.
if (ans == \'y\') {
turn = 0;
userPlay(board, userSymbol); // user puts his/her first tic
}
else {
turn = 1;
compPlay(board, compSymbol); // computer puts its first tic
}
// Show the board, and decrement the count of remaining cells.
showBoard(board);
remainCount--;
// Play the game until either one wins.
boolean done = false;
int winner = -1; // 0 -- the user, 1 -- the computer, -1 -- draw
while (!done && remainCount > 0) {
// If there is a winner at this time, set the winner and the done flag to true.
done = isGameWon(board, turn, userSymbol, compSymbol); // Did the turn won?
if (done)
winner = turn; // the one who made the last move won the game
else {
// No winner yet. Find the next turn and play.
turn = (turn + 1 ) % 2;
if (turn == 0)
userPlay(board, userSymbol);
else
compPlay(board, compSymbol);
// Show the board after one tic, and decrement the rem count.
showBoard(board);
remainCount--;
}
}
// Winner is found. Declare the winner.
if (winner == 0)
System.out.println(\"\ ** YOU WON. CONGRATULATIONS!! **\");
else if (winner == 1)
System.out.println(\"\ ** YOU LOST.. Maybe next time :) **\");
else
System.out.println(\"\ ** DRAW... **\");
}
public static void resetBoard(char[][] brd)
{
for (int i = 0; i < brd.length; i++)
for (int j = 0; j < brd[0].length; j++)
brd[i][j] = \' \';
}
public static void showBoard(char[][] brd)
{
int numRow = brd.length;
int numCol = brd[0].length;
System.out.println();
// First write the column he.
java code please Add event handlers to the buttons in your TicTacToe.pdfezzi97
java code please Add event handlers to the buttons in your TicTacToe GUI so that label of the
first button clicked changes to X, the second button clicked changes to O, the third button clicked
changes to X, etc. Clicking a button that already contains an X or O should have no effect. The
Game Status label at the bottom should start out saying \"Player 1\'s turn\", and then change to
\"Player 2\'s turn\" after the first click, then back to \"Player 1\'s turn\" and so on. You do not
need to recognize when the game has ended, but that might be a good challenge to take on if you
have some extra time.
Solution
A)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TicGUI extends JFrame
{
JFrame frame = new JFrame(\"TicTacToe\");
JButton[][] buttons = new JButton[3][3];
JButton start = new JButton(\"Start\");
JButton reset = new JButton(\"Reset\");
JOptionPane turn;
int moveCounter = 9;
boolean gameWon = false;
public TicGUI()
{
super();
frame.setSize(350, 450);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
}
private void checkWin(int row, int col)
{
if(buttons[row][0].getText()==buttons[row][1].getText()&&
buttons[row][1].getText()==buttons[row][2].getText())
{
gameWon = true;
System.out.println(buttons[row][0].getText()+ \" wins!!!\");
}
else if(buttons[0][col].getText()==buttons[1][col].getText()&&
buttons[1][col].getText()==buttons[2][col].getText())
{
gameWon = true;
System.out.println(buttons[row][0].getText()+ \" wins!!!\");
}
}
private void compTurn(int count)
{
int randomMove=count;
Random num = new Random();
randomMove = num.nextInt(randomMove)+1;
while(gameWon ==false)
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(buttons[i][j].isEnabled()==true)
{
randomMove;
if(randomMove==0 )
{
buttons[i][j].setText(\"O\");
buttons[i][j].setEnabled(false);
moveCounter--;
checkWin(i, j);
}
}
}
}
}
}
private void initialize()
{
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel menu = new JPanel(new BorderLayout());
JPanel game = new JPanel(new GridLayout(3,3));
frame.add(mainPanel);
mainPanel.setPreferredSize(new Dimension(215,315));
menu.setPreferredSize(new Dimension(300,50));
game.setPreferredSize(new Dimension(300,300));
mainPanel.add(menu, BorderLayout.NORTH);
mainPanel.add(game, BorderLayout.SOUTH);
menu.add(start, BorderLayout.WEST);
menu.add(reset, BorderLayout.EAST);
start.addActionListener(new myActionListener());
reset.addActionListener(new myActionListener());
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
buttons[i][j] = new JButton();
buttons[i][j].setText(\"\");
buttons[i][j].setVisible(true);
game.add(buttons[i][j]);
buttons[i][j].addActionListener(new myActionListener());
}
}
}
private class myActionListener implements ActionListener
{ //Implementing action listener for buttons
public void actionPerformed(ActionEvent a)
{
if(a.getSource() == buttons[0][0])
{
buttons[0][0].setText(\"X\");
buttons[0][0].s.
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdfinfomalad
Tic Tac Toe game with GUI written in java.
Solution
Answer:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class TicTacToe extends JPanel
{
JButton buttons[] = new JButton[9];
int alternate = 0;//if this number is a even, then put a X. If it\'s odd, then put an O
public TicTacToe()
{
setLayout(new GridLayout(3,3));
initializebuttons();
}
public void initializebuttons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i] = new JButton();
buttons[i].setText(\"\");
buttons[i].addActionListener(new buttonListener());
add(buttons[i]); //adds this button to JPanel (note: no need for JPanel.add(...)
//because this whole class is a JPanel already
}
}
public void resetButtons()
{
for(int i = 0; i <= 8; i++)
{
buttons[i].setText(\"\");
}
}
// when a button is clicked, it generates an ActionEvent. Thus, each button needs an
ActionListener. When it is clicked, it goes to this listener class that I have created and goes to the
actionPerformed method. There (and in this class), we decide what we want to do.
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton buttonClicked = (JButton)e.getSource(); //get the particular button that was clicked
if(alternate%2 == 0)
buttonClicked.setText(\"X\");
else
buttonClicked.setText(\"O\");
if(checkForWin() == true)
{
JOptionPane.showConfirmDialog(null, \"Game Over.\");
resetButtons();
}
alternate++;
}
public boolean checkForWin()
{
/** Reference: the button array is arranged like this as the board
* 0 | 1 | 2
* 3 | 4 | 5
* 6 | 7 | 8
*/
//horizontal win check
if( checkAdjacent(0,1) && checkAdjacent(1,2) ) //no need to put \" == true\" because the
default check is for true
return true;
else if( checkAdjacent(3,4) && checkAdjacent(4,5) )
return true;
else if ( checkAdjacent(6,7) && checkAdjacent(7,8))
return true;
//vertical win check
else if ( checkAdjacent(0,3) && checkAdjacent(3,6))
return true;
else if ( checkAdjacent(1,4) && checkAdjacent(4,7))
return true;
else if ( checkAdjacent(2,5) && checkAdjacent(5,8))
return true;
//diagonal win check
else if ( checkAdjacent(0,4) && checkAdjacent(4,8))
return true;
else if ( checkAdjacent(2,4) && checkAdjacent(4,6))
return true;
else
return false;
}
public boolean checkAdjacent(int a, int b)
{
if ( buttons[a].getText().equals(buttons[b].getText()) && !buttons[a].getText().equals(\"\") )
return true;
else
return false;
}
}
public static void main(String[] args)
{
JFrame window = new JFrame(\"Tic-Tac-Toe\");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().add(new TicTacToe());
window.setBounds(300,200,300,300);
window.setVisible(true);
}
}.
Hello!This is Java assignment applet.Can someone help me writing.pdfjyothimuppasani1
Hello!
This is Java assignment applet.
Can someone help me writing a code how to exit the game when I press no in question( would
you like to play again?). Also if no one wins or draws i would like to pop up the question ( would
you like to play again?). I have the code below i would like someone to add it
Thanks in advance!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class TicTacToe extends Applet implements ActionListener{
// Array to store buttons
JButton button[][] = new JButton[3][3];
boolean isNewGame =false;
// To switch player either X or O
boolean isZero = true; //first turn is always 0
// Setup size
// Set layout to grid
// Create buttons through loop
// Add buttons to layout
// Add listener
public void init(){
setSize(500, 500);
setLayout(new GridLayout(3,3));
// if it is not a new game
if(isNewGame==false) {
// Adding buttons to layout
//initialize the Grid and add ActionListener to each Button
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
// init jButton
button[i][j] = new JButton(\"\");
// Setup Font and Size here
button[i][j].setFont(new Font(\"Lucida Grande\", Font.PLAIN, 28));
// Add is a method from applet to add buttons in layout
add(button[i][j]);
// Listener
button[i][j].addActionListener(this);
}
}
}
else {
// If we need to restart the game, then we only set text to empty
// Back to black color
// add listener
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
button[i][j].setText(\"\");
button[i][j].setForeground(Color.BLACK);
button[i][j].removeActionListener(this);
button[i][j].addActionListener(this);
}
}
}
}
// Go all the buttons in arrsy
// Check the event with button in array
// if player O is true, set button text O. Otherwise. X
// Remove Listerner. Why? only once you can click
// Change player by isZero
// Check for winner
public void actionPerformed(ActionEvent event){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++){
if((event.getSource() == button[i][j])){
if(isZero){
button[i][j].setText(\"O\");
}
else{
button[i][j].setText(\"X\");
}
button[i][j].removeActionListener(this); //you cannot click on one tile more than
once
isZero = !isZero;
checkForWinners(); //check if any winner after each move
}
}
}
public void checkForWinners(){
//3 horizontal lines
for(int i = 0; i < 3; i++){
if(button[i][0].getText().equals(button[i][1].getText())
&& button[i][1].getText().equals(button[i][2].getText())
&& !button[i][0].getText().equals(\"\")){
String player = button[i][0].getText();
button[i][0].setForeground(Color.RED);
button[i][1].setForeground(Color.RED);
button[i][2].setForeground(Color.RED);
int reply =JOptionPane.showConfirmDialog(null, player + \" wins!\"+\"\ Would like
to play again?\",\"Game over\",JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
isNewGame = true;
init();
return;
}
else {
System.exit(0);
return;
}
}
}
//3 vertical lines
for(int i = 0; i < 3; i++){
if(button[0][i].getText().equals(button[1][i].getText())
&& .
An introduction to making browser based games in JavaScript and HTML5.
This workshop was presented at an open day for the Academy of Interactive Entertainment in Sydney, Australia on November 17, 2012.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
public class Checkers extends JPanel {
public static void main(String[] args) {
JFrame window = new JFrame(\"Checkers\");
Checkers content = new Checkers();
window.setContentPane(content);
window.pack();
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation( (screensize.width - window.getWidth())/2,
(screensize.height - window.getHeight())/2 );
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
window.setResizable(false);
window.setVisible(true);
}
private JButton newGameButton; // Button for starting a new game.
private JButton resignButton; // Button that a player can use to end
// the game by resigning.
private JLabel message; // Label for displaying messages to the user.
public Checkers() {
setLayout(null); // I will do the layout myself.
setPreferredSize( new Dimension(350,250) );
setBackground(new Color(0,150,0)); // Dark green background.
/* Create the components and add them to the applet. */
Board board = new Board(); // Note: The constructor for the
// board also creates the buttons
// and label.
add(board);
add(newGameButton);
add(resignButton);
add(message);
/* Set the position and size of each component by calling
its setBounds() method. */
board.setBounds(20,20,164,164); // Note: size MUST be 164-by-164 !
newGameButton.setBounds(210, 60, 120, 30);
resignButton.setBounds(210, 120, 120, 30);
message.setBounds(0, 200, 350, 30);
} // end constructor
private static class CheckersMove {
int fromRow, fromCol; // Position of piece to be moved.
int toRow, toCol; // Square it is to move to.
CheckersMove(int r1, int c1, int r2, int c2) {
// Constructor. Just set the values of the instance variables.
fromRow = r1;
fromCol = c1;
toRow = r2;
toCol = c2;
}
boolean isJump() {
// Test whether this move is a jump. It is assumed that
// the move is legal. In a jump, the piece moves two
// rows. (In a regular move, it only moves one row.)
return (fromRow - toRow == 2 || fromRow - toRow == -2);
}
} // end class CheckersMove.
private class Board extends JPanel implements ActionListener, MouseListener {
CheckersData board; // The data for the checkers board is kept here.
// This board is also responsible for generating
// lists of legal moves.
boolean gameInProgress; // Is a game currently in progress?
/* The next three variables are valid only when the game is in progress. */
int currentPlayer; // Whose turn is it now? The possible values
// are CheckersData.RED and CheckersData.BLACK.
int selectedRow, selectedCol; // If the current player has selected a piece to
// move, these give the row and column
// containing that piece. If no piece is
// yet selected, then selectedRow is -1.
CheckersMove[] legalMoves; // An array containing the legal moves for the
// current player.
Board() {
setBackground(Color.BLACK);
addMouseListener(this);
resignButton = new JButton(\"Resign\");
resignButton.addActionListener(this);
newGameBu.
public interface Game Note interface in place of class { .pdfkavithaarp
public interface Game // Note *interface* in place of *class*
{
/// play the game and return the final score
/// where a higher score should be better,
/// and a negative score is allowed.
int play(); // Note semicolon in place of a body
// You can have multiple method headings declared
}
--------------------------------------------------------------------------------------------------------------
import java.util.*;
/// Starting point for Interface Lab.
public class PlayGames
{
private static Scanner in;
private static Random rand = new Random();
private static int gameCount = 0;
public static Game popRandom(Game[] g)
{
int n = gameCount;
int i = rand.nextInt(n);
Game ret = g[i];
g[i] = g[n-1];
gameCount--;
return ret;
}
public static void main(String[] args)
{
Game[] games = new Game[10]; // Note Game as a type
games[gameCount] = new AdditionGame(rand, 100);
gameCount++; // next index to put a Game at
// write at least 2 more different types of Game classes
// and add a new one of each type to games
// ...
in = new Scanner(System.in);
int totScore = 0;
do {
Game g = popRandom(games);
totScore += g.play(); // use numerical result from the game
} while (gameCount > 0 && agree(\"Want a game? \"));
System.out.println(\"Thanks for Playing!\");
System.out.println(\"Your total score is \" + totScore);
}
public static boolean agree(String prompt)
{
System.out.print(prompt);
String input = in.next();
if (input.equalsIgnoreCase(\"y\")) return true;
return false;
}
--------------------------------------------------------------------------------------------------------------------
--
import java.util.*;
public class AdditionGame implements Game // note implements!!
{
private Random rand;
private int n;
// Constructor for objects of class AdditionGame
public AdditionGame(Random r, int big)
{
rand = r;
n = big;
}
// play all games and keep score.
public int play() // exactly matches heading in Game interface
{
final int numGames = 3;
Scanner in = new Scanner(System.in);
int score = 0;
System.out.println(\"Welcome to the addition game! We\'ll now play \" + numGames
+ \" rounds.\");
for (int i = 0; i < numGames; i++) {
int x = rand.nextInt(n), y = rand.nextInt(n), ans = x+y;
System.out.print(String.format(\"Enter the sum: %d + %d = \", x, y));
int val = in.nextInt();
if (ans == val) {
System.out.println(\"Correct!\");
score++;
}
else
System.out.println(\"Wrong! Right answer is \" + ans);
}
System.out.println(\"Thanks for playing the addition game. Your score is \" + score +
\".\");
System.out.println();
return score;
}
}
--------------------------------------------------------------------------------------------------------------------
---
Create two classes that implement a Game interface:
------------------------------------
There is a Game interface defined, and also a PlayGames class that uses objects from classes that
implement that interface. The Game interface declares a single abstract method play that returns
an int, the score from playing the gam.
Having issues with passing my values through different functions aft.pdfrajkumarm401
Having issues with passing my values through different functions after \"EmployeeRecord()\".
Problem: This database must be capable of maintaining the employee ID, employee name,
department, and annual salary of each sales rep. The first phase of development for this database
will be to create the EmployeeRecord class.
Header File
#pragma once
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
EmployeeRecord(); //The default constructor
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor shall set
the member values passed into the function.
~EmployeeRecord();// The destructor
int getID();// shall return the value stored in the member variable
void setID(int ID);// will set the member variable m_iEmployeeID to the value of its\' argument.
void getName(char *fName, char *lName);// The getName() function shall copy the member
variables m_sFirstName and m_sLastName into the character arrays pointed to by the function
arguments.
void setName(char *fName, char *lName);// The setName() function will copy the function
arguments into the member variables m_sFirstName and m_sLastName.
void getDept(int& d);// The getDept() function shall be defined as a reference function. That is,
a call to this function will copy the member variable m_iDeptID into the int variable referenced
by the function argument.
void setDept(int d);// The setDept() function will copy the function argument into the member
variable m_iDeptID.
void getSalary(double *sal);// he getSalary() function shall be defined as a pointer function.
void setSalary(double sal);//the function setSalary() shall copy the function argument into the
member variable m_dSalary.
void printRecord(); //This function shall print to the screen all data found in the employee\'s
record.
};
Main File
#include
#include \"EmployeeRecord.h\"
#include
#include
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = \'\\0\';
m_sLastName[0] = \'\\0\';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
fName=NULL;
lName=NULL;
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
// It was tested in sprint 1
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
/*char *newString = new char[strlen(theString) + 1];
strcpy(newString, theString);
return newString;*/
}
void EmployeeRecord::setName(char *fName, char *lName)
{
/*clearString(); // Clear the current string, if any
theString = new char[strlen(str) + 1]; // Allocate memory for new string
strcpy(theString, str.
Explain the characterstic of web service techonolgy.SolutionT.pdfrajkumarm401
Explain the characterstic of web service techonolgy.?
Solution
The characterstics of web service technologies are as follows:
1. It is XML based : They uses XML in the tranportation layer to represent the data. Hence by
using it binding issues with network ,oS etc are removed.
2. Loosely coupled : It is loosely coupled because Adopting a by loosely coupled architecture
tends we can make software systems easy to manage and also it becomes simple to join different
systems.
3.Synchronous as well as asynchronous: In Synchronous client receive their result at that point of
time whereas in ASynchronous client receive thir result at later point of time..
More Related Content
Similar to ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
An introduction to making browser based games in JavaScript and HTML5.
This workshop was presented at an open day for the Academy of Interactive Entertainment in Sydney, Australia on November 17, 2012.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
public class Checkers extends JPanel {
public static void main(String[] args) {
JFrame window = new JFrame(\"Checkers\");
Checkers content = new Checkers();
window.setContentPane(content);
window.pack();
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation( (screensize.width - window.getWidth())/2,
(screensize.height - window.getHeight())/2 );
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
window.setResizable(false);
window.setVisible(true);
}
private JButton newGameButton; // Button for starting a new game.
private JButton resignButton; // Button that a player can use to end
// the game by resigning.
private JLabel message; // Label for displaying messages to the user.
public Checkers() {
setLayout(null); // I will do the layout myself.
setPreferredSize( new Dimension(350,250) );
setBackground(new Color(0,150,0)); // Dark green background.
/* Create the components and add them to the applet. */
Board board = new Board(); // Note: The constructor for the
// board also creates the buttons
// and label.
add(board);
add(newGameButton);
add(resignButton);
add(message);
/* Set the position and size of each component by calling
its setBounds() method. */
board.setBounds(20,20,164,164); // Note: size MUST be 164-by-164 !
newGameButton.setBounds(210, 60, 120, 30);
resignButton.setBounds(210, 120, 120, 30);
message.setBounds(0, 200, 350, 30);
} // end constructor
private static class CheckersMove {
int fromRow, fromCol; // Position of piece to be moved.
int toRow, toCol; // Square it is to move to.
CheckersMove(int r1, int c1, int r2, int c2) {
// Constructor. Just set the values of the instance variables.
fromRow = r1;
fromCol = c1;
toRow = r2;
toCol = c2;
}
boolean isJump() {
// Test whether this move is a jump. It is assumed that
// the move is legal. In a jump, the piece moves two
// rows. (In a regular move, it only moves one row.)
return (fromRow - toRow == 2 || fromRow - toRow == -2);
}
} // end class CheckersMove.
private class Board extends JPanel implements ActionListener, MouseListener {
CheckersData board; // The data for the checkers board is kept here.
// This board is also responsible for generating
// lists of legal moves.
boolean gameInProgress; // Is a game currently in progress?
/* The next three variables are valid only when the game is in progress. */
int currentPlayer; // Whose turn is it now? The possible values
// are CheckersData.RED and CheckersData.BLACK.
int selectedRow, selectedCol; // If the current player has selected a piece to
// move, these give the row and column
// containing that piece. If no piece is
// yet selected, then selectedRow is -1.
CheckersMove[] legalMoves; // An array containing the legal moves for the
// current player.
Board() {
setBackground(Color.BLACK);
addMouseListener(this);
resignButton = new JButton(\"Resign\");
resignButton.addActionListener(this);
newGameBu.
public interface Game Note interface in place of class { .pdfkavithaarp
public interface Game // Note *interface* in place of *class*
{
/// play the game and return the final score
/// where a higher score should be better,
/// and a negative score is allowed.
int play(); // Note semicolon in place of a body
// You can have multiple method headings declared
}
--------------------------------------------------------------------------------------------------------------
import java.util.*;
/// Starting point for Interface Lab.
public class PlayGames
{
private static Scanner in;
private static Random rand = new Random();
private static int gameCount = 0;
public static Game popRandom(Game[] g)
{
int n = gameCount;
int i = rand.nextInt(n);
Game ret = g[i];
g[i] = g[n-1];
gameCount--;
return ret;
}
public static void main(String[] args)
{
Game[] games = new Game[10]; // Note Game as a type
games[gameCount] = new AdditionGame(rand, 100);
gameCount++; // next index to put a Game at
// write at least 2 more different types of Game classes
// and add a new one of each type to games
// ...
in = new Scanner(System.in);
int totScore = 0;
do {
Game g = popRandom(games);
totScore += g.play(); // use numerical result from the game
} while (gameCount > 0 && agree(\"Want a game? \"));
System.out.println(\"Thanks for Playing!\");
System.out.println(\"Your total score is \" + totScore);
}
public static boolean agree(String prompt)
{
System.out.print(prompt);
String input = in.next();
if (input.equalsIgnoreCase(\"y\")) return true;
return false;
}
--------------------------------------------------------------------------------------------------------------------
--
import java.util.*;
public class AdditionGame implements Game // note implements!!
{
private Random rand;
private int n;
// Constructor for objects of class AdditionGame
public AdditionGame(Random r, int big)
{
rand = r;
n = big;
}
// play all games and keep score.
public int play() // exactly matches heading in Game interface
{
final int numGames = 3;
Scanner in = new Scanner(System.in);
int score = 0;
System.out.println(\"Welcome to the addition game! We\'ll now play \" + numGames
+ \" rounds.\");
for (int i = 0; i < numGames; i++) {
int x = rand.nextInt(n), y = rand.nextInt(n), ans = x+y;
System.out.print(String.format(\"Enter the sum: %d + %d = \", x, y));
int val = in.nextInt();
if (ans == val) {
System.out.println(\"Correct!\");
score++;
}
else
System.out.println(\"Wrong! Right answer is \" + ans);
}
System.out.println(\"Thanks for playing the addition game. Your score is \" + score +
\".\");
System.out.println();
return score;
}
}
--------------------------------------------------------------------------------------------------------------------
---
Create two classes that implement a Game interface:
------------------------------------
There is a Game interface defined, and also a PlayGames class that uses objects from classes that
implement that interface. The Game interface declares a single abstract method play that returns
an int, the score from playing the gam.
Having issues with passing my values through different functions aft.pdfrajkumarm401
Having issues with passing my values through different functions after \"EmployeeRecord()\".
Problem: This database must be capable of maintaining the employee ID, employee name,
department, and annual salary of each sales rep. The first phase of development for this database
will be to create the EmployeeRecord class.
Header File
#pragma once
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
EmployeeRecord(); //The default constructor
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor shall set
the member values passed into the function.
~EmployeeRecord();// The destructor
int getID();// shall return the value stored in the member variable
void setID(int ID);// will set the member variable m_iEmployeeID to the value of its\' argument.
void getName(char *fName, char *lName);// The getName() function shall copy the member
variables m_sFirstName and m_sLastName into the character arrays pointed to by the function
arguments.
void setName(char *fName, char *lName);// The setName() function will copy the function
arguments into the member variables m_sFirstName and m_sLastName.
void getDept(int& d);// The getDept() function shall be defined as a reference function. That is,
a call to this function will copy the member variable m_iDeptID into the int variable referenced
by the function argument.
void setDept(int d);// The setDept() function will copy the function argument into the member
variable m_iDeptID.
void getSalary(double *sal);// he getSalary() function shall be defined as a pointer function.
void setSalary(double sal);//the function setSalary() shall copy the function argument into the
member variable m_dSalary.
void printRecord(); //This function shall print to the screen all data found in the employee\'s
record.
};
Main File
#include
#include \"EmployeeRecord.h\"
#include
#include
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = \'\\0\';
m_sLastName[0] = \'\\0\';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
fName=NULL;
lName=NULL;
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
// It was tested in sprint 1
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
/*char *newString = new char[strlen(theString) + 1];
strcpy(newString, theString);
return newString;*/
}
void EmployeeRecord::setName(char *fName, char *lName)
{
/*clearString(); // Clear the current string, if any
theString = new char[strlen(str) + 1]; // Allocate memory for new string
strcpy(theString, str.
Explain the characterstic of web service techonolgy.SolutionT.pdfrajkumarm401
Explain the characterstic of web service techonolgy.?
Solution
The characterstics of web service technologies are as follows:
1. It is XML based : They uses XML in the tranportation layer to represent the data. Hence by
using it binding issues with network ,oS etc are removed.
2. Loosely coupled : It is loosely coupled because Adopting a by loosely coupled architecture
tends we can make software systems easy to manage and also it becomes simple to join different
systems.
3.Synchronous as well as asynchronous: In Synchronous client receive their result at that point of
time whereas in ASynchronous client receive thir result at later point of time..
Executive Summary i. Provide a succinct overview of your strategic p.pdfrajkumarm401
Executive Summary i. Provide a succinct overview of your strategic plan on coca cola.
Solution
Coca Cola is a global beverage brand based at USA. It has a strong positioning in soft drink and
non -alcoholic beverages. Due to global shift in the mindset of consumers, it should restructure
its strategic plan to take leadership position in soft drink as well as Fast moving consumer goods
(FMCG) products across the global market. It should revise its strategic intent by moulding its
mission as to produce more hygienic and less soda as ingradinets products in soft drink.
Globally, consumers are health conscious so they are not showing interest in more soda based
drink. So, Coca Cola will plan its product designing strategies to attract more no. of customers as
well as getting a sophisticated share in the carbonated soft drink. Even, it is utilizing its brand
value in making its current business plans, policies, procedures etc. more focused towards the
sustainable development. In this, only those process or products are utilized which refine the
excessively use of water, plants etc. as an inputs its manufacturing for global supplies..
eee230 Instruction details Answer the following questions in a typed.pdfrajkumarm401
eee230 Instruction details Answer the following questions in a typed paper (single spaced, 12
font) for each instruction: How many bits are used? Is the loading utilization n the upper, lower
or all? Is the use of this instruction loading a constant or variable? What is the format of this
instruction? Is the transfer: Register to Register, Register to Memory, or Memory to Register? Is
the math signed, unsigned, or neither? Is this a pseudo instruction or not? Instructions lui Iw sw
andi ori la srl sll add addi addiu
Solution
a
b
c
d
e
f
g
1
32 bits
all
constant
R-type
Register to Register
either
yes
2
16,32 bits
all
variable
I-type
Memory to register
Unsigned
yes
3
16,32 bits
all
variable
I-type
Register into RAM
Unsigned
yes
4
32 bits
all
variable
I-type
Register to Register
Unsigned
yes
5
16 bits
all
constant
I-type
Register to Register
Unsigned
yes
6
32 bits
all
constant
R1,D2(X2,B2)
Register to RAM
Signed
yes
7
32 bits
lower
variable
R1,D2(B2)
Register to Register
either
yes
8
32 bits
upper
variable
R1,D2(B2)
Register to Register
either
yes
9
32 bits
all
variable
R-type
Register to Register
either
yes
10
16 – 32 bits
all
variable
I-type
Register to Register
Signed
yes
11
32 bits
all
variable
I-type
Register to Register
Unsigned
yes
a
b
c
d
e
f
g
1
32 bits
all
constant
R-type
Register to Register
either
yes
2
16,32 bits
all
variable
I-type
Memory to register
Unsigned
yes
3
16,32 bits
all
variable
I-type
Register into RAM
Unsigned
yes
4
32 bits
all
variable
I-type
Register to Register
Unsigned
yes
5
16 bits
all
constant
I-type
Register to Register
Unsigned
yes
6
32 bits
all
constant
R1,D2(X2,B2)
Register to RAM
Signed
yes
7
32 bits
lower
variable
R1,D2(B2)
Register to Register
either
yes
8
32 bits
upper
variable
R1,D2(B2)
Register to Register
either
yes
9
32 bits
all
variable
R-type
Register to Register
either
yes
10
16 – 32 bits
all
variable
I-type
Register to Register
Signed
yes
11
32 bits
all
variable
I-type
Register to Register
Unsigned
yes.
Essay questionPorter Combining business strategy What is itmeani.pdfrajkumarm401
Essay question:
Porter Combining business strategy: What is itmeaning? - What is the idea? - Why is it
important?
Solution
Strategy According to Michael Porter
In a 1996 Harvard Business Review article [5] and in an earlier book [6], Porter argues that
competitive strategy is \"about being different.\" He adds, \"It means deliberately choosing a
different set of activities to deliver a unique mix of value.\" In short, Porter argues that strategy is
about competitive position, about differentiating yourself in the eyes of the customer, about
adding value through a mix of activities different from those used by competitors. In his earlier
book, Porter defines competitive strategy as \"a combination of the ends (goals) for which the
firm is striving and the means (policies) by which it is seeking to get there.\" Thus, Porter seems
to embrace strategy as both plan and position. (It should be noted that Porter writes about
competitive strategy, not about strategy in general.)
COMBINATION STRATEGIES
Can forms of competitive advantage be combined? Porter asserts that a successful strategy
requires a firm to aggressively stake out a market position, and that different strategies involve
distinctly different approaches to competing and operating the business. An organization
pursuing a differentiation strategy seeks competitive advantage by offering products or services
that are unique from those offered by rivals, either through design, brand image, technology,
features, or customer service. Alternatively, an organization pursuing a cost leadership strategy
attempts to gain competitive advantage based on being the overall low-cost provider of a product
or service. To be \"all things to all people\" can mean becoming \"stuck in the middle\" with no
distinct competitive advantage. The difference between being \"stuck in the middle\" and
successfully pursuing combination strategies merits discussion. Although Porter describes the
dangers of not being successful in either cost control or differentiation, some firms have been
able to succeed using combination strategies.
Research suggests that, in some cases, it is possible to be a cost leader while maintaining a
differentiated product. Southwest Airlines has combined cost cutting measures with
differentiation. The company has been able to reduce costs by not assigning seating and by
eliminating meals on its planes. It has then been able to promote in its advertising that one does
not get tasteless airline food on its flights. Its fares have been low enough to attract a significant
number of passengers, allowing the airline to succeed.
Another firm that has pursued an effective combination strategy is Nike. When customer
preferences moved to wide-legged jeans and cargo pants, Nike\'s market share slipped.
Competitors such as Adidas offered less expensive shoes and undercut Nike\'s price. Nike\'s
stock price dropped in 1998 to half its 1997 high. However, Nike reported a 70 percent increase
in earnings for.
During oogenesis, will the genotypes of the first and second polar b.pdfrajkumarm401
During oogenesis, will the genotypes of the first and second polar bodies be identical? Explain.
Solution
No. The oocyte development occurs through meiosis, which divides the chromosomes. Crossing
over of homologus chromosomes also takes place which adds differences in the daughter cells
produced. Moreover, the first and secondary polar bodies are produced in different phases of
meiosis. As they divide before the mitotic phase of meiosis, the two polar bodies cannot br
identical..
Does personal information available on the Internet make an employee.pdfrajkumarm401
Does personal information available on the Internet make an employee an easier target for social
engineering?
Solution
yes the personal information available on the Internet make an employee an easier target for
social engineering.
the Hackers use social engineering techniques with some other forms of attack to breach
companies and to gather confidencial data.
social engineering is a brutal and it is making unknown conspirator out of innocent employees.
we know that all employees are on Facebook, LinkedIn, Twitter and Quora, and they are adding
personal information to the Web every day.some people wont know how much personal
information is to keep available online. all become comfortable sharing personal information
which reserved for private. social engineers utilizing this and they relies on to launch an attack.
Determine whether each series is convergent or divergent..pdfrajkumarm401
Determine whether each series is convergent or divergent.
4)Determine whether the series converges or diverges.
5)Determine whether the sequence converges or diverges.
Solution
a)
Looking at the right-hand side of the Riemann zeta-function, we recognizeit to be a p-series with
p = x. We know that p-series only converge when p > 1and that they diverge whenever p <= 1,
so the domain of the Riemann zeta-function is
(1,)={x:x>1}.
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdfrajkumarm401
Describe the primary differences between WEP, WPA, and WPA2 protocols. b. Describe how
algorithms enhance the security of the above protocols.
Solution
differences between WEP, WPA, and WPA2 protocols:
Wired Equivalent Privacy (WEP)
Wired Equivalent Privacy (WEP) is the most widely used Wi-Fi security algorithm in the world.
This is a function of age, backwards compatibility, and the fact that it appears first in the
encryption type selection menus in many router control panels.
WEP was ratified as a Wi-Fi security standard in September of 1999. The first versions of WEP
weren’t particularly strong, even for the time they were released, because U.S. restrictions on the
export of various cryptographic technology led to manufacturers restricting their devices to only
64-bit encryption. When the restrictions were lifted, it was increased to 128-bit. Despite the
introduction of 256-bit WEP encryption, 128-bit remains one of the most common
implementations.
Despite revisions to the algorithm and an increased key size, over time numerous security flaws
were discovered in the WEP standard and, as computing power increased, it became easier and
easier to exploit them. As early as 2001 proof-of-concept exploits were floating around and by
2005 the FBI gave a public demonstration (in an effort to increase awareness of WEP’s
weaknesses) where they cracked WEP passwords in minutes using freely available software.
Despite various improvements, work-arounds, and other attempts to shore up the WEP system, it
remains highly vulnerable and systems that rely on WEP should be upgraded or, if security
upgrades are not an option, replaced. The Wi-Fi Alliance officially retired WEP in 2004.
Wi-Fi Protected Access (WPA)
Wi-Fi Protected Access was the Wi-Fi Alliance’s direct response and replacement to the
increasingly apparent vulnerabilities of the WEP standard. It was formally adopted in 2003, a
year before WEP was officially retired. The most common WPA configuration is WPA-PSK
(Pre-Shared Key). The keys used by WPA are 256-bit, a significant increase over the 64-bit and
128-bit keys used in the WEP system.
Some of the significant changes implemented with WPA included message integrity checks (to
determine if an attacker had captured or altered packets passed between the access point and
client) and the Temporal Key Integrity Protocol (TKIP). TKIP employs a per-packet key system
that was radically more secure than fixed key used in the WEP system. TKIP was later
superseded by Advanced Encryption Standard (AES).
Despite what a significant improvement WPA was over WEP, the ghost of WEP haunted WPA.
TKIP, a core component of WPA, was designed to be easily rolled out via firmware upgrades
onto existing WEP-enabled devices. As such it had to recycle certain elements used in the WEP
system which, ultimately, were also exploited.
WPA, like its predecessor WEP, has been shown via both proof-of-concept and applied public
demonstrations to be vulnerable to intrusion. Inte.
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfrajkumarm401
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header
file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list
functionality. The functions header file is also given. Complete the functions of the header file
linked_list.h below.
=========================================================
// listmain.cpp
#include \"Linked_List.h\"
int main(int argc, char **argv)
{
float f;
Linked_List *theList;
cout << \"Simple List Demonstration\ \";
cout << \"(List implemented as an Array - Do not try this at home)\ \ \";
cout << \"Create a list and add a few tasks to the list\";
theList = new Linked_List(); // Instantiate a list object
theList->Insert(5, 3.1f); // Note: The argument to the funtion should be a float
theList->Insert(1, 5.6f); // A constant real number like 3.1 is interpreted as
theList->Insert(3, 8.3f); // a double unless it is explicitly defined as a float
theList->Insert(2, 7.4f); // by adding an \'f\' to the end of the number.
theList->Insert(4, 2.5f);
// Show what is in the list
theList->PrintList();
// Test the list length function
cout << \"\ List now contains \" << theList->ListLength() << \"items.\ \ \";
// Test delete function
cout << \"Testing delete of last item in list.\ \";
theList->Delete(4);
theList->PrintList();
// Test delete function
cout << \"Testing delete of first item in list.\ \";
theList->Delete(5);
theList->PrintList();
// Test delete function
cout << \"Testing delete of a middle item in list.\ \";
theList->Delete(3);
theList->PrintList();
// Test delete function with a known failure argument
cout << \"Testing failure in delete function.\ \";
if(theList->Delete(4))
cout << \"Oops! Should not have been able to delete.\ \";
else
cout << \"Unable to locate item to delete.\ \";
// Test search (known failure)
cout << \"Testing Search function. Search for key 3\ \";
if(theList->Search(3, &f))
cout << \"Search result: theData = %f\ \", f;
else
cout << \"Search result: Unable to locate item in list\ \";
// Test search (known success)
cout << \"Testing Search function. Search for key 2\ \";
if(theList->Search(2, &f))
cout << \"Search result: theData = \" << f << \"\ \";
else
cout << \"Search result: Unable to locate item in list\ \";
cout << \"\ \ End list demonstration...\";
return 0;
}
=====================================================================
===================
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
ListItem *head; // Pointer to head of the list
public:
Linked_List(); // Class constructor
~Linked_List(); // Class destuctor
void ClearList(); // Remove all items from the list
bool Insert(int key, float f);// Add an item to the list
bool Delete(int key); // Delete an item from the list
bool Search(int key, float *retVal); // Search for an item in the list
int ListLength(); // Return numb.
Click the desktop shortcut icon that you created in this module, and .pdfrajkumarm401
Click the desktop shortcut icon that you created in this module, and then press the Delete key to
delete the shortcut. If necessary, click the Yes button to confirm the deletion. Right-click the
Paint button on the taskbar, point to Broadway, and then click the Unpin from this list icon On
the Paint shortcut menu, click Unpin this program from taskbar. Drag the File Explorer button
on the taskbar to its original location to the left of the Microsoft Edge button on the taskbar.
Right-dick the Search the web and Windows button on the taskbar, point to Search on the
shortcut menu, and then click Show search box to redisplay the Search the web and Windows
box on the taskbar. Trouble? If you have activated Cortana, point to Cortana on the shortcut
menu, and then click Show search box. How do you change the position of taskbar buttons?
Why would you pin a file to a taskbar button\'s jump List? You can use a feature called ___ to
list the thumbnails of open windows as you snap a window into place. How can you quickly
minimize all open windows on the desktop? Explain how to create a virtual desktop. Name two
ways you can change the appearance of a tile on the Start menu. What can you do with the
Reader app? Explain how to personalize the user icon on the Start menu.
Solution
1. How do you change the position of taskbar buttons?
Simply right click on the taskbar button, and drag it to the desired location, and leave it.
2. Why would you pin a file to a taskbar buttons Jump List?
Usually, the file which needs a frequent access, something like Windows Explorer, and if you
are
an accountant something like MS-Word, for a photographer something like PhotoShop, these
files
will be accessed almost regularly multiple times a day. So, to make such kind of files handy,
we could pin those files to the taskbar, so that they can be opened with just a click away.
3. You can use a feature called __Aero__ to list the thumbnails of open windows as you snap a
window into place.
Aero is the one which features Snap(to resize open windows), Peek(view open windows), Shake
(close all windows except the selected one) etc.
4. How can you quickly minimize all open windows on the desktop?
Just click on the right corner of the taskbar, which shows a label Show Desktop when your
mouse hovers there.
5. Explain how to create a virtual desktop?
The steps required to create a virtual desktop include:
-> Open a Task View pane which is available on the taskbar, or by pressing WindowKey + Tab
-> In the Task View pane, click New desktop which creates another virtual desktop..
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdfrajkumarm401
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chapo6 folder Add the
labels and a button to the form. The button\'s Click event procedure should display in number of
integers from in one the the sum of those integers the other label. Code the procedure labels and
and then start and using the For...Next statement. Save the solutv test the application. Close the
solution.
Solution
Open Visual Studio 2015 and create new project. In page/tab WindowsFormsApplicationForm1
create 1 button named as button1. Similarly create two labels named as label1 and label2.
Double clock on button1. It will open the click event in page/tab
WindowsFormsApplicationForm1(.cs).
write the below code
Using System;
Using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponents();
}
private void button1_click(object Sender, EventArgs e)
{
int cnt = 0;
int sums = 0;
label1.text = \"14, 15, 16, 17, 18, 19, 20, 21, 22, 23\");
for(cnt = 14; cnt <= 23; cnt++)
{
sums = sums + cnt;
label2.text = sums;
}
}
}
}.
What was the causes of the Vietnam war What was the causes of .pdfrajkumarm401
What was the causes of the Vietnam war?
What was the causes of the Vietnam war?
Solution
The causes of the Vietnam War were derived from the symptoms, components and consequences
of the Cold War. The causes of the Vietnam War revolve around the simple belief held by
America that communism was threatening to expand all over south-east Asia
The US entered the conflict in South Vietnam based on the much maligned \"Domino Theory\"
concept. From the perspective of the Nation\'s leader, this was a very real threat both in terms of
nation\'s falling one by one to communism and with regards to the resultant impacts.
The most significant driver for US involvement in South Vietnam was the Korean War. It
established the notion of a \"civil war\" in which the northern communists were extensively
supported by outside forces and that a conventional invasion was the greatest threat.
On June 25, 1950, North Korea invaded South Korea. The US and its allies spent three years
fighting a very brutal war against the North Koreans, the Chinese and the Soviets. Eventually, it
ended in a stalemate. By definition, on June 25, 1950, this was a civil war.However, by the time
the US entered the Vietnam conflict, there was ample near term historical precedence for the
spread of communism.
In 1954, Vietnamese communist forces defeat the French which leads to the 1954 Geneva
convention in which the region was divided into North and South Vietnam, Laos, and Cambodia.
In 1959, the government of Laos collapses and the Pathet Lao (communist forces backed by the
North Vietnamese) begin to fight for control of the country. A civil war backed by external
communist forces.
It was evident to the US and its allies that communism was spreading throughout the region.
Each state which fell served as a launch point for communist operations in nearby countries
(China into Korea and Vietnam, China and North Vietnam into Laos and Cambodia). Therefore
to prevent further spread to allies to include Thailand and Japan among others, communism had
to be contained.
Based on the results of communist rule in the countries that fell, it seems the concerns were
genuine. South Vietnam asked for help from its SEATO allies and the US responded as it should
under treaty obligation.
The argument that this was civil war substantially underplays the assistance the North
Vietnamese received from the Chinese and Soviets. It was as much a civil war as the Korean
War was.
Some 1.5 million Chinese were executed during the land reforms and counter-revolutionary
executions following the Chinese victory in 1948. In the early 1960s, following the Great Leap
Forward, approximately 2.5 million people were executed, Up to 1 million people were executed
or died in concentration camps in North Korea by the start of the US involvement in Vietnam.
Between 1953 and 1956, the Land reform in North Vietnam carried out by the Communists
resulted in the deaths, by various estimates, of almost 200,ooo landowners via public kanga.
Transactions costs are zero in financial markets. zero in financial i.pdfrajkumarm401
Transactions costs are zero in financial markets. zero in financial intermediaries. equal to the
taxes imposed on financial transactions. the costs of direct financial transactions Save
Solution
Transaction cost includes a wide range of costs like communication. legal or even the
transportation cost in some cases. It is incurred in any direct financial transaction. The answer is
\"D\"..
This is for an homework assignment using Java code. Here is the home.pdfrajkumarm401
This is for an homework assignment using Java code. Here is the homework:
Objective:
Write a game where you are an X trying to get an ice cream cone in a mine field
Before the game starts, a field of mines are created.
The board has to be first initialized
There mines occupy a tenth of the board (IE (BoardSize x BoardSize)/10 = the number of mines)
The mines are randomly placed on the board. If a space which is already occupied (either by the
player, the ice cream cone, or another mine) is selected then another space must be selected until
an empty space is found.
The player is placed at 0,0
The ice cream cone is placed at a random location on the board
At each turn, the player chooses to move in the X or Y direction by entering either -1, 0, or 1,
where
-1 is going one space in the negative direction
1 is going one space in the positive direction (remember positive for Y is down)
0 is staying still
9 quits the game
Anything other than these values should prompt the player that they have inputted an invalid
value and then not move in that direction (IE 0).
Before each turn the board is displayed indicating where the player (X) and the goal (^) are
located. Unoccupied spaces and mines are denoted by and underscore (_). Remember mines need
to be hidden so they are also underscores (_). The board is maximum 10 spaces long and wide.
Once the player reaches the ice cream cone the player wins
If the player lands on a space with a mine they are killed and the game is over
After the game is over, the player should be prompted whether or not they want to play again.
Example Dialog:
Welcome to Mine Walker. Get the ice cream cone and avoid the mines
X_________
__________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
1
Enter either a -1,0, or 1 in the Y
1
__________
_X________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
0
Enter either a -1,0, or 1 in the Y
1
__________
__________
_X________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
-1
Enter either a -1,0, or 1 in the Y
1
Boom! Dead!
Would you like to play again?
This is the code I have so far. And it works fine. But when you land on a bomb or the ice cream
and it ask you to play again, if you say yes then it doesn\'t reset the game board. Instead it just
continues from where the \"X\" last was on the board. How can I reset the board at the end if the
user wants to play again?
import java.util.Random;
import java.util.Scanner;
public class MineWalker
{
//Setup enum, Scanner, and final variables
enum Spaces {Empty, Player, Mines, Ice_Cream, Walked_Path};
private static final int BOARD_SIZE = 10;
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args)
{
//Player\'s location
int pX = 0;
int pY = 0;
//Game .
Question 34 (1 point) D A check is 1) not money because it is not off.pdfrajkumarm401
Question 34 (1 point) D A check is 1) not money because it is not officially issued by the
government. 2) money because it is a means of payment. 3) money because it is generally
accepted as a means of payments. 4) not money but transfers bank deposits which are money.
Solution
Answer is 3. Money because it is generally accepted as a means of payments.
Explanation: A check is a negotiable instrument and is treated like money because it majorly
does all the function of money like accepted as a means of payments, etc..
Program Structure declare ButtonState Global variable holding statu.pdfrajkumarm401
Program Structure: declare ButtonState: Global variable holding status of button unsigned long
Button Time: Holds time to debounce Switch int Button NextState( input) function that is to be
called in loop to service the switch switch based on ButtonState Idle: State where nothing has
been happening. if input is low, Button Time millis0: Record time of high to low transition. set
ButtonState to Wait Move to Wait state. Wait: Button has gone low and we are waiting for it to
remain low for 5 milliseconds if input is high. l f button has gone high. set ButtonState to Idle
Reset back to Idle else if (millis0- Button Time 5 if 5 milliseconds has passed. set ButtonState to
Low Move to low state. return 1 indicating that button has been pressed Low Button is low and
has been so for 5 milliseconds. if input is high Once button released. set ButtonState to Idle: end
of switch return 0 By default return 0 indicating nothing is happening. setup: Function run at the
start of the program. Set pin as input Check Schematic in Lab 4 for pin number. Set ButtonState
to Idle Initialize state loop Function continuously called Check status of button. if
ButtonNextState( digitalRead( input)) Send serial message indicating button press Indicate
button has been pressed end of if
Solution
//initialize and declare variables
const int ledPin = 13; //led attached to this pin
const int buttonPin = 2; //push button attached to this pin
int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if
pressed
int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
//set the mode of the pins...
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}//close void setup
void loop() {
//sample the state of the button - is it pressed or not?
buttonState = digitalRead(buttonPin);
//filter out any noise by setting a time buffer
if ( (millis() - lastDebounceTime) > debounceDelay) {
//if the button has been pressed, lets toggle the LED from \"off to on\" or \"on to off\"
if ( (buttonState == HIGH) && (ledState < 0) ) {
digitalWrite(ledPin, HIGH); //turn LED on
ledState = -ledState; //now the LED is on, we need to change the state
lastDebounceTime = millis(); //set the current time
}
else if ( (buttonState == HIGH) && (ledState > 0) ) {
digitalWrite(ledPin, LOW); //turn LED off
ledState = -ledState; //now the LED is off, we need to change the state
lastDebounceTime = millis(); //set the current time
}//close if/else
}//close if(time buffer)
}//close void loop.
mine whether the following s are true or false False A parabola has e.pdfrajkumarm401
mine whether the following s are true or false False A parabola has either zero or two r-
intercepts False- Given the general form of the parabola, (e) a b the vertical intercept of the graph
of f is the point (0, e) False If a quadratic function f is concave down on the interval 0
Solution
1) false. they can have one too
2)true. put x = 0 in quadratic
3)false. not necessary
4) true
5) False
6) ture
7)true.
Locate an article where the technique of Polymerase chain reaction (.pdfrajkumarm401
Locate an article where the technique of Polymerase chain reaction (PCR) is used.Describe the
technique briefly based on your study material, and explain how this technique provided the
authors with the key information for their results and conclusions.
Solution
This article fairly explain the PCR technique.
\"Activation of Wnt/beta-catenin/Tcf signaling pathway in human astrocytomas\"
In this article Semi -Quantitative PCR technique is used for the analysis of mRNA levels of -
Catenin/Tcf Signaling components.
Initially total RNA isolated from Freezed brain Astrocyte tissue. From thios RNA, cDNA
synthecized using Takara cDNA reverse transcriptase kit. Then the produced cDNA is amplified
with different primers of the -Catenin/Tcf Signaling components that include Dvl-1, Dvl-2, Dvl-
3, beta-catenin, c-myc and cyclin D1.
The mRNA levels were positively correlated with the histological malignancy. Our studies tend
to suggest that Wnt/beta-catenin/Tcf signaling pathway is implicated in malignancy of
astrocytomas.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Instructions for Submissions thorugh G- Classroom.pptx
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
1. Objective:
Create a graphical game of minesweeper IN JAVA. The board should consist of 10x10 buttons.
Of the 100 spaces there should be at least 20 randomly placed mines. If the button is clicked and
it is not a mine then it clears itself. If a space has been cleared then it should indicate how many
of its eight neighbors are mines. If a space is clicked and it is a mine then the game is over and
the player is asked if they want to play again. Finally, if all the non-mine spaces have been
clicked then the player is prompted that they won.
Solution
2 files need to be made.
First Game.Java which will have the gaming logic and User Interface and Main.Java which will
have have the main method and object of Game.java Number of rows and cols is customizable so
user can change that as and when needed.
import java.awt.*;
import java.awt.Dimension;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Game extends JFrame implements ActionListener, ContainerListener {
int fw, fh, blockr, blockc, var1, var2, num_of_mine, detectedmine = 0, savedlevel = 1,
savedblockr, savedblockc, savednum_of_mine = 10;
int[] r = {-1, -1, -1, 0, 1, 1, 1, 0};
int[] c = {-1, 0, 1, 1, 1, 0, -1, -1};
JButton[][] blocks;
int[][] countmine;
int[][] colour;
ImageIcon[] ic = new ImageIcon[14];
JPanel panelb = new JPanel();
JPanel panelmt = new JPanel();
JTextField tf_mine, tf_time;
JButton reset = new JButton("");
Random ranr = new Random();
Random ranc = new Random();
boolean check = true, starttime = false;
2. Point framelocation;
Stopwatch sw;
MouseHendeler mh;
Point p;
Game() {
super("Game");
setLocation(400, 300);
setic();
setpanel(1, 0, 0, 0);
setmanue();
sw = new Stopwatch();
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
sw.stop();
setpanel(savedlevel, savedblockr, savedblockc, savednum_of_mine);
} catch (Exception ex) {
setpanel(savedlevel, savedblockr, savedblockc, savednum_of_mine);
}
reset();
}
});
setDefaultCloseOperation(EXIT_ON_CLOSE);
show();
}
public void reset() {
check = true;
starttime = false;
for (int i = 0; i < blockr; i++) {
for (int j = 0; j < blockc; j++) {
colour[i][j] = 'w';
}
}
}
public void setpanel(int level, int setr, int setc, int setm) {
if (level == 1) {
5. panelb.repaint();
//getcontentpane().setOpaque(true);
getContentPane().setLayout(new BorderLayout());
getContentPane().addContainerListener(this);
//getContentPane().revalidate();
getContentPane().repaint();
getContentPane().add(panelb, BorderLayout.CENTER);
getContentPane().add(panelmt, BorderLayout.NORTH);
setVisible(true);
}
public void setmanue() {
JMenuBar bar = new JMenuBar();
JMenu game = new JMenu("GAME");
JMenuItem menuitem = new JMenuItem("new game");
final JCheckBoxMenuItem beginner = new JCheckBoxMenuItem("Begineer");
final JCheckBoxMenuItem intermediate = new JCheckBoxMenuItem("Intermediate");
final JCheckBoxMenuItem expart = new JCheckBoxMenuItem("Expart");
final JCheckBoxMenuItem custom = new JCheckBoxMenuItem("Custom");
final JMenuItem exit = new JMenuItem("Exit");
final JMenu help = new JMenu("Help");
final JMenuItem helpitem = new JMenuItem("Help");
ButtonGroup status = new ButtonGroup();
menuitem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
//panelb.removeAll();
//reset();
setpanel(1, 0, 0, 0);
//panelb.revalidate();
//panelb.repaint();
}
});
beginner.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
panelb.removeAll();