ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 02 May 2017 My Price 9.00

GUI (Graphical User Interface)

2.1.2 GUI (Graphical User Interface)

Create a subclass of the class JFrame that you will name GUI. This will be the main window of the application. 
You can read the documentation about the class JFrame here:https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html

You will need to import the package java.swing.JFrame to make the name JFrame available.

import javax.swing.JFrame; 

Add a constructor to the class GUI. In a graphical application, the constructor is usually the place where we construct the graphical representation of the application. This is logical since the constructor is called the moment the object is created. Here is the desired visual:

Figure 2 : the desired visual

To obtain a window like this, you will need to add the following elements to the constructor

  • Add a title to the window. This can be done in two different ways: by calling the constructor of thesuperclassand passing the title as a parameter (as a String) or by using the methodsetTitle.
  • It is necessary to add a call the methodSystem.exitwhen we close the window.
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    You can consult the documentation at the following address for more information: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation-int-
  • Create an objectDisplayAreaand add it to the center of the window. Since the classGUIis a subclass of the classJFrame, we can use theLayoutManger. Chose the one that will allow you to add the objectDisplayAreato thelower part of the window
  • Add the buttons to the lower part of the window. To do so, follow these steps:
    • Create an objectJPanel. It will act as a container for the buttons. Make sure that the background of this component is white.
    • Create four object of the classJButton. Use the labels “Left”, “Right”, “Up”, and “Down”.
    • Add these buttons to the objectJPanel. Note that the default layout ofJPanelisFlowLayout. This layout places the object from left to right then up to bottom based on the order that the elements have been added.
    • Add an object of typeJPanelto the classGUI. Since GUI is a subclass of JFame, it should be easy to add the panel at the desired position.
  • Finally, add the two calls to the following methods to the constructor. These methods have been inherited from the parent classes. The methodpackis inherited from the classjava.awt.Window, andsetResizablefrom the classjava.awt.Frame.
    setResizable(false); 
    pack();
    The first call makes the size of the application fixed, while pack determines the ideal size of the window based on its elements. This call to the method pack forces a call to the method getPreferredSize() from the classDisplayArea.
  • Add amainmethod of the classGUI. This method has to create an object of the class GUI. The main method also has to make the window visible. To do so, use the methodsetVisiblelike it the previous section.
  • Compile your application and make sure it resembles the application above.


If you click on the buttons, you will see that nothing happens. We will need to add an event handler to associate actions with each click of a button.

Attachments:

Answers

(11)
Status NEW Posted 02 May 2017 10:05 AM My Price 9.00

-----------

Attachments

file 1493719729-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)