Project #65153 - 7 Java Programming Discussion questions

Answer the 7 DQ ONLY #2-8 on time with no PLAGIARISM 

 

 

 

***** DOES NOT NEED TO BE ANSWERED******

#1 What is an event? How are events and graphical user interfaces (GUIs) related?

Provide an example of an event and relate it to a GUI.

***** DOES NOT NEED TO BE ANSWERED******

 

 

 

#2 Write a 200 word response to Michelle’s answer to #1.

A graphical user interface (GUI) is created with at least three different objects which are, components , events and listeners. A component is a container such as frame or graphical screen element, an example of this is a button. An event is an object that represents an activity buy the user, such as clicking on a check box. Listeners do just that, "listen" for an event to happen and then respond as programmed too.

Events and user interfaces are related as without a graphical user interface there would be no event and therefore nothing to listen for. The event is caused by interaction from a user to a component within the graphical interface, such as a button or check box. 

An great example of this that we all can relate to, would be our individual assignment this week. We are to make a simple graphical user interface with an "Exit" button. The component would be the button within the graphical user interface. The event would be the clicking of the button by the user with the intention of closing the program. The listener would be "listening" for that clicked button and  then exit the program.#3 Write a 200- to 300-word short-answer response for the following:

How are containers used in the Java(r) language? Write a small program in which you

add components to a container. Then post the code for your program.

 

#3 Write a 200- to 300-word short-answer response for the following:

How are containers used in the Java(r) language? Write a small program in which you add components to a container. Then post the code for your program.

 

 

#4 Write a 200 word response to Victor’s answer to #3.

A container is true to its namesake. According to our reading it holds other components

that can be implemented as a program, and displayed as a window known as a frame. I

don't have much experience working with GUI so forgive me for the crudeness of my

application. It was written in NetBeans and compiled and run successfully. It is simple,

and displays a title field along with a sized window, that can display contents within.

/*

* This program was written for

* University of Phoenix

* By Victor M. Beas

*/

package javacontainers;

import javax.swing.*;

/**

*

* @author Victor M. Beas

*/

public class JavaContainers extends JFrame {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

final int WIN_WIDTH = 350,

WIN_HEIGHT = 250;

JFrame greeting = new JFrame("Welcome to the new window!"); //Creates Window

with greeting

greeting.setSize(WIN_WIDTH, WIN_HEIGHT);

greeting.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

greeting.setVisible(true);

}

}

A pattern I've noticed is that some programmers like to call import javax.swing.* and

some like to call individual classes, such as import javax.swing.JFrame. Is there a

benefit to one over the other? Thanks.

 

 

#5. Write a 200 word response to instructors statement to #3.

Java is an Object Oriented (OO) programming language. OO programming differs from

sequential or functional programming in many ways. Hopefully, you learned some of

this in Java Programming I. OO programming has traits such as encapsulation and

inheritance, to name a few.

Also, there is a design pattern called the Model View Controller (MVC) design pattern

that is used in GUI programming or OO programming in general. Maybe some one can

describe the MVC design pattern.

One thing that is not a good practice in OO programming is to do everything in the

main() method. This is not OO programming. You might as well be programming in the

C programming language, which is a functional language.

To start to get the hang of OO programming, I would suggest structuring your code as

follows:

import javax.swing.JFrame;

/*

* This program was written for

* University of Phoenix

* By Victor M. Beas

*/

/**

*

* @author Victor M. Beas

*/

public class JavaContainers extends JFrame {

public static final int WIN_WIDTH = 350;

public static final int WIN_HEIGHT = 250;

public JavaContainers() {

// Display a title

super("Welcome to the new window!");

this.buildGui();

}

/**

* Method to create the content of the GUI

*/

void buildGui() {

setSize(WIN_WIDTH, WIN_HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

JavaContainers container = new JavaContainers();

}

}

Some things to notice: JavaContainers already extends JFrame. You don't need to

create another JFrame. To add to this, just create new components as private

variables, instantiate them in the constructor and add them to the window in the

buildGui() method. This is OO programming.

 

 

#6. Write a 200 word response to Luis’ answer to #3.

In Java, "a container is simply a component that holds other components. In GUI

terminology, a container that can be displayed as a window is known as a frame . A

frame is a basic window that has a border around it, a title bar, and a set of buttons for

minimizing, maximizing, and closing the window. In a Swing application, you create a

frame from the JFrame class." (Gaddis, 2011) Below is an example of a JFrame

container in use.

package containers;

import javax.swing.JFrame; //Allows the use of the JFrame class

import javax.swing.JLabel; //Allows the use of the JLabel class

public class Containers extends JFrame{

public static void main(String[] args) {

JFrame GUI = new JFrame("Hello World"); //Create JFrame window

GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set action for closing

the window

GUI.setVisible(true); //Make window visible (disabled by default)

GUI.setSize(100, 100); //Set size of window

JLabel lblHello = new JLabel("Hello World!"); //Creates a label to add to the container

window

GUI.add(lblHello); //Adds the label to the window

}

}

Gaddis, T. (2011). Starting Out with Java: Early Objects (4th ed.). : Pearson Education,

Inc..

 

 

#7 Write a 200- to 300-word short-answer response for the following:

What do you feel are the advantages and disadvantages to using Swing versus

AWT?

 

 

#8. Write a 200 word response to Adam’s Answer to #1.

From the previous classes with .NET and Java, events are basically actions that occur

with the application that initiate a reaction. This could be clicking, mouseover, and even

text changes within the application. These events are commonly used within the GUI

for button clickings, it could contain the code private void

jButton4ActionPerformed(java.awt.event.ActionEvent evt) indicating that when this

button is clicked, the action within this code is performed. This action could affect other

controls within the GUI, depending the purpose that it is serving. It is also important to

consider the parts of the GUI that has access to the data created within other parts of

the application. Normally this could be maintained by the use of Private and Public

states of the events. Listeners are also events as they react to certain conditions that

are met within the application. Text changes is a common example, as well as boolean

responses. This is most commonly seen with forms that are designed to collect

information and to react to certain conditions; such as invalid format or data. The most

effective means of illustrating incorrect or invalid information is by highlighting the fields

that contain the data in question.

With these events, it is imperative to have contingency plans in place to protect the

application from essentially crashing and causing problems. Normally, try - catch

methods are useful to create a response to syntax errors.

 

 

elaborate on his answer say you agree or disagree and why and so forth 

Subject Computer
Due By (Pacific Time) 04/05/2015 01:00 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy