How do I make the submit, modify, and delete buttons work? I did the layout but need
Question:
How do I make the submit, modify, and delete buttons work? I did the layout but need help in making action events.
I also need help in making this GUI app using random access file. How do I do that?
Here's the classes I've created:
--Main Class
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ProductManager pro = new ProductManager();
pro.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pro.setSize(400, 400);
pro.setVisible(true);
}
}
--------------
-- Product Class
public class Product {
//declared instance variables for product class
private static int count = 0;
int productId;
String productName;
double productPrice;
private boolean isFilled;
//declared constructors
public Product(int productId, String productName, double productPrice) {
this.productId = productId;
this.productName = productName;
this.productPrice = productPrice;
// setProductId(++count);
}
public Product() {
this.productId = 0;
}
//getter for product ID
public int getProductId() {
return productId;
}
//getter for product name
public String getProductName() {
return productName;
}
//getter for product price
public double getProductPrice() {
return productPrice;
}
}
--------------------
--ProductManager Class
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.Writer;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ProductManager extends JFrame {
//declare variables as JLabel
private JLabel productIdLabel;
private JLabel productNameLabel;
private JLabel productPriceLabel;
//declare variables as JTextfield
JTextField productIdField;
JTextField productNameField;
JTextField productPriceField;
//label for frame title
private JLabel frameTitle;
//JButtons for submit and search
private JButton submit;
private JButton modify;
private JButton delete;
//text area
// private JTextArea productManagerArea;
protected JTextArea area;
//constructor to initialize the components
public ProductManager() {
setTitle("Product Manager");
setLayout(null);
//initialize ID label
productIdLabel = new JLabel("Product ID: ");
productIdLabel.setBounds(20, 50, 100, 30);
this.add(productIdLabel);
//initialize Name label
productNameLabel = new JLabel("Product Name: ");
productNameLabel.setBounds(20, 100, 100,30);
this.add(productNameLabel);
//initialize Price label
productPriceLabel = new JLabel("Product Price: ");
productPriceLabel.setBounds(20, 150, 100, 30);
this.add(productPriceLabel);
//initialize ID field
productIdField = new JTextField("");
productIdField.setBounds(150, 50, 150,30);
this.add(productIdField);
//initialize Name field
productNameField = new JTextField("");
productNameField.setBounds(150, 100, 150,30);
this.add(productNameField);
//initialize Price field
productPriceField = new JTextField("");
productPriceField.setBounds(150, 150, 150,30);
this.add(productPriceField);
//initialize buttons for submit, modify, deleter
submit = new JButton("Submit");
submit.setBounds(20, 250, 100, 30);
this.add(submit);
modify = new JButton("Modify");
modify.setBounds(145, 250, 100, 30);
this.add(modify);
delete = new JButton("Delete");
delete.setBounds(270, 250, 100, 30);
this.add(delete);
Auditing Cases An Interactive Learning Approach
ISBN: 978-0132423502
4th Edition
Authors: Steven M Glover, Douglas F Prawitt