Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Computer Science Assignment: Java Programming

Program: First GUI

Throughout the semester, we have been working on command line applications. While the command line can be a powerful form of interacting with the computer, most modern applications have a graphical user interface, or GUI. This program will give you some initial experience making GUI applications with Swing.

Things you will learn

• How to set up a simple GUI based on JFrame
• Setting up listeners and responding to events
• Drawing simple shapes and images
• Dealing with mouse and mouse motion events

Directions

1. Write a GUI application in Java using Swing that has a three buttons and a drawing area. The buttons should be at the top of the window. The buttons should be labeled as "swap", "center", and your name.

2. Give the window an initial size of 800 x 600 pixels, and put your name in the menu bar.

3. The drawing area should cover the remainder of the window.

4. When it starts, the program should show an oval with your name in the center of it (that is not an image of an oval). Also, it should show an image of your choice read in from a file somewhere on the screen. The background of the drawing area should be a non-white color.

5. Pressing the "center" should cause both the the oval to move to the center of the window.

6. You must also be able to click and drag the oval with your name or the image around the screen independently with the mouse.

7. When you click the "swap" button, the oval and image should swap positions on the screen.

8. When the user presses the button with your name on it, the program should do something else not described in the assignment that is unique to your program, such as change the color of all the things you draw, switch the oval to be outlines instead of filled, or something like that.

9. As always, make sure the proper block comment is at the top of your main file with your name.

10. Once your program is working, pass it off directly to the instructor or TA. Also, turn in your code to D2L.

Suggestions

• Get the skeleton of your GUI working first. First get the buttons drawing properly, then go on to listen to and respond to events.

• Initially, hook up the event listeners so that they print something to the console when a button is pressed. That way you can know that your code is getting events.

• Make a subclass of JPanel called "DrawPanel" or something like that to draw the objects. Override the "paintComponent" method of this class. This class needs boolean variables to decide whether to draw the rectangle, oval, your name, and the special. It may also need other variables to indicate colors, positions of things, etc.

• You can measure a string using the FontMetrics class. This measures how much space (in pixels) the string will take when drawn. You would use this information to determine where to place the text and backing rectangle.

Java, Programming

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

Have any Question?


Related Questions in Java

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

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 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 ...

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 ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

  • 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