0% found this document useful (0 votes)
3 views6 pages

Java Queue Implementation GUI

The document contains Java code for a graphical user interface (GUI) application that implements a queue data structure. It allows users to add items to the queue and serve (remove) items from it, displaying the current queue state using a JList. The application uses a custom 'listOperation' class to manage the queue operations and a 'Doublenode' class to represent the nodes in the queue.

Uploaded by

wijilad205
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Java Queue Implementation GUI

The document contains Java code for a graphical user interface (GUI) application that implements a queue data structure. It allows users to add items to the queue and serve (remove) items from it, displaying the current queue state using a JList. The application uses a custom 'listOperation' class to manage the queue operations and a 'Doublenode' class to represent the nodes in the queue.

Uploaded by

wijilad205
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Activity: Queue

Name : Joaquim Muhongo

CODE

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

public class Queue extends JFrame implements ActionListener {


private JTextField num = new JTextField(50);
private JTextField num2 = new JTextField(50);
private JLabel label = new JLabel("Item: ");
private JLabel label2 = new JLabel();
private JButton btnAdd = new JButton("Add");
private JButton btnServe = new JButton("Serve");
private JList list;
private DefaultListModel listModel;
ListSelectionModel listmodel;
//object
listOperation stack = new listOperation();
listOperation stackundo = new listOperation();

public Queue(String title) {


super(title);
setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("img/[Link]")));
setLayout(new FlowLayout());
// Just for refresh :) Not optional!
setSize(399,399);
setSize(300,300);

listModel = new DefaultListModel();


list = new JList(listModel);

JLabel headline = new JLabel("Queue");


[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],15));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],80));
[Link](new Color(32, 50, 57));
//SETBOUNDS
[Link](170,10,200,30);
[Link](50,50,50,30);
[Link](280,230,200,80);
[Link](110,50,320,30);
[Link](110,90,150,30);
[Link](280,90,150,30);

[Link](this);
[Link](this);

JScrollPane listScrollPane = new JScrollPane(list);


[Link](30,150,200,250);
[Link](new Dimension(150,50));
//ADD
add(headline);
add(label);
add(label2);
add(num);
add(listScrollPane);
add(btnAdd);
add(btnServe);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(500,500);
setVisible(true);
}

public void actionPerformed(ActionEvent event) {


String txtinput = [Link]();

if (btnAdd == [Link]()) {
[Link]([Link]([Link]()));
[Link]("");
} else if(btnServe == [Link]()) {
if([Link] == null) {
return;
} else {
[Link]([Link]([Link]));
[Link]();
}

}
[Link]();//parama
[Link]();
[Link]();
[Link]([Link]);
}

public static void main(String[] args) {


Container list = new Queue("Queue");
}
}

class listOperation {
Queue head;
Queue tail;
String output = "";

public listOperation() {
head = null;
tail = null;
}
public boolean isEmpty() {
return head == null;
}
public void addHead(int item) {
if (isEmpty()) {
head = tail = new Queue(item);
} else {
head = [Link] = new Queue(null,item,head);
}
}
public void addTail(int item) {
if (isEmpty()) {
head = tail = new Queue(item);
} else {
tail = [Link] = new Queue(tail,item,null);
//[Link] = new node(item);
//tail = [Link];
}
}
public void deleteHead() {
Queue tempHead;
if (!isEmpty()) {
if (head == tail) {
head = tail = null;
} else {
tempHead = [Link];
[Link] = [Link] = null;
head = tempHead;
}
}
}
public void deleteTail() {
Queue tmp;
if (!isEmpty()) {
if (head == tail) {
head = tail = null;
} else {
tmp = [Link];
[Link] = [Link] = null;//cut the connection
tail = tmp;
}
}
}
public void displayThis() {
Queue tmp = head;
output = "<html>";

for (tmp = head; tmp != null; tmp = [Link]) {


output = output + "<br>" + [Link] + "<br>";
}
output = output + "<html>";
}
}
public class Doublenode {
public int data;
public Doublenode next;
public Doublenode previous;

public Doublenode(int d) {
this(null,d,null);
}

public Doublenode(Doublenode p,int d,Doublenode n) {


previous = p;
data = d;
next = n;

}
}
OUTPUT

ADD

SERVE

You might also like