F27SB2 Programming Languages

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
User Interfaces II GUI – Awt, Swing, Web
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
GUI. Swing Programs Four basic types of Top Level Window – JFrame, a top level window decorated like a native window – JWindow, an undecorated stand-alone.
Graphical User Interfaces
Graphics and event-driven programs Learning objectives By the end of this lecture you should be able to: identify and use some of the common components.
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
More on GUI We wrap up our examination of Java GUI programming by looking at several other components and their listeners – The components all come from.
Drawing in a frame – Java GUI
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
JAVA 程式語言入門 (II).  版面配置  事件驅動  Ch14_01.java 1. import javax.swing.*; 2. import java.awt.*; 3. class Ch14_01 4. { 5. public static void main(String.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Övning 5. Repetition klasser class Rektangel { private static int antal = 0; private double längd; private double bredd; public Rektangel(double l, double.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 16 Java Fundamentals Java2 Graphical User Interfaces.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Chapter 8: Graphical User Interfaces Objectives - by the end of this chapter, you should be able to do the following: –write a simple graphical user interface.
Java Programming Chapter 10 Graphical User Interfaces.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
Introduction to Swing Components Chapter 14.  Part of the Java Foundation Classes (JFC)  Provides a rich set of GUI components  Used to create a Java.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
Graphical User Interface Components: Part 1 Chapter 11.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Lec.10 (Chapter 8 & 9) GUI Jiang (Jen) ZHENG June 27 th, 2005.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.
Basics of GUI Programming Chapter 11 and Chapter 22.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
1 Lecture 8: User Interface Components with Swing.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Welcome To java
CHAPTER 7 & 8 REVIEW QUESTIONS
Graphical User Interface (pronounced "gooey")
Graphical User Interface
Presentation transcript:

F27SB2 Programming Languages Multiple Choice Questions

Introduction these questions are from: Y. Daniel Liang, Introduction to Java Programming, Ninth Edition http://www.cs.armstrong.edu/liang/intro9e/test.html thanks to Hind Zantout for locating the source and selecting appropriate questions please note that: some questions have multiple correct answers our exam is not based on this source of questions

Chapter 12 5 Which component cannot be added to a container? A. JPanel B. JButton C. JFrame D. JComponent

Chapter 12 6 Which of the following are subclasses of java.awt.Component? A. Container classes B. Swing user interface classes C. Helper classes such as Color and Font D. Layout managers

Chapter 12 12 Which of the following classes are in the java.awt package? A. Color B. Font C. Component D. JFrame E. JComponent

Chapter 12 15 Analyze the following code. ... public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My Frame"); frame.add(new JButton("OK")); frame.add(new JButton("Cancel")); ... } } A. Only button OK is displayed. B. Only button Cancel is displayed. C. Both button OK and button Cancel are displayed and button OK is displayed on the left side of button OK. D. Both button OK and button Cancel are displayed and button OK is displayed on the right side of button OK.

Chapter 12 16 How many frames are displayed? public class Test { public static void main(String[] args) { JFrame f1 = new JFrame("My Frame"); JFrame f2 = f1; JFrame f3 = f2; f1.setVisible(true); f2.setVisible(true); f3.setVisible(true); } } A. 1. B. 2. C. 3. D. 0.

Chapter 12 20 Analyze the following code: public class Test1 extends JFrame { public Test1() { JButton jbt1 = new JButton("OK"); add(jbt1); jbt1 = new JButton("Not OK"); } public static void main(String[] args) { JFrame frame = new Test1(); ... } } A. The program displays nothing. B. The program displays a button with text OK. C. The program displays a button with text Not OK. D. The program displays a button with text OK and another button with text Not OK.

Chapter 12 21 What layout manager should you use so that every component occupies the same size in the container? A. a FlowLayout B. a GridLayout C. a BorderLayout D. any layout

Chapter 12 22 What should you use to position a Button within an application Frame so that the size of the Button is NOT affected by the Frame size? A. a FlowLayout B. a GridLayout C. the center area of a BorderLayout D. the East or West area of a BorderLayout E. the North or South area of a BorderLayout

Chapter 12 26 To set a FlowLayout in panel jp, you can use the method __________. A. jp.setLayout(new FlowLayout()); B. jp.setLayout(new FlowLayout(FlowLayout.CENTER)); C. jp.setLayout(new FlowLayout(FlowLayout.center)); D. jp.setLayout(FlowLayout

Chapter 12 27 The default layout out of a contentPane in a JFrame is __________. A. FlowLayout B. GridLayout C. BorderLayout D. None

Chapter 12 28 The default layout out of a JPanel is __________. A. FlowLayout B. GridLayout C. BorderLayout D. None

Chapter 12 29 To create a JPanel of the BorderLayout, use ______________. A. JPanel p = new JPanel() B. JPanel p = new JPanel(BorderLayout()); C. JPanel p = new JPanel(new BorderLayout()); D. JPanel p = new JPanel().setLayout(new BorderLayout());

Chapter 12 30 To add a component c to a JPanel p, use _________. A. p.add(c) B. p.getContentPane(c) C. p.insert(c) D. p.append(c)

Chapter 12 32 The method __________ sets the background color to yellow in JFrame f. A. setBackground(Color.yellow) B. f.setBackground(Color.YELLOW) C. f.setBackground(Color.yellow) D. setBackground(Color.YELLOW) E. f.setBackGround(Color.yellow)

Chapter 12 33 The method __________ sets the foreground color to yellow in JFrame f. A. setForeground(Color.yellow) B. f.setForeground(Color.YELLOW) C. f.setForeground(Color.yellow) D. setForeground(Color.YELLOW) E. f.setForeGround(Color.yellow)

Chapter 12 35 The method __________ sets the font (Helvetica, 20-point bold) in component C. A. c.setFont(new Font("Helvetica", Font.bold, 20)) B. c.setFont(new Font("helvetica", BOLD, 20)) C. c.setFont(Font("Helvetica", Font.BOLD, 20)) D. c.setFont(new Font("Helvetica", Font.BOLD, 20))

Chapter 12 37 Can you use the setBackground method to set a back ground color for _____? A. Component B. Container C. JComponent D. JButton E. JLabel

Chapter 12 43 You can use methods ___________ on any instance of java.awt.Component. A. setForeground B. setBackground C. setFont D. getFont E. setLayout

Chapter 12 47 The method __________ gets the text (or caption) of the button jbt. A. jbt.text() B. jbt.getText() C. jbt.findText() D. jbt.retrieveText().

Chapter 12 64 The method __________ assigns the name Result to the Text of variable jlbl. A. jlbl.setText("Result") B. jlbl.newText("Result") C. jlbl.text("Result") D. jlbl.findText()

Chapter 16 1 Pressing a button generates a(n) __________ event. A. ItemEvent B. MouseEvent C. MouseMotionEvent D. ActionEvent E. ContainerEvent

Chapter 16 2 Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event. A. ItemEvent B. WindowEvent C. MouseMotionEvent D. ComponentEvent E. ContainerEvent

Chapter 16 6 Which of the following statements registers a panel object p as a listener for a button variable jbt? A. addActionListener(p); B. jbt.addActionListener(p); C. jbt.addActionEventListener(p); D. jbt.addEventListener(p);

Chapter 16 7 The interface __________ should be implemented to listen for a button action event. A. MouseListener B. ActionListener C. FocusListener D. WindowListener E. ContainerListener

Chapter 16 33 To be a listener for ActionEvent, an object must be an instance of ____________. A. ActionEvent B. ActionListener C. EventObject D. WindowListener E. WindowEvent

Chapter 17 1 Clicking a JButton object generates __________ events. A. ActionEvent B. ItemEvent C. ComponentEvent D. ContainerEvent

Chapter 17 4 Pressing the Enter key on a JTextField generates _____________ events. A. ActionEvent B. ItemEvent C. ComponentEvent D. ContainerEvent

Chapter 17 5 The method __________ appends a string s into the text area jta. A. jta.setText(s) B. jta.appendText(s) C. jta.append(s) D. jta.insertText(s)

Chapter 17 7 To wrap a line in a text area jta, invoke ____________. A. jta.setLineWrap(false) B. jta.setLineWrap(true) C. jta.WrapLine() D. jta.wrapText()

Chapter 17 9 The method __________ adds a text area jta to a scrollpane jScrollPane. A. jScrollPane.add(jta) B. jScrollPane.insert(jta) C. jScrollPane.addItem(jta) D. None of the above.