Question: JAVA 1- What happens when you place multiple buttons in the SOUTH of a container that uses a BorderLayout manager? 2- What happens when you

JAVA

1- What happens when you place multiple buttons in the SOUTH of a container that uses a BorderLayout manager?

2- What happens when you add a component directly to a JFrame and not to the content pane?

3- What is the name of the event method used to register a window event onto a JFrame?

4- In what ways do the GridBagLayout manager differ from the FlowLayout manager?

5 Given the following program, draw a diagram showing the output from it.

import javax.swing.JFrame;

import javax.swing.JButton;

import java.awt.Container;

public class Flow extends JFrame

{

static String[] arr = {"First", "Second", "Third", Fourth};

public static void main(String[] arg)

{

Flow flow = new Flow("Review");

Container c = flow.getContentPane();

c.setLayout(new FlowLayout(3));

for (int i = arr.length - 1; i >= 0; i--)

c.add(new JButton(arr[i]));

flow.setSize(500, 100);

flow.setVisible(true);

}

Flow(String str)

{

super(str);

}

}

6- Assume that the variable frame is a JFrame object, write appropriate java codes to register a window event object onto frame, such that when the window is about to close down, the message - Window is closing down appears on the DOS screen.

7- Name the method found in the ActionListener interface.

8- Differentiate between a Container object and a Component object. Support your answer with one example of each.

9-

Using the program segment given below, write appropriate Java code that would:

(a) Draw a polygon defined by the given arrays, and color the polygon blue.

(b) Draw the string Hello There! beginning at location x = 250, y = 150, on the application. Use courier font for lettering style. Bold the letters and use pitch 36 for the size of each of the letters. Color the letters magenta.

public void paint(Graphics g)

{

int X[] = {10, 30, 40, 50, 70, 50, 40, 30};

int Y[] = {40, 30, 10, 30, 40, 50, 70, 50};

// Put part (a) here

// Put part (b) here

}

10- Create a class called myTextArea inherited from JFrame. Create a text area object whose size is 300 x 250 pixels. Place the text area in a scrollable pane and place this scrollable pane in the content pane of the frame. Also, initialize the text area with the string Review - Fall 2004.

11- Design a class called MyGui. Incorporate the following features in the class.

Part I

Create a frame of your own by deriving it from the class JFrame.

Add the title Computer Science

Part II

Add a menu bar containing the only menu choice, Student

Add a pull down menu item to contain menu items Name and Course. Treat menu item Course as a menu, and add to it two menu items COP3337 and COP2210.

Add a button to the SOUTH of the screen and label it Exit

Part III

Add an anonymous mouse event listener class to the button such that when the button Exit is pressed the entire program (when built) closes down.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!