Question: The Mosaic assignment is a Java Graphical User Interface (GUI) programming assignment. Instructions: This weeks assignment includes a programming assignment named Mosaic. The assignment consists

The Mosaic assignment is a Java Graphical User Interface (GUI) programming assignment.

Instructions: This weeks assignment includes a programming assignment named Mosaic. The assignment consists of a list of requirements and a detailed design. It will be your responsibility to implementing this design and for implementing one additional interesting feature of your choice.

This is the similar to how the real world works. Most often a non-technical person (project sponsor) will approach your group with a request. You or someone on your team will be responsible for collecting, documenting, confirming their requirements. How this occurs depends on your organizations development process (SDLC). For this assignment, I have collected your requirements and am providing your initial design.

Requirements: We would like to have a colored mosaic that shows a random pattern of colored circles and squares with a random letter in the middle of the shape. Whenever the "Randomize" button is pressed, the tiles need to change at random.

Design: We will develop a Java application that provides a 12 by 12 grid of random circles and squares of random colors that includes a random letter in the middle. The resulting application should look something like:

Requirement #1: Your application must compile under the standard javac command line tools, run with the java runtime. All files need to compile and run the application must be included in the zip file that you submitted.

The name of your main Java file must be Mosaic.java, compile with the command "javac *.java", and run with the command "java Mosaic".

Requirement #2: The application should be appropriately formated and commented. It should use consistent indents, visually appealing code wrapping, concise meaningful comments, solid naming conventions, and NOT include commented out code, extra line feeds, etc.

Requirement #3: The Tile class has all necessary parameters properly declared, at least two constructors, all necessary getter and setter functions, and a toString function that return a string that shows the tile's shape, letter, and color component(s). The string should be printed to the command line each time the Tile is Randomized.

Requirement #4: At the beginning of each paint, the application should write "Start paint***" once followed by writing the toString() of each tile to the console window.

Requirement #5: the TileFrame class will need to hold two panels. One that holds the tiles and the other that holds the "Randomize" button.

Requirement #6: Each panel should be painted in the proper location with the proper letters. The letters must be centered and rendered in a color that assures that they will be visible.

Requirement #7: When the "Randomize" button is pressed (and only when the "Randomize" button is pressed), the tiles are shuffled so that a new pattern emerges.

(This is what I have so far)

----------------------------------------------------------------

Mosaic.java

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JButton;

import java.awt.Container;

import java.awt.GridLayout;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.util.Random;

import java.awt.Graphics;

import java.awt.Color;

import java.awt.Font;

import java.util.ArrayList;

class XAndOTile extends JPanel {

private int red, green, blue;

private String letter;

XAndOTile() {

super();

SetRandomValues();

}

final public void SetRandomValues() {

red = GetNumberBetween(0,255);

green = GetNumberBetween(0,255);

blue = GetNumberBetween(0,255);

letter = "X";

if (GetNumberBetween(0,1) == 1) {

letter = "O";

}

}

private static int GetNumberBetween(int min, int max) {

Random myRandom = new Random();

return min + myRandom.nextInt(max-min+1);

}

public void paintComponent(Graphics g) {

super.paintComponent(g);

int panelWidth = getWidth();

int panelHeight = getHeight();

g.setColor(new Color(red,green,blue));

g.fillRect (10, 10, panelWidth-20, panelHeight-20);

g.setColor(new Color(GetContrastingColor(red),GetContrastingColor(green),GetContrastingColor(blue)));

final int fontSize=100;

g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

int stringX = (panelWidth/2)-30;

int stringY = (panelHeight/2)+30;

g.drawString(letter,stringX,stringY);

}

private static int GetContrastingColor(int colorIn) {

return ((colorIn+128)%256);

}

}

class MosaicFrame extends JFrame implements ActionListener {

private ArrayList tileList;

public MosaicFrame() {

setBounds(200,200,1200,800);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPane = getContentPane();

contentPane.setLayout(new BorderLayout());

JPanel buttonPanel = new JPanel();

contentPane.add(buttonPanel, BorderLayout.SOUTH);

JButton randomize = new JButton("Randomize");

buttonPanel.add(randomize);

randomize.addActionListener(this);

JPanel xAndOGridPanel = new JPanel();

contentPane.add(xAndOGridPanel, BorderLayout.CENTER);

xAndOGridPanel.setLayout(new GridLayout(3,3));

tileList = new ArrayList();

for(int i=1; i

XAndOTile tile = new XAndOTile();

tileList.add(tile);

xAndOGridPanel.add(tile);

}

}

public void actionPerformed(ActionEvent e) {

for(XAndOTile tile : tileList) {

tile.SetRandomValues();

}

repaint();

}

}

public class Mosaic {

public static void main(String[] args) {

System.out.println("Mosaic Starting...");

MosaicFrame myMosaicFrame = new MosaicFrame();

myMosaicFrame.setVisible(true);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!