[Assembly Language Programm] Hopely you can attach a screemshot of these two pro
ID: 3834456 • Letter: #
Question
[Assembly Language Programm]
Hopely you can attach a screemshot of these two program!
Chess Board Write a program that draws an 8 times 8 chess board, with alternating gray and white squares. You can use the SetTextColor and Gotoxy procedures from the Irvine32 library. Avoid the use of global variables, and use declared parameters in all procedures. Use short procedures that are focused on a single task. (A VideoNote for this exercise is posted on the Web site.) Chess Board with Alternating Colors This exercise extends Exercise 9. Every 500 milliseconds, change the color of the colored squares and redisplay the board. Continue until you have shown the board 16 times, using all possible 4-bit background colors. (The white squares remain white throughout.)Explanation / Answer
import java.applet.*;
import java.awt.*;
/*<applet code="Chessboard" width="300" height="500">
</applet>
*/
public class Chessboard extends Applet
{
int x,y,dx,dy;
public void init()
{
setBackground(Color.RED);
}
public void paint(Graphics g)
{
x=1;
y=1;
dx=50;
dy=50;
for(int i=1;i<=8;i++)
{
for(int j=1;j<=8;j++)
{
if(i%2==1)
{
if(j%2==0)
{
g.setColor(Color.WHITE);
}
else
{
g.setColor(Color.BLACK);
}
}
else
{
if(j%2==0)
{
g.setColor(Color.BLACK);
}
else
{
g.setColor(Color.WHITE);
}
}
g.fillRect(x,y,dx,dy);
x=x+dx;
}
y=y+dy;
x=1;
}
}
}
or
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.MenuBar;
import java.awt.Button;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
public class Board extends Chess{
static JFrame chessBoard = new JFrame();
static Container c = new Container();
static GridLayout gl = new GridLayout(8,8);
static int[]rows = new int[gl.getRows()];
static int[] columns = new int[gl.getColumns()];
public static void Board(){
gl.setColumns(8);
gl.setRows(8);
chessBoard.setLayout(gl);
chessBoard.setSize(700,700);
chessBoard.setVisible(true);
chessBoard.setDefaultCloseOperation(chessBoard.EXIT_ON_CLOSE);
chessBoard.setResizable(false);
}
public static void createBoard(){
for(int i=0;i<64;i++){
JPanel x= new JPanel();
chessBoard.add(x);
for(int a = 0;a<8;a++){
for (int b=0;b<8;b++){
if((a+b)%2==0){
if((i/8)%2==0){
if(i%2==0)
x.setBackground(Color.white);
}
}
else
x.setBackground(Color.black);}
}
}
}
public static void main(String[] args) {
Board.Board();
Board.createBoard();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.