SlideShare a Scribd company logo
1 of 7
1 How do you create a frame (AWT or swing)?
How do you set the size for a frame (AWT or swing)?
What would happen if the statements frame.setSize(400, 300)
and frame.setVisibile(true) (lines 9 and 12) were swapped in the
following program?
1: import javax.swing.*;
2:
3: public class MyFrameWithComponents {
4: public static void main ( String [] args ) {
5: JFrame frame = new JFrame( "MyFrameWithComponents" );
6: // Add a button to the frame:
7: JButton okayBtn = new JButton( "OK" );
8: frame.add( okayBtn );
9: frame.setSize( 400, 300 );
10: frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE
);
11: frame.setLocationRelativeTo( null ); // Center frame on
screen
12: frame.setVisible( true );
13: }
14: }
2 A Why do you need to use layout managers?
B What is the default layout manager for a Frame or JFrame?
C How do you add a component to a Frame or JFrame?
3 The following program is supposed to display a button in a
frame, but the button doesn't display.
What is the problem?
How would you fix that?
1: import javax.swing.*;
2:
3: public class Test extends JFrame {
4: public Test () {
5: add( new JButton( "OK" ) );
6: }
7:
8: public static void main ( String [] args ) {
9: JFrame frame = new JFrame();
10: frame.setSize( 100, 200 );
11: frame.setVisible( true );
12: }
13: }
4 A What is the default layout manager for a JPanel?
B How do you add a component to a JPanel?
5 A How do you create a Color object?
B What is wrong with the following code to create a Color?
new Color(400, 200, 300)
C Which of these two colors is darker?
new Color(10, 0, 0)
new Color(200, 0, 0)
6 How do you create a Font object with the font name Courier,
size 20 points, and style bold?
7 What happens if you add a button to a container several times,
as shown below?
Is this a syntax error, logic error, runtime error, or more than
one of these
?
1: JButton btn = new JButton( "click me" );
2: JPanel panel = new JPanel();
3: panel.add( btn );
4: panel.add( btn );
5: panel.add( btn );
8 Will the following code display three buttons (assume the
image is found and is correct)?
Will the buttons display the same icon?
1: import javax.swing.*;
2: import java.awt.*;
3:
4: public class Test extends JFrame {
5: public static void main ( String [] args ) {
6: JFrame frame = new Test();
7: frame.setTitle( "Button Icons" );
8: frame.setSize( 200, 100 );
9: frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE
);
10: frame.setVisible( true );
11: }
12:
13: public Test () {
14: ImageIcon usIcon = new ImageIcon( "images/us.gif" );
15: JButton jbt1 = new JButton( usIcon );
16: JButton jbt2 = new JButton( usIcon );
17:
18: JPanel p1 = new JPanel();
19: p1.add( jbt1 );
20:
21: JPanel p2 = new JPanel();
22: p2.add( jbt2 );
23:
24: JPanel p3 = new JPanel();
25: p3.add( jbt1 );
26:
27: add( p1, BorderLayout.NORTH );
28: add( p2, BorderLayout.SOUTH );
29: add( p3, BorderLayout.CENTER );
30: }
31: }
9 Given a JLabel object jlblMap, write the Java statements
needed to set the label’s foreground to red, background to
yellow, mnemonic to M, tool tip text to “Map Image”,
horizontal alignment to RIGHT, vertical alignment to
BOTTOM, horizontal text position to LEFT, vertical text
position to TOP, and the icon text gap to 5.
10 Can a button (either AWT or swing) fire a MouseEvent?
Can a button fire a KeyEvent?
Can a button fire an ActionEvent?
11 What method do you use to get the timestamp of an
ActionEvent?
12 Why does the ActionListener interface have no listener
interface adapter (that is, no ActionAdapter)?
13 How do you set focus on a component so it can listen for key
events?
14 How do you create a scrollable text area using swing?
15 How do you specify a line wrap for a text area, in swing?
How do you specify wrapping on characters?
How do you specify wrapping on words?
16 How do you create an ImageIcon from the file image/us.gif
(where image is a sub-directory of the directory containing your
Java classes)?
17 How do you create an AudioClip from the file anthem/us.mid
(where anthem is a sub-directory of the directory containing
your Java classes)?

More Related Content

Similar to 1 How do you create a frame (AWT or swing)How do you set th

Gui builder
Gui builderGui builder
Gui builderlearnt
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingPayal Dungarwal
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfMarlouFelixIIICunana
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFIJERD Editor
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdfoptokunal1
 
ma project
ma projectma project
ma projectAisu
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managersswapnac12
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appceleratorAlessio Ricco
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)Narayana Swamy
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Javasuraj pandey
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
JavaFX for Java Developers
JavaFX for Java DevelopersJavaFX for Java Developers
JavaFX for Java DevelopersSten Anderson
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDchessvashisth
 
JetBot basic motion
JetBot basic motionJetBot basic motion
JetBot basic motionPeiJia5
 
Chapter 5 GUI for introduction of java and gui .ppt
Chapter 5 GUI  for  introduction of java and gui .pptChapter 5 GUI  for  introduction of java and gui .ppt
Chapter 5 GUI for introduction of java and gui .pptHabibMuhammed2
 

Similar to 1 How do you create a frame (AWT or swing)How do you set th (20)

GUI programming
GUI programmingGUI programming
GUI programming
 
Gui builder
Gui builderGui builder
Gui builder
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
 
Draw2D
Draw2DDraw2D
Draw2D
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPF
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
 
ma project
ma projectma project
ma project
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appcelerator
 
Action script
Action scriptAction script
Action script
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)
 
Of class1
Of class1Of class1
Of class1
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
JavaFX for Java Developers
JavaFX for Java DevelopersJavaFX for Java Developers
JavaFX for Java Developers
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
 
JetBot basic motion
JetBot basic motionJetBot basic motion
JetBot basic motion
 
Chapter 5 GUI for introduction of java and gui .ppt
Chapter 5 GUI  for  introduction of java and gui .pptChapter 5 GUI  for  introduction of java and gui .ppt
Chapter 5 GUI for introduction of java and gui .ppt
 

More from hirstcruz

AristotleBelow is the second assignment for your assistance.  Th.docx
AristotleBelow is the second assignment for your assistance.  Th.docxAristotleBelow is the second assignment for your assistance.  Th.docx
AristotleBelow is the second assignment for your assistance.  Th.docxhirstcruz
 
Argument and Persuasion is a somewhat more challenging rhetorica.docx
Argument and Persuasion is a somewhat more challenging rhetorica.docxArgument and Persuasion is a somewhat more challenging rhetorica.docx
Argument and Persuasion is a somewhat more challenging rhetorica.docxhirstcruz
 
Argumentative Synthesis AssignmentThis assignment creates an opp.docx
Argumentative Synthesis AssignmentThis assignment creates an opp.docxArgumentative Synthesis AssignmentThis assignment creates an opp.docx
Argumentative Synthesis AssignmentThis assignment creates an opp.docxhirstcruz
 
Argumentative EssayThis writing assignment involves .docx
Argumentative EssayThis writing assignment involves .docxArgumentative EssayThis writing assignment involves .docx
Argumentative EssayThis writing assignment involves .docxhirstcruz
 
Are we civilizing these nations, or making them conform to our belie.docx
Are we civilizing these nations, or making them conform to our belie.docxAre we civilizing these nations, or making them conform to our belie.docx
Are we civilizing these nations, or making them conform to our belie.docxhirstcruz
 
Are humans experiencing microevolution due to natural selection I.docx
Are humans experiencing microevolution due to natural selection I.docxAre humans experiencing microevolution due to natural selection I.docx
Are humans experiencing microevolution due to natural selection I.docxhirstcruz
 
Appraise the effectiveness of the Integrated Marketing Communication.docx
Appraise the effectiveness of the Integrated Marketing Communication.docxAppraise the effectiveness of the Integrated Marketing Communication.docx
Appraise the effectiveness of the Integrated Marketing Communication.docxhirstcruz
 
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docx
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docxApply the reading on the MyArtsLab Closer Look at Édouard Manet, .docx
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docxhirstcruz
 
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docx
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docxAPPLY THE CONCEPTS LIFO inventory calculationClick here to re.docx
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docxhirstcruz
 
Apply a sociological perspective to the social world.Analyze conte.docx
Apply a sociological perspective to the social world.Analyze conte.docxApply a sociological perspective to the social world.Analyze conte.docx
Apply a sociological perspective to the social world.Analyze conte.docxhirstcruz
 
Applied social psychology is a field unto itself and provides rese.docx
Applied social psychology is a field unto itself and provides rese.docxApplied social psychology is a field unto itself and provides rese.docx
Applied social psychology is a field unto itself and provides rese.docxhirstcruz
 
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docx
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docxApplicationVolunteers Roles and RelationshipsBoard Governanc.docx
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docxhirstcruz
 
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docx
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docxApplicationIncorporating a Nonprofit OrganizationIntroduction.docx
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docxhirstcruz
 
ApplicationKnowing When to Make a ReferralSupporting the develo.docx
ApplicationKnowing When to Make a ReferralSupporting the develo.docxApplicationKnowing When to Make a ReferralSupporting the develo.docx
ApplicationKnowing When to Make a ReferralSupporting the develo.docxhirstcruz
 
Application Special Needs From a Variety of PerspectivesThroughou.docx
Application Special Needs From a Variety of PerspectivesThroughou.docxApplication Special Needs From a Variety of PerspectivesThroughou.docx
Application Special Needs From a Variety of PerspectivesThroughou.docxhirstcruz
 
Application Theoretical FrameworksEarlier weeks have focused on t.docx
Application Theoretical FrameworksEarlier weeks have focused on t.docxApplication Theoretical FrameworksEarlier weeks have focused on t.docx
Application Theoretical FrameworksEarlier weeks have focused on t.docxhirstcruz
 
Application The Civil Service SystemHow do public adminis.docx
Application The Civil Service SystemHow do public adminis.docxApplication The Civil Service SystemHow do public adminis.docx
Application The Civil Service SystemHow do public adminis.docxhirstcruz
 
Application Public Versus Private AdministratorsReflect o.docx
Application Public Versus Private AdministratorsReflect o.docxApplication Public Versus Private AdministratorsReflect o.docx
Application Public Versus Private AdministratorsReflect o.docxhirstcruz
 
Application Health Promotion organizations, non-profits, and agenci.docx
Application Health Promotion organizations, non-profits, and agenci.docxApplication Health Promotion organizations, non-profits, and agenci.docx
Application Health Promotion organizations, non-profits, and agenci.docxhirstcruz
 
Application Emergency Preparedness and Disaster ResponseIn thi.docx
Application Emergency Preparedness and Disaster ResponseIn thi.docxApplication Emergency Preparedness and Disaster ResponseIn thi.docx
Application Emergency Preparedness and Disaster ResponseIn thi.docxhirstcruz
 

More from hirstcruz (20)

AristotleBelow is the second assignment for your assistance.  Th.docx
AristotleBelow is the second assignment for your assistance.  Th.docxAristotleBelow is the second assignment for your assistance.  Th.docx
AristotleBelow is the second assignment for your assistance.  Th.docx
 
Argument and Persuasion is a somewhat more challenging rhetorica.docx
Argument and Persuasion is a somewhat more challenging rhetorica.docxArgument and Persuasion is a somewhat more challenging rhetorica.docx
Argument and Persuasion is a somewhat more challenging rhetorica.docx
 
Argumentative Synthesis AssignmentThis assignment creates an opp.docx
Argumentative Synthesis AssignmentThis assignment creates an opp.docxArgumentative Synthesis AssignmentThis assignment creates an opp.docx
Argumentative Synthesis AssignmentThis assignment creates an opp.docx
 
Argumentative EssayThis writing assignment involves .docx
Argumentative EssayThis writing assignment involves .docxArgumentative EssayThis writing assignment involves .docx
Argumentative EssayThis writing assignment involves .docx
 
Are we civilizing these nations, or making them conform to our belie.docx
Are we civilizing these nations, or making them conform to our belie.docxAre we civilizing these nations, or making them conform to our belie.docx
Are we civilizing these nations, or making them conform to our belie.docx
 
Are humans experiencing microevolution due to natural selection I.docx
Are humans experiencing microevolution due to natural selection I.docxAre humans experiencing microevolution due to natural selection I.docx
Are humans experiencing microevolution due to natural selection I.docx
 
Appraise the effectiveness of the Integrated Marketing Communication.docx
Appraise the effectiveness of the Integrated Marketing Communication.docxAppraise the effectiveness of the Integrated Marketing Communication.docx
Appraise the effectiveness of the Integrated Marketing Communication.docx
 
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docx
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docxApply the reading on the MyArtsLab Closer Look at Édouard Manet, .docx
Apply the reading on the MyArtsLab Closer Look at Édouard Manet, .docx
 
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docx
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docxAPPLY THE CONCEPTS LIFO inventory calculationClick here to re.docx
APPLY THE CONCEPTS LIFO inventory calculationClick here to re.docx
 
Apply a sociological perspective to the social world.Analyze conte.docx
Apply a sociological perspective to the social world.Analyze conte.docxApply a sociological perspective to the social world.Analyze conte.docx
Apply a sociological perspective to the social world.Analyze conte.docx
 
Applied social psychology is a field unto itself and provides rese.docx
Applied social psychology is a field unto itself and provides rese.docxApplied social psychology is a field unto itself and provides rese.docx
Applied social psychology is a field unto itself and provides rese.docx
 
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docx
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docxApplicationVolunteers Roles and RelationshipsBoard Governanc.docx
ApplicationVolunteers Roles and RelationshipsBoard Governanc.docx
 
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docx
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docxApplicationIncorporating a Nonprofit OrganizationIntroduction.docx
ApplicationIncorporating a Nonprofit OrganizationIntroduction.docx
 
ApplicationKnowing When to Make a ReferralSupporting the develo.docx
ApplicationKnowing When to Make a ReferralSupporting the develo.docxApplicationKnowing When to Make a ReferralSupporting the develo.docx
ApplicationKnowing When to Make a ReferralSupporting the develo.docx
 
Application Special Needs From a Variety of PerspectivesThroughou.docx
Application Special Needs From a Variety of PerspectivesThroughou.docxApplication Special Needs From a Variety of PerspectivesThroughou.docx
Application Special Needs From a Variety of PerspectivesThroughou.docx
 
Application Theoretical FrameworksEarlier weeks have focused on t.docx
Application Theoretical FrameworksEarlier weeks have focused on t.docxApplication Theoretical FrameworksEarlier weeks have focused on t.docx
Application Theoretical FrameworksEarlier weeks have focused on t.docx
 
Application The Civil Service SystemHow do public adminis.docx
Application The Civil Service SystemHow do public adminis.docxApplication The Civil Service SystemHow do public adminis.docx
Application The Civil Service SystemHow do public adminis.docx
 
Application Public Versus Private AdministratorsReflect o.docx
Application Public Versus Private AdministratorsReflect o.docxApplication Public Versus Private AdministratorsReflect o.docx
Application Public Versus Private AdministratorsReflect o.docx
 
Application Health Promotion organizations, non-profits, and agenci.docx
Application Health Promotion organizations, non-profits, and agenci.docxApplication Health Promotion organizations, non-profits, and agenci.docx
Application Health Promotion organizations, non-profits, and agenci.docx
 
Application Emergency Preparedness and Disaster ResponseIn thi.docx
Application Emergency Preparedness and Disaster ResponseIn thi.docxApplication Emergency Preparedness and Disaster ResponseIn thi.docx
Application Emergency Preparedness and Disaster ResponseIn thi.docx
 

Recently uploaded

Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 

Recently uploaded (20)

Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

1 How do you create a frame (AWT or swing)How do you set th

  • 1. 1 How do you create a frame (AWT or swing)? How do you set the size for a frame (AWT or swing)? What would happen if the statements frame.setSize(400, 300) and frame.setVisibile(true) (lines 9 and 12) were swapped in the following program? 1: import javax.swing.*; 2: 3: public class MyFrameWithComponents { 4: public static void main ( String [] args ) { 5: JFrame frame = new JFrame( "MyFrameWithComponents" ); 6: // Add a button to the frame: 7: JButton okayBtn = new JButton( "OK" ); 8: frame.add( okayBtn ); 9: frame.setSize( 400, 300 ); 10: frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 11: frame.setLocationRelativeTo( null ); // Center frame on screen 12: frame.setVisible( true );
  • 2. 13: } 14: } 2 A Why do you need to use layout managers? B What is the default layout manager for a Frame or JFrame? C How do you add a component to a Frame or JFrame? 3 The following program is supposed to display a button in a frame, but the button doesn't display. What is the problem? How would you fix that? 1: import javax.swing.*; 2: 3: public class Test extends JFrame { 4: public Test () { 5: add( new JButton( "OK" ) ); 6: } 7: 8: public static void main ( String [] args ) { 9: JFrame frame = new JFrame();
  • 3. 10: frame.setSize( 100, 200 ); 11: frame.setVisible( true ); 12: } 13: } 4 A What is the default layout manager for a JPanel? B How do you add a component to a JPanel? 5 A How do you create a Color object? B What is wrong with the following code to create a Color? new Color(400, 200, 300) C Which of these two colors is darker? new Color(10, 0, 0) new Color(200, 0, 0) 6 How do you create a Font object with the font name Courier, size 20 points, and style bold? 7 What happens if you add a button to a container several times, as shown below? Is this a syntax error, logic error, runtime error, or more than one of these ? 1: JButton btn = new JButton( "click me" );
  • 4. 2: JPanel panel = new JPanel(); 3: panel.add( btn ); 4: panel.add( btn ); 5: panel.add( btn ); 8 Will the following code display three buttons (assume the image is found and is correct)? Will the buttons display the same icon? 1: import javax.swing.*; 2: import java.awt.*; 3: 4: public class Test extends JFrame { 5: public static void main ( String [] args ) { 6: JFrame frame = new Test(); 7: frame.setTitle( "Button Icons" ); 8: frame.setSize( 200, 100 ); 9: frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 10: frame.setVisible( true ); 11: }
  • 5. 12: 13: public Test () { 14: ImageIcon usIcon = new ImageIcon( "images/us.gif" ); 15: JButton jbt1 = new JButton( usIcon ); 16: JButton jbt2 = new JButton( usIcon ); 17: 18: JPanel p1 = new JPanel(); 19: p1.add( jbt1 ); 20: 21: JPanel p2 = new JPanel(); 22: p2.add( jbt2 ); 23: 24: JPanel p3 = new JPanel(); 25: p3.add( jbt1 ); 26: 27: add( p1, BorderLayout.NORTH ); 28: add( p2, BorderLayout.SOUTH ); 29: add( p3, BorderLayout.CENTER );
  • 6. 30: } 31: } 9 Given a JLabel object jlblMap, write the Java statements needed to set the label’s foreground to red, background to yellow, mnemonic to M, tool tip text to “Map Image”, horizontal alignment to RIGHT, vertical alignment to BOTTOM, horizontal text position to LEFT, vertical text position to TOP, and the icon text gap to 5. 10 Can a button (either AWT or swing) fire a MouseEvent? Can a button fire a KeyEvent? Can a button fire an ActionEvent? 11 What method do you use to get the timestamp of an ActionEvent? 12 Why does the ActionListener interface have no listener interface adapter (that is, no ActionAdapter)? 13 How do you set focus on a component so it can listen for key events? 14 How do you create a scrollable text area using swing? 15 How do you specify a line wrap for a text area, in swing? How do you specify wrapping on characters? How do you specify wrapping on words? 16 How do you create an ImageIcon from the file image/us.gif (where image is a sub-directory of the directory containing your
  • 7. Java classes)? 17 How do you create an AudioClip from the file anthem/us.mid (where anthem is a sub-directory of the directory containing your Java classes)?