create an edit menu in your gui add a second menu to the gui called edit which will 5150686
Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Insert. Clicking on insert should prompt the user using a JOptionPane input dialog to enter a new date in the same format as is read from the input file. The new date, if valid, should be displayed in the unsorted and sorted text areas of the GUI. If the date is invalid it should be printed to the console. You will need to write a second menu handler called EditMenuHandler.
Name the Main Project4
this is my previous code:
Candle.java
//declare class which implements
//comparable interface
public class Candle
{
int height;
int width;
float price;
boolean islit;
//Default constructor
public Candle()
{
this.height=0;
this.width=0;
this.price=0.0f;
}
//getter and setter method for Islit
public boolean isIslit()
{
return islit;
}
public void setIslit(boolean islit)
{
this.islit = islit;
}
//getter and setter method for height
public int getHeight()
{
return height;
}
public void setHeight(int height) {
this.height = height;
}
//getter and setter method for width
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
//getter and setter method for price
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
//paremetrized construtor
public Candle(int height, int width,
float price)
{
super();
this.height = height;
this.width = width;
this.price = price;
this.islit = false;
}
//override methpd toString()
@Override
public String toString()
{
return height + “,” + width
+ “, ” + price+”,”+ islit;
}
}
CandleGUI.java
//Import required packages
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
//declare the class
public class CandleGUI extends JFrame
{
//Constructor which takes an array of Box objects as parameter
public CandleGUI(SortedCandleList sortedCandleList,
UnsortedCandleList unsortedCandleList)
{
setDefaultCloseOperation(EXIT_ON_CLOSE);
//using GridLayout with 1 row and 2 columns, with 10 spaces gap between
//each cells horizontally and vertically
setLayout(new GridLayout(1, 2, 10, 10));
//Defining a Text area for displaying unsorted list
JTextArea left = new JTextArea();
// making it not editable (by user)
left.setEditable(false);
String candle = “UNSORTED LIST OF CANDLESnn”;
candle+=unsortedCandleList.toString();
//Setting text for unsorted list
left.setText(candle);
//Adding the text area
add(left);
//Defining a text area for displaying sorted list, and adding the
//details of each candles
JTextArea right = new JTextArea();
right.setEditable(false);
candle = “SORTED LIST OF CANDLESnn”;
candle+=sortedCandleList.toString();
right.setText(candle);
add(right);
setVisible(true);
//Adjust the length and width of the window
pack();
}
}
CandleList.java
//declare the abstract CandleList
public abstract class CandleList
{
//declare local variables
protected CandleNode head , last;
protected int size_of_list;
//define the default constructor
public CandleList()
{
head = last = new CandleNode(null);
size_of_list = 0;
}
//implement the method to test the linked list is empty
//or not
public boolean isEmpty()
{
if(size_of_list == 0)
{
return true;
}
else
{
return false;
}
}
//append date to the list
public void append(Candle date)
{
//append the date to the last node
last.next = new CandleNode(date);
//set the last node to last.next
last = last.next;
//increment the size of list
size_of_list++;
}
//implement the method toString
public String toString()
{
//define the current node
CandleNode curr = head.next;
String str = “”;
//Using while loop to repear the current node is null or not
while(curr != null)
{
//call the toString()
str += curr.candle.toString() + “n”;
//set current to current next
curr = curr.next;
}
//return the string
return str;
}
}
CandleNode.java
//Define the class BoxNode
public class CandleNode
{
//declare the local variable
protected Candle candle;
protected CandleNode next;
//define the Constructor
public CandleNode(Candle c)
{
candle = c;
next = null;
}
}
SortedCandleList.java
//define the class which extends the abstract class
public class SortedCandleList extends CandleList {
//Constructor
public SortedCandleList()
{
//call variables though super keyWord
super();
}
//implement the method add()
public void add(Candle candle)
{
//define the head for the previous and current nodes in the liked list
CandleNode prev = head,
curr = head.next;
//define the nodes
CandleNode node = new CandleNode(candle);
//Using while loop
while(curr != null && candle.getPrice() > curr.candle.getPrice())
{
//set previoud node as current node
prev = curr;
//set current node as next node
curr = curr.next;
}
//set node to next is current node
node.next = curr;
//previous to next is node
prev.next = node;
//If node to next value is null
if(node.next == null)
{
//set that is as last node
last = node;
//increment the node
size_of_list++;
}
}
}
UnsortedCandleList.java
//define the class UnsortedBoxList which extends the //CandleList
public class UnsortedCandleList extends CandleList {
//define the Constructor
public UnsortedCandleList()
{
//call the variables
super();
}
//implement the method add
public void add(Candle unsortedCandle)
{
//just append values to the text area
append(unsortedCandle);
}
}
Project2.java
//Import required classes
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
//Define the class name Project2
public class Project2
{
//main method
public static void main(String[] args)
{
//Defining sorted and unsorted Candle lists objects
SortedCandleList sortedCandleListObject = new SortedCandleList();
UnsortedCandleList unsortedCandleList = new UnsortedCandleList();
//define file object with the input text file
File file = new File(“candles.txt”);
//Read date in the file and save into the string array
try
{
//define the scanner object for that file
Scanner scanner = new Scanner(file);
//Read line by line in the file
while (scanner.hasNext())
{
//read the line
String line = scanner.nextLine();
System.out.println(line);
// splitting the line by ,
String candles[] = line.split(“,”);
//Store each file by height, width and price
int height = Integer.parseInt(candles[0].trim());
int width = Integer.parseInt(candles[1].trim());
float price = Float.parseFloat(candles[2].trim());
System.out.println(height +” t “+ width +”t”+ price);
//define the class Candle object
Candle candleObject = new Candle(height, width, price);
//Add Candle objects to the classes
sortedCandleListObject.add(candleObject);
unsortedCandleList.add(candleObject);
}
//call the Construtor with the objects
new CandleGUI(sortedCandleListObject, unsortedCandleList);
}
//If the input text file is not exits
//Display and error message
catch (FileNotFoundException e)
{
System.out.println(“File not found!”);
}
//If the input text file is invalid
catch (Exception e)
{
//print the message
System.out.println(“Invalid file format!”);
}
}
}