0% found this document useful (0 votes)
51 views11 pages

AJP Chapter 1

I have done this

Uploaded by

171 Om Bhoyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
51 views11 pages

AJP Chapter 1

I have done this

Uploaded by

171 Om Bhoyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
hh of the following statements are true? To distinguish new Swing component classes from their gy, counterparts, Swing GUI component classes are named with a prefiy All Swing GUI components are lightweight. A user interface object such as (button, list) can appear in ons container. (d) A container such as JFrame is also a component. 2. Which of the following statements about GUI components is wrong ? (2) Swing exists since version 1.2 of the jdk (b) You can not place AWT components on Swing containers (©) AWT stands for Abstract Window Toolkit (d) The AWT classes are deprecated Which of the following are subclasses of java.awt.Component? (a) Container classes (b) Swing user interface classes (¢) Helper classes such as Color and Font (d) Layout managers ‘Swing components that don't rely on native GUI are referred to as —: (a) lightweight components _(b)_ heavyweight components (c) GUI components (d)_non-GUI components programming 1115 5, What is best to describe the relationship between 1Component and 38 ‘and 3Button? (a) Association (b) Aggregation (©) Composition (6) Inheritance fh Neh componentcannet be edt a conan? {a) JPanel (b) 2Button (©) JFrame (@)_3Component ‘analyze the following code. © aport java-ant amport javax.swing.*; public class Test [ public static void main(Stringf] args) ( Component ¢ = new dButton(*0K"); serame frame © new JFrame(*My Frame"); frame.add (ec) frame. setDefaultCloseoperat ion (JFrame. BX1T_ON_CLOSE) ; frame.setVisible (true); ) , (a) You cannot assign @ JButton to a variable of java.awt.Component. (b) You can only add ¢ to a container because c's type is Component. (c) You cannot add a Swing component directly to a 3Frame using add(c) prior to JDK 1.4, but itis OK in DK 15. > (a) You cannot create a JFrame using new JFrame("My Frame"), 8, Analyze the following code, import java. awt.*7 sport javax.swing.*7 public class Test Public static void main(string{) args) ( JFrame frame = new JFrame ("My Frame"); frame.add (new JButton ("0K") )7 frane.add (new JButton ("cancel") )7 frane set DefaultCloseoperation (JFr frane.setsize(200, 2007 ‘ane .EXIT_ON_CLOSE) + frame. setVisible(teue) H Advanced Java Pre 10. u 12, Programming, 115 nro. to Abc Wadoning To (A 8g (a) Only button Ok is displayed. (b)_ Only button Cancel is displayed. (©) Both button OK and button Cancel are displayed and button OK js displayed on the left side of button OK (a) Both button OK and button Cancel are displayed and button OK is displayed on the right side of button OK. How many frames are displayed? import javax.swing.*7 public class public static void main(string{] ag3) [ Jrame £1 = new JFrame(*Hy Frame"); aerame £2 = 1; werane £3 = £2; f1.setVielble(true) f2.setVialble (true) 13. setVisible (true); 1 , (a) (b) 2 (3 i) 0 Which of the following statements is for placing the frame's upper left corer to (200, 100)? (a) frame.settocation(100, 100) (b) frame.setLocation( 100, 200) (©) frame.setLocation(200, 100) (0) frome.settocation(200, 200) What should you use to position a Button within an application Frame s0 tet the size of the Button is NOT affected by tne Frame size? (a) @ FlowLayout (b) a GridLayout (0) the center area of a BorderLayout (a) the East or West area of a BorderLayout mat layout manager should you use jes th Se ee erie mame tam chr comers Sear (a) @ Flowtayout (0) a Gridtayout (c)_ a BorderLayout (@) any layout va ad ‘ Into.to a Hr. to Abstat Windowing Tet (AW) & Swings 13, Suppose a JFrame uses the GridLayout(2, 0). If you add six but frame, how many columns are displayed? fons to the @ (b) 2 3 (@ 4 ‘o set a FlowLayout in panel jp, you can use the method __. (a) jp.setLayout(new FlowLayout()); a {b) jp.setLayout(new FlowLayout(FlowLayout.CENTER)); {@) jp.setLayout(new FlowLayout(FlowLayout.center)); {@) jpsetLayout(FlowLayout()); ‘Suppose a JFrame uses the GridLayout(0, 2). If you add six buttons to the frame, how many columns are displayed? (a) 1 (b) 2 © 3 (a) 4 ‘Suppose @ JFrame uses the GridLayout(2, 2). If you add six buttons to the frame, how many columns are displayed? @ 1 (b) 2 © 3 (@) 4 J The default layout out ofa 3Panel is __. (2) FlowLayout (b) GridLayout (©) Bordertayout (@) None 418, The defeult layout out of @ contentPane in a JFrame is _. (@) Flowtayout (b) GridLayout (©) BorderLayout (a) None 19. To create a JPanel of the BorderLayout, use 4 45. 16. (@) 3Panel p = new 3Panel() (b) JPanel p = new JPanel(BorderLayout()); (©) JPanel p = new JPanel(new BorderLayout()); (@) Janel p = new JPanel().setLayout(new BorderLayout()); 20. _ creates a color object. (@) new Color(0, 0, 0) (b) new Color(0, 266, 0) (©) new Color(255, 255, 255) (d) new Color(t, 2, 3) 21. To add a component ¢ to a JPanel p, use (@) p.adace) (b) p.getContentPane(<) ag, ©, Paste) (2) p.append(c) . The method sets the foreground color to yellow in JFrame f. (a) setForeground(Color. yellow) (©) f.setForeground(Color. YELLOW) (©) f.setForeground(Color. yellow) (@) setForeground(Color. YELLOW) of Advanced Jv Programing 1110 hv. Abt! denn ten an 23, Which color is the darkest? (a) new Color(0, 0, 0) (c)_new Color(20, 0, 0) 24. 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) 25, The method ___ sets the font (Helvetica, 20-point bold) In component ¢. (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)) (a) _c.setFont(new Font("Helvetica", Font.BOLD, 20)) 26. Can you use the setBackground method to set a back ground coor fo, (bnew Color(10, 0, 0) (a) new Color(30, 0, 0) (a) Component (b) Container (©) Component (a) 3Button 27. To specify a font to be bold and italic, use the font style value _ (2). Font-PLAIN (b) Font.BOLD (©) Font.ITALIC (d) Font.BOLD + Font-ITALIC 28. Can you use the setBorder method to set a border for_? (2) Component (b) Component. (c) JButton (d) JLabel 29. Can you use the getWidth method to get a width for_ (a) Component (b) Container (©) 3Component (d)3Button 30. You can use methods ____on any instance of java.awt.Component. (2) setBackground (b)_getBackground (©) getBorder (6) getHeight 31. Analyze the following code: import javax.swing.*; Public class Test extends JFrame ( PrivatedButtonjbtoK = new Jautton(#0K") ; Public static void main(String!] args) { // Create a frane and set its properties sostio 32, 33, 7ning tn Abstract Wendowing Tok (AWN & Swings mmo aetTite ("Logic Error"); pefaultcloseop ame. EXIT_ON_CLOSE) ; sotVisible(true); oO public 7 peOK. set TOOLTEpText (*This 5 a button"); gda(new JButton (*OK")); ' ' (a) The too! tip text is displayed when you move the mouse on the button. (b) The tool tip text will be displayed if you replace add(new JButton(*OK")) with add(jbtOK). (c)_ The tool tip text will be displayed if you swap the two lines in the Test constructor. (@) The tool tip text will be displayed if you replace add(new JButton("OK")) with add(jbtOK = new JButton("OK")).. Can you use the setTooITip method to set a tool tip for (2) JLabel (b) Container (©) Component (d) Button Show the output of the following code? import javax.swing.*; Public class Test ( Public static void main(Stringl) args) ( JButtonjbtoK = new JButton ("OK"); System.out print (jbtOK.-isvisible() +") * JFrame frame = new gFrame() ; System.out.printin(frame.isVisible(}}; , (2) true, true (©) true, false ©) ‘false, true (a) false, false You can use methods ‘on any instance of java.at. Component. (2) setForeground (b) setBackground (©) setFont (d) setLayout 1 sto Asie a pa Progemming 2120 Ae Nine Toh a Jig methods on the button jbt? a) ich of the folowing are val fo) pbesettnemoni("®) (b) jbt.setMnemonic(’A'y; (2) jpesettconTextGap(s0): (2) pt setTextGap(50); (ere mage eon fro file n \booK\mage\con, use {0 new imagelcon(:\book\image\con)i to) ew Imagetcon‘:\book\mageVcon’ {e)_ new Imagetcon(":\\pook\\nage\ eon") {5} new Imagetcon(c:\book\\image\\icon eo retnad. gets the text (or caption) ofthe button bt, (a) jpttext() (p) jot.getText() (0). btfindText() (¢) jbtretrieveText(), Which of the following Is true? (2) JButton inherits from javax.sw (b) You can create a JButton by speci (c) You can create a JButton by specifying a (4) You can create a JButton by a text. 1. Analyze the following code: import javax. swing. 7 import java.awt.*; public class Test extends JFrame ( ing. AbstractButton. ying an icon and text, in icon. public Test() ( InageTconusIcon Button jbe1 = new JButton(usteon) + Button jbt2 = new JButton(ustcon) ; lew Imagecon ("image/usTcon.gif"); gPanel pl = new Jeanel(); pl.add(3bt1); JPanel p2 = new JPanel (); p2.add (Jbt2); gPanel p3 = new JPanel (); p2.add (3bEL) 5 add(pl, BorderLayout NORTE) ; add(p2, BorderLayout .SOUTE) ; add(p3, BorderLayout .CENTER) ) Public static void main(String] args) ( 1/ Greate a frame and set its properties Gerame frame = new Test (); rane, setSize(200, 100); {rane tpatinteei tds ton (rcane.nerr_o¥ £1098)! } , 40. a. 2 4a. sa 0:40 Abarat Windowing Toot (AW) & Swings {a) Two buttons displayed with the same icon, b) Three buttons displayed with the same icon. {6)_ Only Jott displays the icon and jbt2 does not display the icon. {@) Two buttons displayed with different icons. ‘the method creates alconimage for file c\image\us.cif. (a) new Imagelcon("e:\image\us.gif); {b) new Icon(*c:\image\us.gi" {o)_new Imagelcon("c:\\image\\us.gif}; {@)_ new Icon("e:\\image\\us.gif; ‘The method specifies that the text is placed on the right of the icon in the button jbt. {a) jbt.setVerticalTextPosition(JButton.LEFT) (0) jbt-setHorizontalTextPosition(JButton. LEFT) (c) jbt-setHorizontalTextPosition(Button.RIGHT) () jbt setHorizontalAlignment(JButton.RIGHT) ‘The method ‘specifies that the text and icon are horizontally aligned to the right in the button jb. (@) jpt.setVerticalTextPosition(JButton LEFT) () bt.setHorizontalTextPosition(JButton.LEFT) {¢)_jpt.setHorizontarTextPosition( Button. RIGHT) {(@) JotsetHorizontalalignment(JButton. RIGHT) ‘Analyze the following code: Inport javax.swing.*7 import java.awt-*7 public class Test extends JFrame { public Test () ( setLayout (new FlowLayout ())7 add(new Button ("Java") add (new Button (*Java")) 7 add(new gButton ("Java") 5 ada(new JButton("Java")) 7 , public static void main(stringl) args) | 11 Create a frame and set ies properties JFrane frame = new Test (0 frame. setSize(200, 100); frame. getDefaultCloseoperation (JFrame. EXIT_ON_CLOSE) ; frane.setVieible (true) : y ae jazz intro. to Abatract Windowing Toot (AT a 44, 4s. (2). One button is displayed with the text "Java (b) Two buttons are displayed with the same text “Jova". (€)_ Three buttons are displayed with the same text "Java". (4) Four buttons are displayed with the same text "Java". _____ checks whether the JCheckBoxjchk is selected. (a) jchk.getSelected() (b) jchk.selected() (c) jchk.isSelected(). (d)_jehk.select() Analyze the following code: import javax. swing. *7 import javax.swing-border.* Amport java-awt.*7 public class Test extends JFrame { public Test () ( Border border = new TitledBorder("My button"); Button jbl = new JButton(*0K"); Button jbt2 ~ new JButton ("Cancel"); Jott .setBorder (border) + jbt2.setBorder (border) ; add (jbt1, BorderLayout NORTH) ; ada (jbt2, BorderLayout SOUTH) ; public static void main(string() args) ( Frame frame = new Test (); frane.setSize(200, 100); frame. setDefaultClosedperat ion (JPrane.EXIT_ON_CLOSE) ; Frame.setVieible(true) (a) Two buttons displayed with the same border, (b) Two buttons displayed, but only one button has the bord: (©) The program has a co mpile error use 7 TiledBorder("My button to variable of the wenn tine sient 1e Border type. (@) The program has a runtime error button. Tor because you cannot set a border 0” # «Progaming 3 post vii of Wai ou can create a9 istance of BuKoNGroup and ad rd Instance to group the buttons, ip) ButtonGrouP can be added to» container. (oTocheck whether a radio button jr is selected, use istered) (6) By default, when a radio button is created, the radio butter © noe selected. whieh ofthe following statements are true? (a) 2CheckBox inherits from Javax.swing.AbstractBtton, {uy Allthe methods in JCheckBox are also in 3Button {@) You can set a mnemonic for a ICheckBox, {@) You can use an icon on JCheckBox. wich ofthe fllotng statements are true? (a) RadioButton inherits from javax. swing. AbstractButton, (0) Allthe methods in JRadioBultton are also in 3Button, (©) You can set a mnemonic fr a ICheckBiox (@) You can use an icon on IRadioButon, 4, The method __ gets the text (or caption) ofthe labet jb following statements are true? 4. ”. 48 (2) jtb.text() (b) jlbl.getText() (0) jlbLrindText() (2) jlbl retrieveText() 50. Which of the following are valid methods on the label jbl? (2) jibl.setMnemonic("A"); _(b)_jlbl.setMnemonic(‘A’); (©) Sibl.seticonTextap(50); (4) jIbl.setTextGap(50); 51, Which of the following statements are true? (@) All the methods in. ‘JLabel are inherited from Javax.swing.AbstractButton. (®) You can set a mnemonic key in a JLabel (©) You can create a label with both text and icon. (©) You can create a label with an icon. The method assigns the name Result to the Text of variable jlbl. (2) jibi.setText(*Result") (b)_jibl.newText("Result") (©) jibl.text("Result") (d)_jibl.findText() The method specifies that the text and icon are horizontally aligned to the right in the label jlbl. (2) sib setverticarrgxtPosition(3Button.LEFT) (©) jIbl setHorizontalTextPosition (Button. LEFT) (©) bl setHorizentarTextPosition(JButton.RIGHT) ) Jbl setHorizontalAlignment(JButton.RIGHT) 8, 83, 324 Intro. to Abstract Windowing Tootkit ( -svance Java Progaming 8 54, The method specifies that the text is placed on the right of the jan in the label jlbl. (@) sib.setVerticarTextPosition(JButton-LEFT) (p) jibl setHorizontalTextPosition(JButton.LEFT) (c) ib.setHorizontalTextPosition(JButton.RIGHT) (@) jibl setHorizontalAlignment( Button-RIGHT) 55. Which of the following statements are true? (a) You can specify a horizontal text alignment in a text field (b) You can specify the number of columns in a text field. () You can disable editing on a text field. (¢) You can create a text field with a specified text. 56. ___can be used to enter or display a string. (a) Alabel (b) A button (c) Acheck box (d) texfield 57. The method ___gets the contents of the text field jtf. (a) jtf.getText(s) (b)_jtf.getText() (c)_ jtf.getString() (d)_jtf.findString() in ac Answers F )— 3. (a,b) 4. (a) 5.(4) La@ 8..(b) 9.(2) 10.(2) rer 13.4 | 14. (a,b) | _15.(0) | [a] —18.(a) | 19.) | 20. (a,c,8) | 26. (,b,c,¢) | | 24. (bc) | 25.6) — {—_29.(¢)__|_30.(2,bd)_— 34. (a,b,c) | 35. (b) — | 40. — | 45. (2) [ so. (¢) — (ss. (a,b,6.8)-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy