Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Assignment

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)?

Java, Programming

  • Category:- Java
  • Reference No.:- M92559081

Have any Question?


Related Questions in Java

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As