<< Chapter < Page
  Digital signal processing - dsp     Page 18 / 25
Chapter >> Page >

The code in Listing 24 :

  • Creates the JPanel object, and sets its layout property to GridLayout.
  • Creates the requisite number of objects of the MyCanvas class (which extends Canvas), setting the background colors of the panels alternately towhite and gray.
  • Adds the MyCanvas objects to the cells in the grid. (Note that the constructor for each MyCanvas object receives an integer that specifies itsposition in the stack of MyCanvas objects. We will see how that information is used later.)

More routine construction code

The code in Listing 25 is simply more routine code required to:

  • Finish the construction of the GUI object
  • Set its location and size on the screen
  • Make it visible

Once again, I will let the comments serve as the explanation for this code.

Listing 25. More routine construction code.
//Add the sub-assemblies to the // frame. Set its location, size,// and title, and make it visible. getContentPane().add(ctlPnl,"South"); getContentPane().add(canvasPanel,"Center"); setBounds(0,0,frmWidth,frmHeight);setTitle("Graph01, " + "Copyright 2002, " +"Richard G. Baldwin"); setVisible(true);//Set to exit on X-button click setDefaultCloseOperation(EXIT_ON_CLOSE); //Get and save the size of the// plotting surface width = canvases[0].getWidth(); height = canvases[0].getHeight();

Force a repaint

As you will see later, the actual plotting behavior of this program is defined by the code in an overridden version of the paint method in the MyCanvas class. I will discuss that code in some detail later.

One way to cause the code in the overridden paint method to be executed is to call the repaint method on a reference to a MyCanvas object.

The code in Listing 26 calls the repaint method on each MyCanvas object in sequence, to guarantee that they are properly painted when the GUI object first becomes visible.

Listing 26. Force a repaint.
for(int cnt = 0; cnt<number; cnt++){ canvases[cnt].repaint(); }//end for loop}//end constructor

Similar code will be used again later to cause the graphs to be repainted each time the user presses the Graph button in the bottom right corner of Figure 1 .

End of the constructor

The code in Listing 26 also ends the constructor for the GUI object. When the constructor finishes execution, the GUI appears on the screen with all plotting areas properly painted.

Re-plotting the data

[link] shows the beginning of the event handler that is registered on the button to cause the functions to be re-plotted.

Beginning of the re-plot code.
public void actionPerformed( ActionEvent evt){//Re-instantiate the object that // provides the datatry{ if(args != null){data = (GraphIntfc01)Class. forName(args).newInstance();}else{ data = new junk();}//end else }catch(Exception e){//Known to be safe at this point. // Otherwise would have aborted// earlier. }//end catch

The purpose of the event handler is to cause the functions to be re-plotted after the user changes the plotting parameters.

Questions & Answers

what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
yes that's correct
I think
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Digital signal processing - dsp. OpenStax CNX. Jan 06, 2016 Download for free at https://legacy.cnx.org/content/col11642/1.38
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?