java: implement stack in gui (JFrame, Applet)

Опубликовано: 21 Январь 2025
на канале: CODE ZERO
2,874
70

#java #stack #gui #stack_in_gui #netbeans//

we'll be creating a stack in graphical user interface or you may say stack using gui.
we will implement some core functionalities of the stack gui which may include pop , push and reset. the code for stack class is provided below which you have to copy inside the project as shown in tutorial. stack gui using netbeans and java will work as normall.
gui Stack : It is Last-In-First-Out (LIFO) DS
The name "stack" for this type of structure comes from the analogy to a set of physical items stacked on top of each other, which makes it easy to take an item off the top of the stack,
while getting to an item deeper in the stack may require taking off multiple other items first
We can perform 2 operation on it :
PUSH : which adds an element to the collection, and
POP : which removes the most recently added element that was not yet removed
STACK CODE:

class Stack
{

int top=-1;
int size=0;
int[] arr;

public Stack(int size)
{
arr= new int[size];
this.size=size;
}
public void push (int value)
{
arr[++top] = value;
}
public int pop()
{
return arr[top--];
}
public int peek()
{
return arr[top];
}
public void reset()
{
top=-1;
}

}