Question

In: Computer Science

1. How are different fonts set with Java GUI programs? What are font statistics? 2. What...

1. How are different fonts set with Java GUI programs? What are font statistics?

2. What is meant by drawing a string with Java and how is this done?

Solutions

Expert Solution

1. We use a class as java.awt.Font to mark a particular Font Face for required texts. A Constructor can also be created for creating an instance of Font. We may also proceed for setFont() method that is used to render the text with the current font. A font can be plain, bold or italic. The font face represents the name that is specified for a certain font face like Arial Italic, Arial etc. The Font Family describes the family structure for a particular font face. We have two other classifications for Fonts: Logical and Physical. Logical Fonts are assisted by JDK whereas Physical Fonts are font libraries itself. We can make use of a getAvailableFontFamilyNames() to get to know about all Font Family Names. We may use getAllFonts() for creating the Font Instance. For deriving a new instance of a Font, we can prefer deriveFont() which helps in the obtaining a font instance from the current font which offers difference in size, style and properties. We can use different methods or routines to get to know of current font such as getName(), getSize(), getStyle(), getFontName().

For acquiring the descriptive information about spacing and size of the text with a certain font, we use a class java.awt.font.LineMetrics. We can specify getLineMetrics() method in our code to ask for a metrics that have been used in a text for a particular font. Our code can also provide getStringBounds() method in our Font class that provides bounding box for particular text. FontShow is used to represent characterstics of a particular font been used in a text. LineMetrics class can allow us to use getAscent () and getDescent() methods that ask for height and depth of baseline been used in text. getLeading() method is used to get to know details of vertical spacing between the lines of text. getHeight() method is used to represent the total height of text with space.

2. While drawing different primitive shapes , we can also draw strings or text with the help of Graphics class. There are certain methods been used for drawing strings in Java. There are three methods to be used for drawing strings: drawString(), drawChars() and drawBytes(). In drawString() method, we use String class instance and two values of integers. The String class instance represents the string to be drawn such as void drawString(String name, int a, int b).  A drawChars() method contains character array, array offset, integer value for number of drawing characters and two coordinates enabling the text starting points such as drawChars(Char [] name, int offset, int l, int a , int b ). A drawBytes() method holds a byte array, an offset integer value, an integer value for number of bytes to be drawn and two coordinates representing the text starting points such as void drawBytes(byte [] name, int offset, int l, int a, int b).


Related Solutions

Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a) a TextField b) a Button c) a Text d) a Label 3. create the following container and put them the above controls: a) a VBox controller b) a BorderPane controller c) a GridPane
In java, Create a GUI which works as an accumulator 1. There is a textfield A...
In java, Create a GUI which works as an accumulator 1. There is a textfield A which allows user to enter a number 2. There is also another textfield B with value start with 0. 3. When a user is done with entering the number in textfield A and press enter, calculate the sum of the number in textfield B and the number user just entered in textfield A, and display the updated number in textfield B
Write 2 short Java programs based on the description below. 1) Write a public Java class...
Write 2 short Java programs based on the description below. 1) Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”} 2) Write a public Java...
Problem set #3 1) What is human capital, and how is it different from strictly the...
Problem set #3 1) What is human capital, and how is it different from strictly the quantity of workers available for work? Name three ways to increase a nation's human capital. Is an increase in the size of the labor force also an increase in the human capital? Explain your answer. 2) The Rule of 70 applies in any growth rate application. Let's say you have $1000 in savings and you have three alternatives for investing these funds. How long...
You are evaluating 2 different diets and 2 different exercise programs: one focused on cardio and...
You are evaluating 2 different diets and 2 different exercise programs: one focused on cardio and one focused on weight training. You want to determine which result in greater weight loss. You randomly assign participants to either diet A or B and either the cardio or weight training regimen, and then record the amount of weight they have lost after 1 month (y-axis = mean weight loss). Question: Which diet is better? Please explain (Hint: “it depends”). Link to graph:...
1. Explain "physical projects" and "regulatory programs". What is the challenge regarding the regulatory programs? 2....
1. Explain "physical projects" and "regulatory programs". What is the challenge regarding the regulatory programs? 2. Name two possible discount rate. Also, explain the difference between nominal and real rate
1. Explain "physical projects" and "regulatory programs". What is the challenge regarding the regulatory programs? 2....
1. Explain "physical projects" and "regulatory programs". What is the challenge regarding the regulatory programs? 2. Name two possible discount rate. Also, explain the difference between nominal and real rate if you do not know the answers please do not answer and i just want short answers not too long. thank you
1. What is a mutual fund? What is an ETF? How are they different? 2. What...
1. What is a mutual fund? What is an ETF? How are they different? 2. What are some arguments for why a mutual fund is better than an ETF? What are some of the arguments for why an ETF is better than a mutual fund? 3. Do professional money managers add value by picking the “right” (profitable) investments? 4. In shopping for stock mutual funds, what are the key, listed risk characteristics? 5. In shopping for bond mutual funds, what...
Use Java GUI create following: Task 1: A basic UI with a button and a TextField,...
Use Java GUI create following: Task 1: A basic UI with a button and a TextField, when you press the button, set the button text to the current text field contents. Task 2: set the text field text to the mouse coordinates when that same button is pushed.
Explain the different types of health insurance programs. What are the main differences among these programs?...
Explain the different types of health insurance programs. What are the main differences among these programs? How are they similar? Be sure to use terms that are unique to benefits, compensation, and human relations
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT