Question: Hello, Can you help me write this in JAVA based on the given code below? Develop a GUI testing tool to test the given class

Hello,

Can you help me write this in JAVA based on the given code below?

Develop a GUI testing tool to test the given class MyGUI in the GUI.jar file. The class MyGUI is in the package named gui. By running the MyGUI main method, a frame will show up with three JTextFields and one JButton. Your GUI testing tool will let you to click on each GUI component once to identify their existence for later testing purpose.

The testing process begins by reading two numbers and the expected sum from each line of file input.txt and putting them into the two upper text fields. The tool then presses the button automatically. The buttons action will sum up the two numbers and show the result in the bottom text field. This process will continue until reaching the EOF. Show the compared boolean results in the standard output between the actual outputs and the expected outputs to detect any anomalies.

(Hint: Take advantage of the Toolkit class and the addAWTEventListener method. Threading program may be necessary to correctly show the values in the text fields.).

import java.awt.AWTEvent; import java.awt.Toolkit; import java.awt.event.AWTEventListener; import java.awt.event.MouseEvent; import java.util.ArrayList; import javax.swing.JTextField;

/** * * @author wxw18 */ public class GUITest {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Toolkit tk = Toolkit.getDefaultToolkit(); AWTEventListener listener = new AWTEventListener() { ArrayList al = new ArrayList<>();

@Override public void eventDispatched(AWTEvent event) { if (al.size() < 3) { if (event.getID() == MouseEvent.MOUSE_PRESSED) { al.add(event); } if (al.size() == 3) { JTextField jtf1 = (JTextField) al.get(0).getSource(); JTextField jtf2 = (JTextField) al.get(1).getSource(); JTextField jtf3 = (JTextField) al.get(2).getSource(); jtf1.setText("100"); jtf2.setText("200"); jtf3.setText("300"); } } } };

tk.addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK); NewJFrame njf = new NewJFrame();

njf.setSize(400, 250); njf.setVisible(true); } }

public class NewJFrame extends javax.swing.JFrame {

/** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); }

/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() {

jButton1 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel();

jButton1.setText("jButton1");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Value 1:");

jLabel2.setText("Value 2:");

jLabel3.setText("Sum:");

jLabel4.setText("+");

jLabel5.setText("=");

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(31, 31, 31) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jLabel4) .addGap(180, 180, 180)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jLabel5) .addGap(182, 182, 182)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(38, 38, 38) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel4) .addGap(7, 7, 7) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addGap(14, 14, 14) .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addContainerGap(34, Short.MAX_VALUE)) );

pack(); }// //GEN-END:initComponents

// Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; // End of variables declaration//GEN-END:variables }

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!