import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Queue extends JFrame implements ActionListener {
JLabel welcom=new JLabel("Welcome to Graphical Represention of Queues Press Enter to Continue");
Font fnt=new Font("Arial",Font.ITALIC,20);
JButton entr=new JButton("Enter");
JPanel panel_for_Label=new JPanel();
JPanel panel_for_Button=new JPanel();
public Queue()
{
super("Graphical Representation of Queues");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1000,600);
setLocation(150,100);
setLayout(new GridLayout(2,1));
panel_for_Label.setLayout(new FlowLayout(FlowLayout.CENTER));// Lay out for Welcome Label Panel
panel_for_Button.setLayout(new FlowLayout(FlowLayout.CENTER));//Layout for Enter Button Panel
welcom.setFont(fnt);
panel_for_Label.add(welcom);
entr.addActionListener(this);
panel_for_Button.add(entr);
add(panel_for_Label);
add(panel_for_Button);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==entr)
{
setVisible(false);
Paint_window obj= new Paint_window();
}
}
public static void main(String[] args) {
new Queue();
}
}
class Paint_window extends JFrame implements ActionListener
{
int count=0;
JFrame f=new JFrame("Queue");
JLabel ent_data=new JLabel("Enter Data");
JTextField tf=new JTextField(10);
JButton ent=new JButton("Enter");
JButton rtrv=new JButton("Retrieve");
JButton ad=new JButton("Add");
JLabel dta[]=new JLabel[100];
String str[]=new String [100];
JLabel l=new JLabel("Faraz);");
JPanel que_panel=new JPanel();
JPanel btn_panel=new JPanel();
Paint_window()
{
super("Graphical Representation of Queue");
setSize(600,300);
setLocation(150,100);
setLayout(new GridLayout(2,1));
que_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
btn_panel.setLayout(new FlowLayout(FlowLayout.CENTER));
add(que_panel);
ad.setEnabled(false);
btn_panel.add(ad);
add(btn_panel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
// Data for 2nd Frame
{
f.setSize(500,250);
f.setLocation(800,400);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.add(ent_data);
f.add(tf);
f.add(ent);
f.add(rtrv);
ent.addActionListener(this);
rtrv.addActionListener(this);
ad.addActionListener(this);
f.setVisible(true);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ent)
{
{dta[count]=new JLabel(str[count]);
que_panel.add(dta[count]);
}
str[count]=tf.getText();
//JOptionPane.showMessageDialog(null,count);
ent.setEnabled(false);
ad.setEnabled(true);
f.setAutoRequestFocus(false);
tf.setText("");
}
if(e.getSource()==ad)
{
//que_panel.add(dta[count-1]);
dta[count].setText(str[count]);
count++;
ent.setEnabled(true);
ad.setEnabled(false);
f.setAutoRequestFocus(true);
}
if(e.getSource()==rtrv)
{
if(count>0)
{
for(int i=0;i<count;i++)
{
dta[i].setText(str[i+1]);
}
for(int i=0;i<count;i++)
{
str[i]=str[i+1];
}
count--;
}
else
{
JOptionPane.showMessageDialog(null," Queue is Empty\n or\nAll the Data Has Retrieved");
}
}
}
}
import java.awt.*;
import java.awt.event.*;
public class Queue extends JFrame implements ActionListener {
JLabel welcom=new JLabel("Welcome to Graphical Represention of Queues Press Enter to Continue");
Font fnt=new Font("Arial",Font.ITALIC,20);
JButton entr=new JButton("Enter");
JPanel panel_for_Label=new JPanel();
JPanel panel_for_Button=new JPanel();
public Queue()
{
super("Graphical Representation of Queues");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1000,600);
setLocation(150,100);
setLayout(new GridLayout(2,1));
panel_for_Label.setLayout(new FlowLayout(FlowLayout.CENTER));// Lay out for Welcome Label Panel
panel_for_Button.setLayout(new FlowLayout(FlowLayout.CENTER));//Layout for Enter Button Panel
welcom.setFont(fnt);
panel_for_Label.add(welcom);
entr.addActionListener(this);
panel_for_Button.add(entr);
add(panel_for_Label);
add(panel_for_Button);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==entr)
{
setVisible(false);
Paint_window obj= new Paint_window();
}
}
public static void main(String[] args) {
new Queue();
}
}
class Paint_window extends JFrame implements ActionListener
{
int count=0;
JFrame f=new JFrame("Queue");
JLabel ent_data=new JLabel("Enter Data");
JTextField tf=new JTextField(10);
JButton ent=new JButton("Enter");
JButton rtrv=new JButton("Retrieve");
JButton ad=new JButton("Add");
JLabel dta[]=new JLabel[100];
String str[]=new String [100];
JLabel l=new JLabel("Faraz);");
JPanel que_panel=new JPanel();
JPanel btn_panel=new JPanel();
Paint_window()
{
super("Graphical Representation of Queue");
setSize(600,300);
setLocation(150,100);
setLayout(new GridLayout(2,1));
que_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
btn_panel.setLayout(new FlowLayout(FlowLayout.CENTER));
add(que_panel);
ad.setEnabled(false);
btn_panel.add(ad);
add(btn_panel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
// Data for 2nd Frame
{
f.setSize(500,250);
f.setLocation(800,400);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.add(ent_data);
f.add(tf);
f.add(ent);
f.add(rtrv);
ent.addActionListener(this);
rtrv.addActionListener(this);
ad.addActionListener(this);
f.setVisible(true);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ent)
{
{dta[count]=new JLabel(str[count]);
que_panel.add(dta[count]);
}
str[count]=tf.getText();
//JOptionPane.showMessageDialog(null,count);
ent.setEnabled(false);
ad.setEnabled(true);
f.setAutoRequestFocus(false);
tf.setText("");
}
if(e.getSource()==ad)
{
//que_panel.add(dta[count-1]);
dta[count].setText(str[count]);
count++;
ent.setEnabled(true);
ad.setEnabled(false);
f.setAutoRequestFocus(true);
}
if(e.getSource()==rtrv)
{
if(count>0)
{
for(int i=0;i<count;i++)
{
dta[i].setText(str[i+1]);
}
for(int i=0;i<count;i++)
{
str[i]=str[i+1];
}
count--;
}
else
{
JOptionPane.showMessageDialog(null," Queue is Empty\n or\nAll the Data Has Retrieved");
}
}
}
}

