Java Using NetBean
Write a program that can dynamically change the font of a
message. The font name or font size
can be chosen from combo boxes. The font name can be Dialog,
DialogInput, Monospaced,
Serif, or SansSerif. The font style can be selected as PLAIN, BOLD
and/or ITALIC.
Font myFont = new Font("Serif", Font.PLAIN,
12);
message.setFont(myFont);
Below is the solution:
code:
FontChange.java:
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
/**
*
* @author nehal
*/
public class FontChange extends JFrame {
// Variables declaration - do not modify
private JComboBox cmbFontStyle;
private JComboBox cmbFontType;
private JLabel lblMessage;
// End of variables declaration
public FontChange() {
cmbFontType = new
JComboBox();
cmbFontStyle = new
JComboBox();
lblMessage = new JLabel();
// add the combo items to font
style
cmbFontType.addItem("Dialog");
cmbFontType.addItem("DialogInput");
cmbFontType.addItem("Monospaced");
cmbFontType.addItem("Serif");
cmbFontType.addItem("SansSerif");
// add the combo items to font
type
cmbFontStyle.addItem("PLAIN");
cmbFontStyle.addItem("BOLD");
cmbFontStyle.addItem("ITALIC");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new
GridLayout());
getContentPane().add(cmbFontType);
getContentPane().add(cmbFontStyle);
lblMessage.setText("Message");
getContentPane().add(lblMessage);
pack();
// create font type of
each
Font DialogPlain = new
Font("Dialog", Font.PLAIN, 18);
Font DialogBold = new
Font("Dialog", Font.BOLD, 18);
Font DialogItalic = new
Font("Dialog", Font.ITALIC, 18);
Font DialogDialogInputPlain =
new Font("DialogInput", Font.PLAIN, 18);
Font DialogDialogInputBold = new
Font("DialogInput", Font.BOLD, 18);
Font DialogDialogInputItalic = new
Font("DialogInput", Font.ITALIC, 18);
Font MonospacePlain = new
Font("Monospace", Font.PLAIN, 18);
Font MonospaceBold = new
Font("Monospace", Font.BOLD, 18);
Font MonospaceItalic = new
Font("Monospace", Font.ITALIC, 18);
Font SerifPlain = new
Font("Serif", Font.PLAIN, 18);
Font SerifBold = new Font("Serif",
Font.BOLD, 18);
Font SerifItalic = new
Font("Serif", Font.ITALIC, 18);
Font SansSerifPlain = new
Font("SansSerif", Font.PLAIN, 18);
Font SansSerifBold = new
Font("SansSerif", Font.BOLD, 18);
Font SansSerifItalic = new
Font("SansSerif", Font.ITALIC, 18);
// action listener for the font
type
// cmbFontType.addActionListener(new
ActionListener() {
// public void
actionPerformed(ActionEvent event) {
//
// Get the source of the component, which is our
combo
//
// box.
//
cmbFontType = (JComboBox)
event.getSource();
//
//
// Print the selected items and the action
command.
//
Object selectedFontType =
cmbFontType.getSelectedItem();
//
Object selectedFontStyle =
cmbFontStyle.getSelectedItem();
//
//
System.out.println("selectedFontType\n");
//
System.out.println("selectedFontType" +
selectedFontType);
//
System.out.println("selectedFontStyle" +
selectedFontStyle);
//
//
if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("PLAIN")) {
//
lblMessage.setFont(DialogPlain);
//
} else if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("BOLD")) {
//
lblMessage.setFont(DialogBold);
//
} else if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("ITALIC")) {
//
lblMessage.setFont(DialogItalic);
//
}
//
else if (selectedFontStyle.equals("DialogInput")
&& selectedFontType.equals("PLAIN")) {
//
lblMessage.setFont(DialogDialogInputPlain);
//
} else if
(selectedFontStyle.equals("DialogInput") &&
selectedFontType.equals("BOLD")) {
//
lblMessage.setFont(DialogDialogInputBold);
//
} else if
(selectedFontStyle.equals("DialogInput") &&
selectedFontType.equals("ITALIC")) {
//
lblMessage.setFont(DialogDialogInputItalic);
//
}
//
else if (selectedFontStyle.equals("Monospaced")
&& selectedFontType.equals("PLAIN")) {
//
lblMessage.setFont(MonospacePlain);
//
} else if
(selectedFontStyle.equals("Monospaced") &&
selectedFontType.equals("BOLD")) {
//
lblMessage.setFont(MonospaceBold);
//
} else if
(selectedFontStyle.equals("Monospaced") &&
selectedFontType.equals("ITALIC")) {
//
lblMessage.setFont(MonospaceItalic);
//
}
//
else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("PLAIN")) {
//
lblMessage.setFont(SerifPlain);
//
} else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("BOLD")) {
//
lblMessage.setFont(SerifBold);
//
} else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("ITALIC")) {
//
lblMessage.setFont(SerifItalic);
//
}
//
else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("PLAIN")) {
//
lblMessage.setFont(SansSerifPlain);
//
} else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("BOLD")) {
//
lblMessage.setFont(SansSerifBold);
//
} else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("ITALIC")) {
//
lblMessage.setFont(SansSerifItalic);
//
}
// }
// });
// action listener for the font
style
cmbFontStyle.addActionListener(new
ActionListener() {
public void
actionPerformed(ActionEvent event) {
// Print the selected items and the action
command.
Object selectedFontStyle =
cmbFontType.getSelectedItem(); // comboBox Selected items for font
style
Object selectedFontType =
cmbFontStyle.getSelectedItem(); // comboBox Selected items for font
type
// check for the comboBox Selected items font
type and font style
if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("PLAIN")) {
lblMessage.setFont(DialogPlain);
} else if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("BOLD")) {
lblMessage.setFont(DialogBold);
} else if (selectedFontStyle.equals("Dialog")
&& selectedFontType.equals("ITALIC")) {
lblMessage.setFont(DialogItalic);
} else if
(selectedFontStyle.equals("DialogInput") &&
selectedFontType.equals("PLAIN")) {
lblMessage.setFont(DialogDialogInputPlain);
} else if
(selectedFontStyle.equals("DialogInput") &&
selectedFontType.equals("BOLD")) {
lblMessage.setFont(DialogDialogInputBold);
} else if
(selectedFontStyle.equals("DialogInput") &&
selectedFontType.equals("ITALIC")) {
lblMessage.setFont(DialogDialogInputItalic);
} else if
(selectedFontStyle.equals("Monospaced") &&
selectedFontType.equals("PLAIN")) {
lblMessage.setFont(MonospacePlain);
} else if
(selectedFontStyle.equals("Monospaced") &&
selectedFontType.equals("BOLD")) {
lblMessage.setFont(MonospaceBold);
} else if
(selectedFontStyle.equals("Monospaced") &&
selectedFontType.equals("ITALIC")) {
lblMessage.setFont(MonospaceItalic);
} else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("PLAIN")) {
lblMessage.setFont(SerifPlain);
} else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("BOLD")) {
lblMessage.setFont(SerifBold);
} else if (selectedFontStyle.equals("Serif")
&& selectedFontType.equals("ITALIC")) {
lblMessage.setFont(SerifItalic);
} else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("PLAIN")) {
lblMessage.setFont(SansSerifPlain);
} else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("BOLD")) {
lblMessage.setFont(SansSerifBold);
} else if (selectedFontStyle.equals("SansSerif")
&& selectedFontType.equals("ITALIC")) {
lblMessage.setFont(SansSerifItalic);
}
}
});
}
// main method
public static void main(String args[]) {
FontChange fc = new
FontChange();
fc.setSize(400, 200); // set the
frame size
fc.setVisible(true); // frame
visible to true
}
}
output:
Java Using NetBean Write a program that can dynamically change the font of a message. The font name or font size can be chosen from combo boxes. The font name can be Dialog, DialogInput, Monospaced, S...
answer this question please, use java language Exercise 5: StyleOption program a) Modify the "StyleOption" program, in your lecture slides, to allow the user to specify the font name and size. Use combo boxes to obtain the font name and size (at least add four font name and 10 sizes) Style Options Say it with style! ]Bold Italic Make A Selection.... 26 b) Modify your solution in part 'a' such that it uses a slider to obtain the font size....
1. Create a Java application that will change the appearance of a string as shown in the picture. 2. The program will include a panel, label, checkboxes, radio buttons, and list. 3. To change color, set up 4 radio buttons in a button group. The colors are Black, Red, Green, and Blue to be selected. The default color is Black. 4. To change the font size, set up a list. The sizes are 18, 26, 38, and 56 to be...
Java Programing. Using NetBean Write a program to draw a line connecting two circles. These two circles can be dragged by mouse. And when circles are dragged, the line should be adjusted so that it still connect these two circles (binding property)
For Java, can someone help me understand what the questions were asking for? Consider the following Java declarations: JComboBox cb = new JComboBox(); JButton b = new JButton ("Press"); JCheckBox cb = new JCheckBox("Honors"); JTextField tf = new JTextField(10); Font f1 = new Font ("Serif", Font. BOLD, 12); Write a single, complete, syntactically correct Java statement in the form of a method invocation) that will perform each of the following tasks: a. Change the label on the JButton to "Submit"....
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...
Write a Java program to do the following with your name. This can all be done in the main() method. 1. Create a String variable called myName and assign your personal name to it. Use proper capitalization for a legal name. I.e. String myName = "Billy Bob"; 2. Load myName with the upper case version of itself and display the result. 3. Load myName with the lower case version of itself and display the result. 4. Capitalize the first letter...
Write a Java program to work with a generic list ADT using a fixed size array, not ArrayList. Create the interface ListInterface with the following methods a) add(newEntry): Adds a new entry to the end of the list. b) add(newPosition, newEntry): Adds a new entry to the list at a given position. c) remove(givenPosition): Removes the entry at a given position from the list. d) clear( ): Removes all entries from the list . e) replace(givenPosition, newEntry): Replaces the entry...
Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...
Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...
You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities: a Show all records r Remove the current record f Change the first name in the current record l Change the last name in the current record n Add a new record d ...