Answer:
Here, I have following modified java program as shown below
SudokuLayout.java:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class SudokuLayout extends JFrame{
JTextArea txtArea;
JPanel gridPanel,butPanel;
JButton hint,reset,solve,newPuzzel;
JComboBox difficultyBox;
SudokuLayout()
{
setName("Sudoku Bord");
setLayout(new BorderLayout());
GridLayout gbag=new GridLayout(3,9);
gridPanel=new JPanel(gbag);
for (int k = 1; k <= 9; k++)
{
JPanel level2 = new JPanel(new GridLayout(3,3));
for (int i = 1; i <= 9; i++)
{
JTextField text = new JTextField(" ");
level2.add(text);
}
level2.setBorder(BorderFactory.createBevelBorder(1));
level2.setBackground(Color.BLACK);
gridPanel.add(level2);
}
add(gridPanel, BorderLayout.WEST);
hint=new JButton("Hint");
reset=new JButton("Reset");
solve=new JButton("Solve");
newPuzzel=new JButton("New Puzzel");
butPanel=new JPanel();
butPanel.setLayout(new BoxLayout(butPanel,BoxLayout.Y_AXIS));
butPanel.add(Box.createRigidArea(new Dimension(0,15)));
butPanel.add(reset);
butPanel.add(Box.createRigidArea(new Dimension(0,15)));
butPanel.add(hint);
butPanel.add(Box.createRigidArea(new Dimension(0,15)));
butPanel.add(solve);
butPanel.add(Box.createRigidArea(new Dimension(0,15)));
butPanel.add(newPuzzel);
butPanel.add(Box.createRigidArea(new Dimension(0,15)));
butPanel.add(Box.createRigidArea(new Dimension(0,15))); //add empty space between components
String[] difficulties = { "Easy", "Medium", "Hard"};
difficultyBox = new JComboBox(difficulties);
difficultyBox.setSelectedIndex(2);
butPanel.add(difficultyBox);
//add buttons panel on sudoku panel
add(butPanel,BorderLayout.EAST);
reset.addActionListener(new ButtonsAction());
hint.addActionListener(new ButtonsAction());
solve.addActionListener(new ButtonsAction());
newPuzzel.addActionListener(new ButtonsAction());
txtArea = new JTextArea(4, 20);
txtArea.setBorder(BorderFactory.createTitledBorder("output"));
txtArea.setText("Hello world!");
add(txtArea, BorderLayout.SOUTH);
}
private class ButtonsAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
Object button=e.getSource();
if(button.equals(hint))
{
txtArea.setText("Hint Button clicked!..");
}
else if(button.equals(reset))
{
txtArea.setText("Reset Button clicked!");
}
else if(button.equals(solve))
{
txtArea.setText("Solve button clicked!");
}
else
{
txtArea.setText("New Puzzel button clicked!");
}
}
}
}
TestSudoku.java:
import java.awt.Color;
import javax.swing.*;
public class TestSudoku
{
public static void main(String args[])
{
SudokuLayout frame=new SudokuLayout();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setSize(450,350);
frame.setResizable(false);
frame.setVisible(true);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Please fix and test my code so that all the buttons and function are working in...
tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) { JFrame frame = new temperatureConverter(); frame.setTitle("Temp"); frame.setSize(200, 100); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public temperatureConverter() { JLabel lblC = new...
I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 { public TextArea courseInput; public Label textAreaLabel; public JButton addData; public Dialog confirmDialog; HashMap<Integer, ArrayList<String>> students; public Fall_2017(){ courseInput = new TextArea(20, 40); textAreaLabel = new Label("Student's data:"); addData = new JButton("Add...
Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) { myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame { myJPanel6 p6; public myJFrame6 () { super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField p6 = new myJPanel6(); //------------------------------------------------------...
I have this problem for a final thats in my book thats i'm stuck on . Any help would be really appreciated. Design and code a Swing GUI to translate text that is input in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: ⦁ For words that begin with consonants, move the leading consonant to the end of the word and add “ay.” For example, “ball” becomes...
JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...
With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...
Any thoughts on this, i can get it to run but can't pass code around and the button doesnt move around. i didnt pass the student, or the app.java. What will you learn Combined use of Timer and the tracking of user interactions Deliverables app.java myJFrame.java myJPanel.java and other necessary Java files Contents The objective of the lab is to create a game in which the player has to click on a moving student-button to score. The student button has...
Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off. Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...
I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener { private JLabel titleLabel; private JTextField titleTxtFd; private JComboBox typeCmb; private ButtonGroup ratingGP; private JButton processBnt; private JButton endBnt; private JButton clearBnt; private JTextArea entriesTxtAr; private JRadioButton excellentRdBnt; private JRadioButton veryGoodRdBnt; private JRadioButton fairRdBnt; private JRadioButton poorRdBnt; private String ratingString; private final String EXCELLENT = "Excellent"; private final String VERYGOOD = "Very Good"; private final String FAIR = "Fair"; private final String POOR = "Poor"; String...