Introduction This part of your main assignment should be done individually. This assignment consists of writing a program and demonstrating it or submitting it on Moodle. NOTE: while you can do this...

1 answer below »



Introduction








This part of your main assignment should be done individually. This assignment consists of writing a program and demonstrating it or submitting it on Moodle.






NOTE: while you can do this using drag and drop in eclipse or some other java development environment you should be warned that;  I will put coding questions in the exam that assume you wrote this swing form yourself manually coding the listeners and attaching them to buttons. You are unlikely to learn how to do this if you use drag and drop GUI builders.







GENERAL INSTRUCTIONS






Write a simple swing form that has the following features and looks (more or less) like the following:









It has three buttons, each of which does one thing; Add, Subtract, Concatenate.






Here are examples of each function






Add









Subtract




Introduction This part of your main assignment should be done individually. This assignment consists of writing a program and demonstrating it or submitting it on Moodle. NOTE: while you can do this using drag and drop in eclipse or some other java development environment you should be warned that; I will put coding questions in the exam that assume you wrote this swing form yourself manually coding the listeners and attaching them to buttons. You are unlikely to learn how to do this if you use drag and drop GUI builders. GENERAL INSTRUCTIONS Write a simple swing form that has the following features and looks (more or less) like the following: It has three buttons, each of which does one thing; Add, Subtract, Concatenate. Here are examples of each function Add Subtract Concatenate (example 1) Concatenate (example 2) Marking Rubric No Submission Zero Marks Form Displays with no features working 2 Marks Add button works 4 Marks Add and Subtract buttons work 5 Marks Add, Subtract and Concatenate buttons work 6 Marks You Tutor can mark it quickly and on the spot with a simple demonstration or you can submit it to Moodle with the code and a cover sheet and screenshots of all 3 functions (as in my example above, show two different examples of concatenate): It’s fairly Straightforward to code if you have done the Swing Tutorial 1 Hints : 1. First define the GUI class which extends Jframe 1. Set the frame size 1. Set it to visible 1. Add the 3 or 4 JLabels (I used a JLabel for ===== which is optional) 1. Test it 1. Add the 2 JTextField (input boxes) 1. Test it 1. Add the 3 buttons 1. Test it 1. Write 1 listener class for Add 1. Connect the listener to the button 1. Test it 1. Write 2 more listener classes for Subtract and Concatenate 1. Connect the listener to the button 1. Test it 1. Drink Vanilla coke (optional step) 1. Fix formatting of the output 1. Add a title to jframe 1. Tidy it up 1. Test it 1. Show your tutor (get 6 easy marks) Below are some useful code fragments: // ******************************************************* getContentPane().setLayout(null); setTitle("Assignment PartA"); // ******************************************************* String text = text1.getText(); try { val1 = Double.parseDouble(text); } catch (NumberFormatException e) { val1=0; rc=false; JOptionPane.showMessageDialog(null, "Enter a valid double precision number please", "< first="" number="" error="">>", JOptionPane.ERROR_MESSAGE); } // ******************************************************* public class bAddAction implements ActionListener { public void actionPerformed (ActionEvent event) { ///// ----------------- ////// Lines deleted here that parsed the JTextFields into val1 and val2 ///// ----------------- if (rc) {displayText4.setText(String.format("%12.4f",(val1 + val2)));} else {displayText4.setText("0");} } } // ******************************************************* int posX =260; JButton buttonAdd = new JButton("Add"); buttonAdd.setLocation(posX,30); buttonAdd.setSize(110,20); buttonAdd.addActionListener(new bAddAction()); getContentPane().add(buttonAdd); // *******************************************************
Answered Same DayOct 29, 2019

Answer To: Introduction This part of your main assignment should be done individually. This assignment consists...

David answered on Nov 30 2019
133 Votes
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
im
port javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Form extends JFrame implements ActionListener {
    JFrame frame;
    JLabel firstNumberLabel, secondNumberLabel, resultLine, resultLabel;
    JTextField inputFieldOne, inputFieldTwo;
    Font ft;
    JButton addButton, subtractButton, concatenateButton;
    Form() {
        // initialize frame and set its properties
        frame = new JFrame("Assignment PartA");
        frame.setLayout(null);
        frame.setSize(500, 300);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // initialize elements
        addButton = new JButton("Add");
        subtractButton = new JButton("Subtract");
        concatenateButton = new JButton("Concatenate");
        ft = new Font("Courier New", Font.BOLD, 18);
        firstNumberLabel = new JLabel("First...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here