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

how I can create GUI in jave : product application• The application has a produc

ID: 3605310 • Letter: H

Question

how I can create GUI in jave :

product application•

The application has a product class and tow windows: Main, Add product.

The Main window:

Has a component for showing product info and three buttons: Add, Look Up, and Display.

also Text Field to search phrase from the user.

- When the user clicks the Look-Up button the Edit Student Info window pops up with the info of the first product ( name contains the search phrase). The user can then edit the information .

The user can view the ID, expiration, date of production, and category of all product by clicking on Display button.

Add button, the Add product window pops up. •

in product window: The user can enter all required student info (ID, Name, expiration, date of production, category).

in this window also there is two Add and Cancel buttons.

Explanation / Answer

import java.awt.*;        // Using AWT container and component classes

import java.awt.event.*; // Using AWT event classes and listener interfaces

// An AWT program inherits from the top-level container java.awt.Frame

public class AWTCounter extends Frame implements ActionListener {

   private Label lblCount;    // Declare a Label component

   private TextField tfCount; // Declare a TextField component

   private Button btnCount;   // Declare a Button component

   private int count = 0;     // Counter's value

   // Constructor to setup GUI components and event handlers

   public AWTCounter () {

      setLayout(new FlowLayout());

         // "super" Frame, which is a Container, sets its layout to FlowLayout to arrange

         // the components from left-to-right, and flow to next row from top-to-bottom.

      lblCount = new Label("Counter"); // construct the Label component

      add(lblCount);                    // "super" Frame container adds Label component

      tfCount = new TextField("0", 10); // construct the TextField component

      tfCount.setEditable(false);       // set to read-only

      add(tfCount);                     // "super" Frame container adds TextField component

      btnCount = new Button("Count");   // construct the Button component

      add(btnCount);                    // "super" Frame container adds Button component

      btnCount.addActionListener(this);

         // "btnCount" is the source object that fires an ActionEvent when clicked.

         // The source add "this" instance as an ActionEvent listener, which provides

         //   an ActionEvent handler called actionPerformed().

         // Clicking "btnCount" invokes actionPerformed().

      setTitle("AWT Counter"); // "super" Frame sets its title

      setSize(250, 100);        // "super" Frame sets its initial window size

      // For inspecting the Container/Components objects

      // System.out.println(this);

      // System.out.println(lblCount);

      // System.out.println(tfCount);

      // System.out.println(btnCount);

      setVisible(true);         // "super" Frame shows

      // System.out.println(this);

      // System.out.println(lblCount);

      // System.out.println(tfCount);

      // System.out.println(btnCount);

   }

   // The entry main() method

   public static void main(String[] args) {

      // Invoke the constructor to setup the GUI, by allocating an instance

      AWTCounter app = new AWTCounter();

         // or simply "new AWTCounter();" for an anonymous instance

   }

   // ActionEvent handler - Called back upon button-click.

   @Override

   public void actionPerformed(ActionEvent evt) {

      ++count; // Increase the counter value

      // Display the counter value on the TextField tfCount

      tfCount.setText(count + ""); // Convert int to String

   }

}