Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

According to this cord please give me this 2 question answer. package Program_07; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import java.awt.*; import java.awt.event.ActionEvent;

According to this cord please give me this 2 question answer.

package Program_07;

import javax.swing.*;

import javax.swing.border.Border;

import javax.swing.border.EmptyBorder;

import javax.swing.border.LineBorder;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class SudokuLayout extends JFrame {

/** Author Tri Nguyen

*

*/

private static final long serialVersionUID = 1L;

private JTextField square[][][];

private JFrame frame = new JFrame ();

private JPanel main = new JPanel( new BorderLayout());

private JPanel p1,p2,panel[];

private JTextArea TxtAr;

JButton reset,hint,solve,puzzle;

JLabel difficulty;

JComboBox difficultyBox;

Border exteriorBorder = new LineBorder(Color.BLACK, 2);

Border dividerBorder = new LineBorder(Color.BLUE, 1);

SudokuLayout()

{

frame = new JFrame();

frame.setTitle("Sudoku - Tri Nguyen");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

int i,j,k;

square = new JTextField[9][3][3];

Font font = new Font("Verdana", Font.BOLD, 30);

for(i=0;i<9;i++)

{

for(j=0;j<3;j++)

{

for(k=0;k<3;k++)

{

square[i][j][k] = new JTextField("",1);

square[i][j][k].setFont(font);

square[i][j][k].setPreferredSize(new Dimension(30,30));

square[i][j][k].setHorizontalAlignment(JTextField.CENTER);

square[i][j][k].setBorder(dividerBorder);

}

}

}

p1 = new JPanel();

panel = new JPanel[9];

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

for(i=0;i<9;i++)

{

panel[i] = new JPanel();

panel[i].setLayout(new GridLayout(3,3));

for(j=0;j<3;j++)

{

for(k=0;k<3;k++)

{

panel[i].add(square[i][j][k]);

}

}

panel[i].setBorder(exteriorBorder);

p1.add(panel[i]);

}

p1.setBorder(exteriorBorder);

class RoundedBorder implements Border

{

private int radius;

RoundedBorder(int radius) {

this.radius = radius;

}

public Insets getBorderInsets(Component c) {

return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);

}

public boolean isBorderOpaque() {

return true;

}

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

g.drawRoundRect(x,y,width-1,height-1,radius,radius);

}

}

reset = new JButton("Reset");

reset.setSize(new Dimension(10, 40));

reset.setBorder(new RoundedBorder(10));

reset.addActionListener(new resetl( ));

hint = new JButton("Hint");

hint.setSize(new Dimension(10, 40));

hint.setBorder(new RoundedBorder(10));

hint.addActionListener(new hintl( ));

solve = new JButton("Solve");

solve.setSize(new Dimension(10, 40));

solve.setBorder(new RoundedBorder(10));

solve.addActionListener(new solvel( ));

puzzle = new JButton("New Puzzle");

puzzle.setSize(new Dimension(10, 40));

puzzle.setBorder(new RoundedBorder(10));

puzzle.addActionListener(new puzzlel( ));

difficulty = new JLabel("Difficulty: ");

difficulty.setHorizontalAlignment(JLabel.CENTER);

String[] difficulties = { "Easy", "Medium", "Hard" };

difficultyBox = new JComboBox (difficulties);

difficultyBox.setPreferredSize(new Dimension(100, 20));

p2 = new JPanel();

p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));

p2.setAlignmentY(CENTER_ALIGNMENT);

p2.add(reset);

p2.add(Box.createRigidArea(new Dimension(0, 20)));

p2.add(hint);

p2.add(Box.createRigidArea(new Dimension(0, 20)));

p2.add(solve);

p2.add(Box.createRigidArea(new Dimension(0, 20)));

p2.add(puzzle);

p2.add(Box.createRigidArea(new Dimension(0, 20)));

p2.add(difficulty);

p2.add(difficultyBox);

main.add(p1,BorderLayout.LINE_START);

main.add(p2,BorderLayout.LINE_END);

main.setBorder(new EmptyBorder(5, 5, 5, 5));

TxtAr = new JTextArea(4, 20);

TxtAr.setBorder(BorderFactory.createTitledBorder ("Output Area: ")) ;

main.add(TxtAr,BorderLayout.SOUTH);

frame.add(main);

frame.pack();

frame.setVisible(true);

}

class resetl implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

TxtAr.setText("");

TxtAr.append("Reset button clicked!");

}

}

class hintl implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

TxtAr.setText("");

TxtAr.append("Hint button clicked!");

}

}

class solvel implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

TxtAr.setText("");

TxtAr.append("Solve button clicked!");

}

}

class puzzlel implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

TxtAr.setText("");

TxtAr.append((String)difficultyBox.getSelectedItem());

}

}

}

package Program_07;

public class TestSudoku {

public static void main(String args[]) {

new SudokuLayout();

}

}

1. Draw a class diagram in the space below (remember that private classes neednt to be in a class diagram):

2. Implementation conforms to the requirements (using private class listeners or adapter class):

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago