Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help and make my program display input in another frame when i click the

ID: 3648717 • Letter: P

Question

please help and make my program display input in another frame when i click the button. i am stack please just improve this one below.

package Ivan;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt. BorderLayout;


public class Ivan extends JFrame {

private JTextField jtfresult = new JTextField(10);

// declare and create output button
private JButton jbtresult = new JButton(" Click ");

public Ivan(){

// set gridlayout, 4 rows, 2 columns and space between components
// horizonatally and vertically.
setLayout(new GridLayout(4, 2, 5, 5));

//add labels and text fields to the frame

add(new JLabel("First Name :"));
add(new JTextField(8));
add(new JLabel("Age :"));
add(new JTextField(4));
add(new JLabel("Last Name :"));
add(new JTextField(8));

add(new JButton("Click"), BorderLayout.SOUTH);


jtfresult.setEditable(false);
jtfresult.setHorizontalAlignment(JTextField.RIGHT);



}

/**
* @param args
* main method
*/
public static void main(String[] args) {
Ivan frame = new Ivan();
frame.setTitle("Ivan's Application");
frame.setSize(300, 150);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}

}

Explanation / Answer

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Exercise16_4 extends JFrame{ // FlowLayout components of top portion of calculator private JLabel jlbNum1 = new JLabel("Number 1"); private JTextField jtfNum1 = new JTextField(4); private JLabel jlNum2 = new JLabel("Number 2"); private JTextField jtfNum2 = new JTextField(4); private JLabel jlbResult = new JLabel("Result"); private JTextField jtfResult = new JTextField(8); // FlowLayout Components of bottom portion of calculator private JButton jbtAdd = new JButton("Add"); private JButton jbtSubtract = new JButton("Subtract"); private JButton jbtMultiply = new JButton("Multiply"); private JButton jbtDivide = new JButton("Divide"); public Exercise16_4(){ JPanel panel1 = new JPanel(); panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3)); panel1.add(jlbNum1); panel1.add(jtfNum1); panel1.add(jlNum2); panel1.add(jtfNum2); panel1.add(jlbResult); panel1.add(jtfResult); JPanel panel2 = new JPanel(); panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 10)); panel1.add(jbtAdd); panel1.add(jbtSubtract); panel1.add(jbtMultiply); panel1.add(jbtDivide); add(panel1, BorderLayout.NORTH); add(panel2, BorderLayout.CENTER); } public static void main(String[] args){ Exercise16_4 frame = new Exercise16_4(); frame.setTitle("Caculator"); frame.setSize(400, 200); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setResizable(false); frame.setVisible(true); } }