false items should be explained if false

The true/false items should be explained if false. 1. Method mouseMoved is called when the mouse is moved with no buttons pressed and an event listene...
Author: Joel Reeves
0 downloads 2 Views 176KB Size
The true/false items should be explained if false. 1. Method mouseMoved is called when the mouse is moved with no buttons pressed and an event listener is registered to handle the event. 2. A(n) layout manager arranges GUI components in a Container. 3. Method setLayout is used to specify the layout manager for a container. 4. A mouseDragged method is preceded by a(n) mousePressed method call and followed by a(n) mouseReleased method call (think about the order events will be fired). 5. T/F. In a BorderLayout, two buttons added to the NORTH region will be placed side by side. - False, Only the last button added will be displayed. Remember that only one component should be added to each region in a BorderLayout. 6. T/F. When one is using BorderLayout, a maximum of five components should be displayed. - True. 7. T/F. A JPanel cannot be added to another JPanel. - False, A JPanel can be added to another JPanel, because JPanel is a Component can be added to a Container. 8. Find the error(s) in each of the following statements, and explain how to correct it (them): a) buttonName = JButton( “Caption” ); ­ new is needed to create an object. b) JLabel aLabel, JLabel; //create references ­ JLabel is a class name and cannot be used as a variable name. c) txtField = new JTextField( 50, “Default Text” ); ­ The arguments passed to the constructor are reversed. The String must be passed first. d) Container container = getContentPane(); setLayout( new BorderLayout() ); button1 = new JButton( “North Star” ); button2 = new JButton( “South Pole” ); container.add( button1 ); container.add( button2 ); ­ BorderLayout has been set, and components are being added without specifying the region so both are added to the center region. Proper add statements might be container.add( button1, BorderLayout.NORTH ); container.add( button2, BorderLayout.SOUTH ); 9. T/F. Only one layout manager can be used per Container. True. 10. T/F. GUI components can be added to a Container in any order in a BorderLayout. True, when using proper adds. 11. Create the following GUI, You do not have to provide any functionality.

- See attached code Example1.java 12. Write a temperature conversion program that converts from Fahrenheit to Celsius. The Fahrenheit temperature should be entered from the keyboard (via a JTextField). A JLabel  should be used to display the converted temperature. Use the following formula for the conversion: Celcius = 5/9 x ( Fahrenheit – 32) ­ see attached code Conversion.java 13. The drawLine method of class Graphics draw a line between two points. 14. RBG is short for red , blue and green . 15. Font sizes are measured in units called points . 16. T/F. The first two arguments of Graphics method drawOval specify the center coordinate of the oval. - False, the first two arguments specify the upper-left corner of a GUI component on which drawing occurs. 17. T/F. In the Java coordinate system, x value increased from left to right. True 18. T/F. Method getSize returns the size of the current font in centimeters. False, font size is measured in points. 19. Find the error(s) in each of the following and explain how to correct the error(s). Assume that g  is a Graphics object. a) g.setFont( “SansSerif” ); - The setFont method takes a Font object as an argument – not a String b) g.erase(x, y, w, h); // clear rectangle at (x, y) - The Graphics class does not have an erase method. The clearRect method should be used. c) Font f = new Font( “Serif”, Font.BOLDITALIC, 12); ­ Font.BOLDITALIC is not a valid font style. To get a bold italic font, use Font.BOLD+Font.ITALIC. d) g.setColor( Color.Yellow ); // change color to yellow ­ Yellow should be all uppercase letters as in g.setColor( Color.YELLOW ); 20. Class Graphics of the Java2D API is used to draw ovals. 21. Methods draw and fill of class Graphics2D require an object of type Shape . 22. T/F. The drawPolygon method automatically connects the endpoints of the polygon. True. 23. T/F. The Graphics class is an abstract class. True. 24. Write a program that draws a series of eight concentric circles. The circle should be separated

by 10 pixels. Use the drawOval method of class Graphics. - See attached code Circles.java 25. T/F. When String objects are compared using ==, the result is true of the String contain the same values. - True, see StringTest.java 26. T/F. A String can be modified after it is created. - False, a String object is immutable. 27. Write an application that uses String method compareTo to compare two strings input by the user. Output whether the first string is less than, equal to or greater than the second. - See attached code StringCompareTo.java 28. Members of a class specified as private are accessible only to method of the class. 29. A(n) constructor is used to initialize the instance variable of a class. 30. The keyword class introduces a class declarations. 31. Members of a class specified as public are accessible anywhere an object of the class is in scope. 32. A method declared static cannot access non-static class members directly. 33. The elements of an array are related by the fact that they have the same name and type . 34. The number used to refer to a particular element of an array is called the element's index . 35. An array that uses two indices is referred to as a(n) two-dimensional array. 36. T/F. An array index should normally be of type float. - False, an index can only be an integer or an integer expression. 37. T/F. An individual array element that is passed to a method and modified in the method will contain the modified value when the called method completes execution. - For individual primitive-type elements o an array: False. Such elements are passed by value. If a reference to an array is passed, the modifications to the array elements are reflected in the original. For individual elements of a non-primitive type: True. Such elements are passed by reference, and changes to the object will be reflected in the original array element. 38. Perform the following tasks for an array called table: a) Declare and create the array as an integer array that has three rows and three columns. Assume that the constant ARRAY_SIZE has been declared to be 3. - int table[][] = new int[ ARRAY_SIZE][ARRAY_SIZE]; b) How many elements does the array contain? - Nine. c) Use a for statement to initialize each element of the array to the sum of its indices. Assume that the integer variables x and y are declared as control variables. - for (int x = 0; x