Question: Modify this code to you create a menu and choose the color. The color selected by the user changes the digit to that color. In

Modify this code to you create a menu and choose the color. The color selected by the user changes the digit to that color. In the first exercise the color was black. In this exercise the sdigit must load with darkGray color.

here is the code

import javax.swing.*; import java.applet.Applet; import java.awt.*; import java.awt.event.ActionEvent;

public class NewApplet extends Applet {

Label lCommand; TextField tNumber; Panel pDetails; Button cancel; Button ok;

@Override public void init() {

// initialize components lCommand = new Label("Enter a digit"); tNumber = new TextField(9); ok = new Button("OK"); cancel = new Button("cancel");

ok.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { //Create the frame. JFrame frame = new JFrame("Applet"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create components and put them in the frame. //...create emptyLabel... Label number = null; try { number = new Label(tNumber.getText()); } catch (Exception ex) { number = new Label("0"); } // create custom font Font myFont = new Font("Serif", Font.BOLD, 80); number.setFont(myFont);

frame.getContentPane().add(number, BorderLayout.CENTER);

//4. Size the frame. frame.pack();

//5. Show it. frame.setVisible(true); } });

cancel.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } });

pDetails = new Panel();

// add the components to panel pDetails.add(lCommand); pDetails.add(tNumber); pDetails.add(ok); pDetails.add(cancel); pDetails.setSize(100, 100); pDetails.validate(); add(pDetails); } }

the output should look like this:

Modify this code to you create a menu and choose the color.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!