Calculate new dimensions for the textdraw panel

Assignment Help Computer Engineering
Reference no: EM132076127

You need help with this JAVA program. Here my previous code for it and the instructions are below it.

public class DrawPanel implements Runnable { static int width = 250; static int height = 250; JFrame application; public void run() { application = new JFrame(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add(new IDrawPanel()); application.setSize(width, height); application.setVisible(true); } public static void main(String[] args) { DrawPanel dp = new DrawPanel(); SwingUtilities.invokeLater(dp); } class IDrawPanel extends JPanel { int steps = 16; Color clr = new Color(0, 192, 0); public void paint(Graphics gr) { int hgt, wid, x1, y1, x2, y2, x3, y3, hst, vst; Graphics2D g2 = (Graphics2D)gr; g2.setColor(clr); wid = getWidth(); hgt = getHeight(); hst = wid / steps; vst = hgt / steps; x1 = y1 = 0; x3 = wid - 1; y3 = hgt - 1; for (x2 = hst, y2 = hgt - vst; x2 < wid && y2 > 0; x2 += hst, y2 -= vst) { g2.drawLine(x1, y1, x2, y2); g2.drawLine(x2, y2, x3, y3); } } } }

Using the DrawPanel example, create a program that will display the string "BCS 345" in a well-proportioned window using a 42-point font of the SanSerif family.

Use the following guidelines:

Rename the IDrawPanel to TextPanel

After the application frame is set visible, get the dimensions of both the application frame and the TextDraw panel using get size

Calculate and save the difference between the two in both the height and width dimensions.

Implement the TextPanel as a Component listener.

In the componentResized() method, set a doFlag to indicate that the font needs to be calculated.

In the paint method is the font needs to be recalculated, do the following

get the current font from the Grapics and derive a 42 point font from it

Save the new font so it can be set in the Graphics whenever it is necessary to repaint

Get the new font's FontMetrics object

Get the display rectangle of the string "BCS 345"

Calculate new dimensions for the TextDraw panel that are 4/3 the width and 3/2 the height

Calculate the beginning point for a text display that centers the text in the dimensions of the panel with the new size.

Set the application frame to the new size plus the difference in the components' height and width calculated earlier. This should resize the window so that it will appear as shown in the attached image

Reset the doFont flag

In the paint() method's common logic, set the font, set the color, and draw the BCS 345 string.

Reference no: EM132076127

Questions Cloud

Write a recursive function called sumdigits : Write a recursive function called sumDigits with the following signature: public static long sumDigits(long n).
Create a package named reading_with_exceptions : Create a package named "reading_with_exceptions". Write a class named: Reading_With_Exceptions with the following method.
Find the work done hoisting : Find the work done hoisting a 1,500 pound generator 50 feet straight up into the air. Assume the force of gravity is acting straight downwards
What is the instantaneous rate of change : What is the instantaneous rate of change of the remaining amount of medication after 1 hour?
Calculate new dimensions for the textdraw panel : Calculate and save the difference between the two in both the height and width dimensions.
Create an array that holds hundred integers : Write a complete method (including a full method header) called contains.Create an array that holds 100 integers
Find values for the parameters a and p : a. Find values for the parameters a and P. b. State the initial quantity and the percent rate of growth or decay.
Find the indicated probability : Suppose that X has a normal distribution. Find the indicated probability. The mean is 15.2 and the standard deviation is 0.9. Find the probability that X is gre
Write a findwinner method that takes in two moves : Determining the winner will require you to compare a lot of possible match-ups through a series of nested conditionals.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd