Question

In: Computer Science

home / study / engineering / computer science / questions and answers / working with layout...

home / study / engineering / computer science / questions and answers / working with layout managers. notes: 1. in part ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Working with Layout Managers. Notes: 1. In part 2,... Bookmark 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!\nSetting 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("Have fun playing this Tile Puzzle game", SwingConstants.CENTER); // ***** Task 3: // instantiate the JPanel component named top // Part 3 student code starts here: // set the layout of top to a 1-by-3 grid // instantiate the JButtons that determine the grid size // add the buttons to JPanel top // add JPanel top to the content pane as its north component // Part 3 student code ends here. // ***** Task 5: // Note: search for and complete Task 4 before performing this task // Part 5 student code starts here: // declare and instantiate an ActionListener // register the listener on the 3 buttons // that you declared in Task 1 // Part 5 student code ends here. contents.add(bottom, BorderLayout.SOUTH); setSize(325, 325); setVisible(true); } // ***** Task 4: // create a private inner class that implements ActionListener // your method should identify which of the 3 buttons // was the source of the event // depending on which button was pressed, // call the setUpGame method of the Game class // with arguments 3, 4, or 5 // the API of that method is: // public void setUpGame(int nSides) // At the end of the method call validate() // Part 4 student code starts here: // Part 4 student code ends here. public static void main(String[] args) { NestedLayoutPractice nl = new NestedLayoutPractice(); nl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class TilePuzzle { private int side; // grid size for game 1 private String[][] tiles; private int emptyRow; private int emptyCol; public TilePuzzle( int newSide ) { setUpGame( newSide ); } public void setUpGame( int newSide ) { if ( side > 0 ) side = newSide; else side = 3; side = newSide; tiles = new String[side][side]; emptyRow = side - 1; emptyCol = side - 1; for ( int i = 0; i < side; i++ ) { for ( int j = 0; j < side; j++ ) { tiles[i][j] = String.valueOf( ( side * side ) - ( side * i + j + 1 ) ); } } // set empty tile to blank tiles[side - 1][side - 1] = ""; } public int getSide( ) { return side; } /* public int getEmptyRow( ) { return emptyRow; } public int getEmptyCol( ) { return emptyCol; } */ public String[][] getTiles( ) { return tiles; } public boolean tryToPlay( int row, int col ) { if ( possibleToPlay( row, col ) ) { // play: switch empty String and tile label at row, col tiles[emptyRow][emptyCol] = tiles[row][col]; tiles[row][col] = ""; emptyRow = row; emptyCol = col; return true; } else return false; } public boolean possibleToPlay( int row, int col ) { if ( ( col == emptyCol && Math.abs( row - emptyRow ) == 1 ) || ( row == emptyRow && Math.abs( col - emptyCol ) == 1 ) ) return true; else return false; } public boolean won( ) { for ( int i = 0; i < side ; i++ ) { for ( int j = 0; j < side; j++ ) { if ( !( tiles[i][j].equals( String.valueOf( i * side + j + 1 ) ) ) && ( i != side - 1 || j != side - 1 ) ) return false; } } return true; } } Programming Activity 12-2 Guidance ================================== Overview -------- There are 5 parts. Make sure you complete the parts in numerical order. Notice that part 4 occurs in the code after part 5. As stated in the part 5 comments, you should complete part 4 before part 5 because part 5 has a step that says: "// declare and instantiate an ActionListener" This ActionListener must be an object of the private inner button handler class that you write in part 4. The 5 parts of 12-2 each have helpful comments. The comments will guide you about what code to write. Button instantiation -------------------- Suppose you define a button as follows: JButton three; To instantiate it with its label set to "3 x 3", you would write: three = new JButton("3 x 3"); 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. Part 4 button handler --------------------- You have to create a private inner class to handle events from any of the three game setup buttons. This course is cumulative. Each new chapter builds on previous chapters. Week 4 had a video called Java GUI Button Components. The code for that video was supplied in a folder in week 4. Here is a section of the code shown in that video: private class CommandHandler implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == btnDisplayTrees) { displayTrees(); return; } if (source == btnDisplayWater) { displayWater(); return; } if (source == btnPackWindow) { packWindow(); return; } if (source == btnReset) { reset(); return; } } etc. The above code shows a private inner class named CommandHandler that handles button events. You can name your button handler whatever you want, such as ButtonHandler, but you must use the same name in part 5 after the comment: // declare and instantiate an ActionListener In the above video example, there is an if test for each button event. Each of the if blocks does something and then returns. In your button handler, you also have to do a certain thing for each button as specified in the comments. However, you cannot then simply return because validate() must be called at the end of the function--no matter which button was clicked. There are 2 simple ways to achieve this: 1) Use nested if/else's followed by the validate() call, or 2) Call validate() after each button's processing and then return from each one as in the video example. Part 4 setUpGame() ------------------ The part 4 comments include: // depending on which button was pressed, // call the setUpGame method of the Game class // with arguments 3, 4, or 5 // the API of that method is: // public void setUpGame(int nSides) To call a function we need an object of its class. Does our framework code have an object for us of type Game? Looking near the beginning of the NestedLayoutPractice class that we are in, you will see the following declaration: private Game game; So, game is an object reference of type Game that we can use. Your framework starting code already includes the following line of code in part 2: game = new Game(3); // instantiating the GamePanel object This is where the game object is actually created. It is passed a value of 3 in the constructor call. This will cause the game to be created with 3 rows by 3 columns of numbered squares. Now back to your part 4 handler comments. The comments say to change the game setup as instructed based on which button was clicked. If you look at the example user interface you will see that there are 3 buttons to change the game to 3 x 3, or 4 x 4, or 5 x 5 squares. You should have already declared these buttons in part 1 and created them in part 3 as instructed. In part 4, your event handler function must handle when each of the buttons is clicked. If, for exaample, the 4 x 4 button is clicked, then you should have the following line of code for that event: game.setUpGame(4); Don't overthink this. It is a simple function call using the game object, its setUpGame() method, and a literal parameter of 4. At the end of the function, call

Solutions

Expert Solution

6
down vote
Using this thread, and also the indisputable fact that if f1f1 and f2f2 ar 2 integrable functions, F(f⋆g)=F(f)⋅F(g)F(f⋆g)=F(f)⋅F(g), we have
F(ddx(f⋆g))(x)=ixF((f⋆g))(x)=ixF(f)(x)⋅F(g)(x),
F(ddx(f⋆g))(x)=ixF((f⋆g))(x)=ixF(f)(x)⋅F(g)(x),
and
F((ddxf)⋆g)(x)=(F(ddxf))⋅(F(g)(x))=ixF(f)(x)⋅F(g)(x).
F((ddxf)⋆g)(x)=(F(ddxf))⋅(F(g)(x))=ixF(f)(x)⋅F(g)(x).
We conclude by individuality of Fourier remodel.

shareciteimprove this answer
answered Jul thirty one '12 at 16:57

Davide Giraudo
108k15114218
2     
How you'll be able to take Fourier remodel whereas we do not comprehend it has Fourier remodel or not? In alternative words, we do not understand ddx(f∗g)ddx(f∗g) is in L1L1? For the second Fourier remodel, it's correct since we all know that f′∗gf′∗g is in L1L1. – rfvahid Jul thirty one '12 at 17:09
     
Indeed, it deserves additional details. i feel associate degree approximation argument will work (approximate in L1L1 ff and gg by C1C1 functions with compact support). – Davide Giraudo Jul thirty one '12 at 17:20
add a comment
up vote
6
down vote
Note that, if f∈L1(R)f∈L1(R) then it's Fourier translatable. Since,

∣∣∣∫∞−∞f(x)e−ixw∣∣∣≤∫∞−∞|f(x)|&lt;∞
|∫−∞∞f(x)e−ixw|≤∫−∞∞|f(x)|&lt;∞
.

To prove that the convolution of 2 L1(R)L1(R) performs is once more associate degree L1(R)L1(R) function, let

h(x)=∫f(t)g(x−t)dt
h(x)=∫f(t)g(x−t)dt
∫|h(x)|dx≤∫∫|f(t)||g(x−t)|dtdx=∫|f(t)|∫|g(x−t)|dxdt=∫|f(t)|||g||1dt=||f||1||g||1⇒h∈L1(R).
∫|h(x)|dx≤∫∫|f(t)||g(x−t)|dtdx=∫|f(t)|∫|g(x−t)|dxdt=∫|f(t)|||g||1dt=||f||1||g||1⇒h∈L1(R).
The modification of the order of integration is even by Fubini's theorem. So, you'll be able to use the Fourier technique as in Davide's answer.

shareciteimprove this answer
edited August one '12 at 16:30
answered Jul thirty one '12 at 18:46

Mhenni Benghorbal
40.2k52967
add a comment
up vote
0
down vote
Definition:
h(x)=f∗g(x)=∫f(x−t)g(t)dt
h(x)=f∗g(x)=∫f(x−t)g(t)dt
Let's calculate derivative:

dhdx=limdx−&gt;0(∫f(x+dx−t)g(t)dt−∫f(x−t)g(t)dt)dx=limdx−&gt;0(∫(f(x+dx−t)−f(x−t))dxg(t)dt
dhdx=limdx−&gt;0(∫f(x+dx−t)g(t)dt−∫f(x−t)g(t)dt)dx=limdx−&gt;0(∫(f(x+dx−t)−f(x−t))dxg(t)dt
If assume that for
(f(x+dx−t)−f(x−t))dx
(f(x+dx−t)−f(x−t))dx
exist some integrable perform q(t), that is edge on this expression, perhaps except potential on set with live zero then by Lebesgue dominated convergence theorem we will push the limit within integral.

dhdx=f∗g(x)=∫f′(x−t)g(t)dt=f′∗g


Related Solutions

home / study / engineering / computer science / computer science questions and answers / create...
home / study / engineering / computer science / computer science questions and answers / create a new java file, containing this code public class datastatsuser { public static void ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Create a new Java file, containing this code public class DataStatsUser { public static void... Create a new Java file, containing this code public class DataStatsUser { public static void main...
home / study / engineering / computer science / computer science questions and answers / Modify...
home / study / engineering / computer science / computer science questions and answers / Modify StudentLinkedList Class By Adding The Following Methods:  PrintStudentList: Print ... Your question has expired and been refunded. We were unable to find a Chegg Expert to answer your question. Question: Modify StudentLinkedList class by adding the following methods:  printStudentList: print by call... Modify StudentLinkedList class by adding the following methods:  printStudentList: print by calling and printing “toString” of every object in...
home / study / engineering / computer science / computer science questions and answers / 2....
home / study / engineering / computer science / computer science questions and answers / 2. design an er-diagram for a bank that implements the following requirements. the database ... Question: 2. Design an ER-diagram for a bank that implements the following requirements. The database you d... 2. Design an ER-diagram for a bank that implements the following requirements. The database you design should store information about customers, accounts, branches and employees • Customer: Customers are identified by their SSN....
home / study / engineering / computer science / computer science questions and answers / write...
home / study / engineering / computer science / computer science questions and answers / write a program that in c++: 1.prompts the user to enter a positive integer, think of this ... Question: Write a program that in C++: 1.Prompts the user to enter a positive integer, think of this intege... Write a program that in C++: 1.Prompts the user to enter a positive integer, think of this integer as representing a specific number of pennies. 2. The program...
home / study / engineering / computer science / computer science questions and answers / Using...
home / study / engineering / computer science / computer science questions and answers / Using JAVA The Following Code Is Able To Read Integers From A File That Is Called "start.ppm" ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Using JAVA The following code is able to read integers from a file that is called "start.ppm" ont... Using JAVA The following code is able to read integers from...
home / study / engineering / computer science / questions and answers / this is c....
home / study / engineering / computer science / questions and answers / this is c. create three files to submit. contacts.h ... Question: This is C. Create three files to submit. Contacts.... Bookmark This is C. Create three files to submit. Contacts.h - Struct definition, including the data members and related function declarations Contacts.c - Related function definitions main.c - main() function (2) Build the ContactNode struct per the following specifications: Data members char contactName[50] char contactPhoneNum[50] struct ContactNode*...
The questions read as follows: home / study / engineering / computer science / computer science...
The questions read as follows: home / study / engineering / computer science / computer science questions and answers / Course Grades Java Class In A Course, A Teacher Gives The Following Tests And Assignments: ... Question: Course grades java class In a course, a teacher gives the following tests and assignments: A lab ... course grades java class In a course, a teacher gives the following tests and assignments: A lab activity that is observed by the teacher and...
home / study / science / nursing / nursing questions and answers / This Is A...
home / study / science / nursing / nursing questions and answers / This Is A Theoretical Case Taken From VHA Intensive Ethics Advisory Committee Training, 1998, ... Your question has been posted. We'll notify you when a Chegg Expert has answered. Post another question. Next time just snap a photo of your problem. No typing, no scanning, no explanation required. Get Chegg Study App Question: This is a theoretical case taken from VHA Intensive Ethics Advisory Committee Training, 1998,...
home / study / science / nursing / nursing questions and answers / you are a...
home / study / science / nursing / nursing questions and answers / you are a public health researcher. you have been asked to identify a vaccine-preventable disease. ... Question: You are a public health researcher. You have been asked to identify a vaccine-preventable disease... You are a public health researcher. You have been asked to identify a vaccine-preventable disease. Your research design should focus on determining why health care workers are not receiving the vaccination for your selected vaccine-preventable...
home / study / science / biology / questions and answers / which of the following...
home / study / science / biology / questions and answers / which of the following best explains why atp is ... Question: Which of the following BEST explains why ATP is a ... Save Which of the following BEST explains why ATP is a positive regulator of aspartate transcarbamoylase (ATCase)? A. Aspartate is only available when ATP levels are high. B. ATP levels correspond to CTP levels, thus when both ATP and CTP are high, ATCase is active. C....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT