Question

In: Computer Science

In Java Write a GUI that will let the user sample borders. Include a menu named...

In Java

Write a GUI that will let the user sample borders. Include a menu named Borders that offers three options—beveled border, etched border, and line border—as submenus with the following options:

• Beveled-border submenu options: raised or lowered.

• Etched-border submenu options: raised or lowered.

• Line-border submenu options: small, medium, or large. Each of these options should be a submenu with three color options: black, red, and blue. Put the borders around a label containing text that describes the border, such as Raised Border, Lowered Etched Border, and so forth. Fix the highlight and shadow colors for the etched-border options to whatever colors you like, and make the small line border 5 pixels wide, the medium one 10 pixels wide, and the large one 20 pixels wide.

Solutions

Expert Solution

import java.awt.Color;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
public class swingLine extends javax.swing.JFrame {

  
public swingLine() {
initComponents();
}


@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenuBorder = new javax.swing.JMenu();
jMenuBeveled = new javax.swing.JMenu();
jMenuItemBRaised = new javax.swing.JMenuItem();
jMenuItemBLowered = new javax.swing.JMenuItem();
jMenuEtched = new javax.swing.JMenu();
jMenuItemeRaised = new javax.swing.JMenuItem();
jMenuItemELowered = new javax.swing.JMenuItem();
jMenuLine = new javax.swing.JMenu();
jMenuSmall = new javax.swing.JMenu();
jMenuItemLSB = new javax.swing.JMenuItem();
jMenuItemLSR = new javax.swing.JMenuItem();
jMenuItemLSBLU = new javax.swing.JMenuItem();
jMenuMedium = new javax.swing.JMenu();
jMenuItemLMB = new javax.swing.JMenuItem();
jMenuItemLMR = new javax.swing.JMenuItem();
jMenuItemLMBLU = new javax.swing.JMenuItem();
jMenuLarge = new javax.swing.JMenu();
jMenuItemLLB = new javax.swing.JMenuItem();
jMenuItemLLR = new javax.swing.JMenuItem();
jMenuItemLLBLU = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Hello");

jMenuBorder.setText("Border");

jMenuBeveled.setText("Beveled-Border");

jMenuItemBRaised.setText("Raised");
jMenuItemBRaised.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemBRaisedActionPerformed(evt);
}
});
jMenuBeveled.add(jMenuItemBRaised);

jMenuItemBLowered.setText("Lowered");
jMenuItemBLowered.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemBLoweredActionPerformed(evt);
}
});
jMenuBeveled.add(jMenuItemBLowered);

jMenuBorder.add(jMenuBeveled);

jMenuEtched.setText("Etched-Border");

jMenuItemeRaised.setText("Raised");
jMenuItemeRaised.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemeRaisedActionPerformed(evt);
}
});
jMenuEtched.add(jMenuItemeRaised);

jMenuItemELowered.setText("Lowered");
jMenuItemELowered.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemELoweredActionPerformed(evt);
}
});
jMenuEtched.add(jMenuItemELowered);

jMenuBorder.add(jMenuEtched);

jMenuLine.setText("Line-border");

jMenuSmall.setText("Small");

jMenuItemLSB.setText("Black");
jMenuItemLSB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLSBActionPerformed(evt);
}
});
jMenuSmall.add(jMenuItemLSB);

jMenuItemLSR.setText("Red");
jMenuItemLSR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLSRActionPerformed(evt);
}
});
jMenuSmall.add(jMenuItemLSR);

jMenuItemLSBLU.setText("Blue");
jMenuItemLSBLU.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLSBLUActionPerformed(evt);
}
});
jMenuSmall.add(jMenuItemLSBLU);

jMenuLine.add(jMenuSmall);

jMenuMedium.setText("Medium");

jMenuItemLMB.setText("Black");
jMenuItemLMB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLMBActionPerformed(evt);
}
});
jMenuMedium.add(jMenuItemLMB);

jMenuItemLMR.setText("Red");
jMenuItemLMR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLMRActionPerformed(evt);
}
});
jMenuMedium.add(jMenuItemLMR);

jMenuItemLMBLU.setText("Blue");
jMenuItemLMBLU.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLMBLUActionPerformed(evt);
}
});
jMenuMedium.add(jMenuItemLMBLU);

jMenuLine.add(jMenuMedium);

jMenuLarge.setText("Large");

jMenuItemLLB.setText("Black");
jMenuItemLLB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLLBActionPerformed(evt);
}
});
jMenuLarge.add(jMenuItemLLB);

jMenuItemLLR.setText("Red");
jMenuItemLLR.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLLRActionPerformed(evt);
}
});
jMenuLarge.add(jMenuItemLLR);

jMenuItemLLBLU.setText("Blue");
jMenuItemLLBLU.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemLLBLUActionPerformed(evt);
}
});
jMenuLarge.add(jMenuItemLLBLU);

jMenuLine.add(jMenuLarge);

jMenuBorder.add(jMenuLine);

jMenuBar1.add(jMenuBorder);
jMenuBorder.getAccessibleContext().setAccessibleName("menuBorder");

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(jLabel1)
.addContainerGap(238, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(112, 112, 112)
.addComponent(jLabel1)
.addContainerGap(153, Short.MAX_VALUE))
);

jLabel1.getAccessibleContext().setAccessibleName("lblName");

pack();
}// </editor-fold>

private void jMenuItemBRaisedActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
  
jLabel1.setBorder(BorderFactory.createRaisedBevelBorder());
}

private void jMenuItemBLoweredActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLoweredBevelBorder());
}   

private void jMenuItemeRaisedActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
}

private void jMenuItemELoweredActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
}   

private void jMenuItemLSBActionPerformed(java.awt.event.ActionEvent evt) {   
jLabel1.setBorder(BorderFactory.createLineBorder(Color.black,2)); // TODO add your handling code here:
}

private void jMenuItemLSRActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.RED,2));
}

private void jMenuItemLSBLUActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.blue,2));
}

private void jMenuItemLMBActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.black,4));
}

private void jMenuItemLMRActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.red,4));
}

private void jMenuItemLMBLUActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.blue,4));
}

private void jMenuItemLLBActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.black,6));
}

private void jMenuItemLLRActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.red,6));
}

private void jMenuItemLLBLUActionPerformed(java.awt.event.ActionEvent evt) {   
// TODO add your handling code here:
jLabel1.setBorder(BorderFactory.createLineBorder(Color.blue,6));
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
  
new swingLine().setVisible(true);
}
});
}

//create the menu bar

// Variables declaration - do not modify   
private javax.swing.JLabel jLabel1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu jMenuBeveled;
private javax.swing.JMenu jMenuBorder;
private javax.swing.JMenu jMenuEtched;
private javax.swing.JMenuItem jMenuItemBLowered;
private javax.swing.JMenuItem jMenuItemBRaised;
private javax.swing.JMenuItem jMenuItemELowered;
private javax.swing.JMenuItem jMenuItemLLB;
private javax.swing.JMenuItem jMenuItemLLBLU;
private javax.swing.JMenuItem jMenuItemLLR;
private javax.swing.JMenuItem jMenuItemLMB;
private javax.swing.JMenuItem jMenuItemLMBLU;
private javax.swing.JMenuItem jMenuItemLMR;
private javax.swing.JMenuItem jMenuItemLSB;
private javax.swing.JMenuItem jMenuItemLSBLU;
private javax.swing.JMenuItem jMenuItemLSR;
private javax.swing.JMenuItem jMenuItemeRaised;
private javax.swing.JMenu jMenuLarge;
private javax.swing.JMenu jMenuLine;
private javax.swing.JMenu jMenuMedium;
private javax.swing.JMenu jMenuSmall;
// End of variables declaration   
}


Related Solutions

in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that...
JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
JAVA: Write a program to perform time conversion. The user will select from the following menu:...
JAVA: Write a program to perform time conversion. The user will select from the following menu: Hours to minutes Days to hours Minutes to hours Hours to days. Each choice has a separate method which is called when the user makes the selection. Please see the output below: Hours to minutes. 2. Days to hours. 3. Minutes to hours. 4. Hours to days. Enter your choice: 2 Enter the number of days: 5 There are 120 hours in 5 days.
Write a java program that presents the user with the following menu Linear Search Binary Search...
Write a java program that presents the user with the following menu Linear Search Binary Search The user can choose any of these operations using numbers 1 or 2. Once selected, the operation asks the user for an input file to be searched (the file is provided to you and is named input.txt). If option 1 or 2 is selected, it asks the user for the search string. This is the string that the user wants the program to search...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
write a java program for a restaurant menu. including price , add taxes and include tip
write a java program for a restaurant menu. including price , add taxes and include tip
Java Math Tutor: Write a program that displays a menu as shown in the sample run....
Java Math Tutor: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1...
​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT