Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is A decimal to/from binary number converter problem. This is a pretty beginner class so we havent discussed any major topics. We are

This program is A decimal to/from binary number converter problem. This is a pretty beginner class so we havent discussed any major topics. We are using abstract methods and exception handling to deal with this problem/ arrays and other basic java topics binary object files.I will include an example as reference to how much we have used. Essentially this is an excersie A decimal to/from binary number converter, please include srcshot of output.

The first step in this project is to decide which types of components youll need and the design layout of those components in your window.

Decide how your program will work:

Your screen should have two text areas, one which will contain a decimal number and the other which will contain a binary string of digits.

Option A: One possible configuration is to use two buttons: one to convert a decimal number to binary and another to convert a binary string of digits to a decimal number

Option B: Another second option is to use a single button which converts the contents of whichever text area has something in it to the other text area (presumably empty).

Option C: A third option might be to use no buttons at all. Instead, convert the contents of whichever text area is active when the user enters a number and presses the Enter key. (The scope of this option is probably beyond what weve learned up to this point, but you can give it a try, if you wish.)

Next, design the look of translators screen:

Determine the layout of your screen (frame). It should contain:

A title for the window frame in the top left corner

A title for your main screen (in the top center of the content pane)

Labels for the text areas

Button or buttons to convert the contents of one text area from or to binary

A third button to close the window

Once you have your screen layout figured out, determine the panels and their layout managers which will best handle your application.

The next step might be to create each component and place it on a JFrame.

Create your class with the appropriate type of frame, then instantiate the class in main

Make the frame visible

Set the window frames title to include your name plus Converter

Set the background color of the frame to a soft, pleasing color

Create all necessary panels and layouts

Create and add a title for your main screen

Create and add the two text areas and their labels

Create one button for each text area (Option A) or just a single button (Option B)

Create a third button to close the screen

Determine the look-and-field of each component (color, size, and content)

Modify the layout so that it is pleasing to the eye and intuitive to use.

Now you have a pleasant-looking screen which is completely non-functional. Add the functionality to each component on the screen

Add listeners to the button (or buttons).

When the user enters a decimal number in the text box for decimal numbers and the user presses the button to convert from decimal to binary, place the binary equivalent in the other text box. Use the Integer.toBinaryString(n) method to convert from a decimal number (in n) to a binary string,

If the user enters an invalid number, then place a message in the box for binary numbers which indicates there is an error

When the user enters a binary number in the text box for binary digits and the user presses the button to convert from binary to decimal, place the decimal equivalent in the other text box. Use the Integer.parseInt(s, 2) method to convert a binary string (in s) to a decimal number

If the user enters an invalid binary number, then place a message in the box for decimal numbers which indicates there is an error

When the user clicks on the button to close the application, the program stops

Submit listings for class(es) in your project. Test your program with at least 3 different numbers converted either to or from decimal, and PrintScreen the results.

EXAMPLE OF CODE NOT PART OF THE QUESTION FOR CONTEXT

/* TextProcessing.java - Demonstrate JTextField and JTextArea components * Author: Chris Merrill * Topic: Topic 13 * Project: Demonstration * Problem Statement: Create a JTextField and JTextArea on a JFrame. Enter * some text in both areas, and retrieve the data * * Discussion: * * How to size a JTextField and JTextArea component * * Setting the vertical and horizontal alignment of a panel (the text panels) * * Changing the font size (more next week) * * Text field does not accept new-line. Text area does. * * Line wrap doesn't break on word boundaries. */ import java.awt.BorderLayout ; import java.awt.GridLayout ; import java.awt.event.ActionListener ; import java.awt.event.ActionEvent ; import java.awt.event.WindowAdapter ; import java.awt.event.WindowEvent ; import java.awt.Color ; import java.awt.Dimension ; import java.awt.Font ; import javax.swing.JFrame ; import javax.swing.JPanel ; import javax.swing.JButton ; import javax.swing.JTextField ; import javax.swing.JTextArea ; import javax.swing.JLabel ; public class TextProcessing extends JFrame implements ActionListener { // Constants private static final String TITLE = "Text Component Demo" ; private static final int FRAME_WIDTH = 800, FRAME_HEIGHT = 300 ; private static final String DEFAULT_FIELD_TEXT = "This is the text field." ; private static final String DEFAULT_AREA_TEXT = "This is the text area." ; private static final String PROCESS_BUTTON_TEXT = "Send text to program" ; private static final String CLOSE_BUTTON_TEXT = "Close" ; // Create the buttons to process the text area and to close the window JButton processButton ; JButton closeButton ; // Define text areas JTextField textField ; JTextArea textArea ; // Constructor does all of the work public TextProcessing() { // Settings for the JFrame setTitle(TITLE) ; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; setResizable(true) ; setSize(FRAME_WIDTH, FRAME_HEIGHT) ; setLocationRelativeTo(null) ; BorderLayout layout = new BorderLayout(0, 0) ; setLayout(layout) ; JPanel center = new JPanel() ; GridLayout grid = new GridLayout(3, 2) ; center.setLayout(grid) ; add(center, BorderLayout.CENTER) ; // Create borders around the frame JPanel borderNorth = new JPanel() ; borderNorth.setBackground(Color.BLUE) ; JPanel borderSouth = new JPanel() ; borderSouth.setBackground(Color.BLUE) ; JPanel borderEast = new JPanel() ; borderEast.setBackground(Color.BLUE) ; JPanel borderWest = new JPanel() ; borderWest.setBackground(Color.BLUE) ; // add(borderEast, BorderLayout.EAST) ; add(borderWest, BorderLayout.WEST) ; add(borderNorth, BorderLayout.NORTH) ; add(borderSouth, BorderLayout.SOUTH) ; // Create labels for the text components. Center in their respective // grid areas. // // Use a larger font for the labels JLabel textFieldLabel = new JLabel("Text Field") ; textFieldLabel.setVerticalAlignment(JLabel.BOTTOM) ; textFieldLabel.setHorizontalAlignment(JLabel.CENTER) ; textFieldLabel.setFont( new Font(textFieldLabel.getFont().getName(), Font.PLAIN, 25)) ; JLabel textAreaLabel = new JLabel("Text Area") ; textAreaLabel.setVerticalAlignment(JLabel.BOTTOM) ; textAreaLabel.setHorizontalAlignment(JLabel.CENTER) ; textAreaLabel.setFont( new Font(textAreaLabel.getFont().getName(), Font.PLAIN, 18)) ; // Create Panels for the text areas to control sizing issues JPanel fieldPanel = new JPanel() ; JPanel areaPanel = new JPanel() ; // Create the text components and add to their panels textField = new JTextField(DEFAULT_FIELD_TEXT, 30) ; fieldPanel.add(textField) ; textArea = new JTextArea(DEFAULT_AREA_TEXT, 5, 30) ; textArea.setLineWrap(true) ; areaPanel.add(textArea) ; // Add labels and text components to the center grid center.add(textFieldLabel) ; center.add(textAreaLabel) ; center.add(fieldPanel) ; center.add(areaPanel) ; // Create a button that will cause the program to read and print the // contents of the two text components on the console. Add the // listener. JPanel processPanel = new JPanel() ; processButton = new JButton(PROCESS_BUTTON_TEXT) ; processButton.setActionCommand("process") ; processButton.addActionListener(this) ; processPanel.add(processButton) ; center.add(processPanel) ; // Create a button that will exit the program. Add the // listener, and add the button to the center panel JPanel closePanel = new JPanel() ; closeButton = new JButton(CLOSE_BUTTON_TEXT) ; closeButton.setActionCommand("stop") ; closeButton.addActionListener(this) ; closePanel.add(closeButton) ; center.add(closePanel) ; } // Depending on which button was entered, either show the contents of the // two text areas, or close the program public void actionPerformed( ActionEvent e ) { if (e.getSource() == closeButton) { System.exit(0) ; } System.out.println("Text field: " + textField.getText()) ; System.out.println("Text area: " + textArea.getText()) ; } // main() just creates the frame and makes it visible public static void main( String[] args) { TextProcessing frame = new TextProcessing() ; frame.setVisible(true) ; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

2. Develop a persuasive topic and thesis

Answered: 1 week ago

Question

1. Define the goals of persuasive speaking

Answered: 1 week ago