Question

JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The...

JAVA

Create a simple Graphical User Interface (GUI) in java with the following requirements:

 The interface components will appear centered in the interface, and in two rows.

o Row one will have a Label that reads “Please enter a valid integer:” and a Text Field to take in the integer from the user.

o Row two will have a Button that when pressed converts the integer to binary

 The conversion will be completed using recursion – A separate recursive method will use divide by 2 then mod 2 on each digit of the integer (See below)

 The program will use either a Lambda or anonymous class to implement the Event Handler.

 The program will use the @Override annotation where appropriate.

 The program will conform to the coding conventions discussed in class.

 The program will properly handle any checked Exceptions. This assignment is intended to get you to demonstrate knowledge of basic GUI design, basic Event handling, and Recursion. Example – The integer 50 produces the binary number 110010 as follows: 50/2 = 25, 50%2 = 0 25/2 = 12, 25%2 = 1 12/2 = 6, 12%2 = 0 6/2 = 3, 6%2 = 0 3/2 = 1, 3%2 = 1 1/2 = 0, 1%2 = 1 Construct backwards from mod answers, bottom up – 110010 Please submit the assignment to the Canvas drop box by Wednesday, December 4, 2018.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class DecToBinGUI {
  
private static JFrame mainFrame;
private static JPanel mainPanel, inpPanel, buttonPanel, resultPanel;
private static JLabel inpLabel, resultLabel;
private static JTextField decField;
private static JButton convertButton;
  
public static void main(String[] args)
{
mainFrame = new JFrame("Decimal To Binary Converter");
mainPanel = new JPanel(new GridLayout(3, 0));
  
inpPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
inpLabel = new JLabel("Please enter a valid integer: ");
decField = new JTextField(20);
inpPanel.add(inpLabel);
inpPanel.add(decField);
  
buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
convertButton = new JButton("Convert");
buttonPanel.add(convertButton);
  
resultPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
resultLabel = new JLabel("Result: ");
resultPanel.add(resultLabel);
  
mainPanel.add(inpPanel);
mainPanel.add(buttonPanel);
mainPanel.add(resultPanel);
  
mainFrame.add(mainPanel);
mainFrame.setSize(450, 180);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
  
// add action listener for the convert button
ConvertButtonListener listener = new ConvertButtonListener();
convertButton.addActionListener(listener);
}
  
static class ConvertButtonListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
if(decField.getText().equals(""))
JOptionPane.showMessageDialog(null, "Please enter a decimal number to convert!");
else
{
String decInp = decField.getText().trim();
int decimal = Integer.parseInt(decInp);
resultLabel.setText("Result: " + decToBin(decimal) + "");
}
}
  
private String decToBin(int dec)
{
if(dec == 0)
return "0";
String bin = "";
while(dec > 0)
{
int remainder = (dec % 2);
bin = remainder + bin;
dec /= 2;
}
return bin;
}
}
}

****************************************************************** SCREENSHOT *********************************************************

Add a comment
Know the answer?
Add Answer to:
JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • User interfaces are a critical part of any system. In this lesson, a Graphical User Interface...

    User interfaces are a critical part of any system. In this lesson, a Graphical User Interface (GUI) is created. The code generated will link the components to the action. Assignment: Create a Graphical User Interface that has two buttons and a textArea (See Examples 12.3 and Example 12.4). figure 1 Create a String array to store the following messages (Enter your name where it says YourName). "Congratulations YourName!nYou completed the Java class. nYou learned to write Java programs with commonly...

  • Using Dr Java Objective: Create a game of video poker with a graphical user interface (GUI)....

    Using Dr Java Objective: Create a game of video poker with a graphical user interface (GUI). The player should start with $100, and then the system deals out 5 playing cards. After the player sees the cards they are then asked to wager $10, $20, $50, or $100. Next the user picks which cards they wish to throw away, and then the system deals more cards in their place. Once this has concluded money are awarded by these criteria: Nothing...

  • REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter...

    REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter a credit card number. Display whether the number is valid and the type of credit cards (i.e., Visa, MasterCard, American Express, Discover, and etc). The requirements for this assignment are listed below: • Create a class (CreditNumberValidator) that contains these methods: // Return true if the card number is valid. Boolean isValid(String cardNumber); // Get result from Step 2. int sumOfDoubleEvenPlace(String cardNumber); // Return...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • VII JAVA ASSIGNMENT. Write a program with a graphical interface that allows the user to convert...

    VII JAVA ASSIGNMENT. Write a program with a graphical interface that allows the user to convert an amount of money between U.S. dollars (USD), euros (EUR), and British pounds (GBP). The user interface should have the following elements: a text box to enter the amount to be converted, two combo boxes to allow the user to select the currencies, a button to make the conversion, and a label to show the result. Display a warning if the user does not...

  • Exercise 1 1. Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the...

    Exercise 1 1. Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the Palette to drag and drop the Swing Containers and Controllers like the figure shown. Your Form should accept number in its text field as Month. When the user press GO Button, the corresponding Month Name has to be displayed in the Label, otherwise, the Label text has to indicate that the number entered is invalid Convert month number to month name: W Gom The...

  • Convert Project #1 into a GUI program, following the following requirements: Provide two text fields: one...

    Convert Project #1 into a GUI program, following the following requirements: Provide two text fields: one receives the length of the sequence, and the second receive the sequence (each number separated by a comma). There may, or may not, be space in between the comma and the number element. Provide a clear button that has an event listener attached to it. When pressed, the two text fields are emptied. The event listener should be defined and implemented as an anonymous...

  • JAVA Developing a graphical user interface in programming is paramount to being successful in the business...

    JAVA Developing a graphical user interface in programming is paramount to being successful in the business industry. This project incorporates GUI techniques with other tools that you have learned about in this class. Here is your assignment: You work for a flooring company. They have asked you to be a part of their team because they need a computer programmer, analyst, and designer to aid them in tracking customer orders. Your skills will be needed in creating a GUI program...

  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • with java programming language Create a swing application to get following gui screen. All gui elements...

    with java programming language Create a swing application to get following gui screen. All gui elements in the JFrame are JButton. You are expected to write proper event handler so that: • When the JButton with text "O" is pressed value of the button increased by 1. • When the JButton with text "a" is pressed the text will be replaced with the next ascii character. i.e it will be 'b' on first press, than 'c'on next press, so on....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT