Merosansar 0 Newbie Poster

The code for sleeping barber problem. When the status of the barber
is set to busy then the customer cannot have a hair cut and is added to the
waiting queue. when the customer is set to free then the customer have a
hair cut.
Here the problem is that only the first customer have a hair cut and the other
customers added in the queue cannot have a hair cut.
Any help will be appreciated.

customeradd class:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cutomeradd.java
 *
 * Created on Apr 4, 2010, 12:47:17 PM
 */

package gui;

import customer.Customer;

/**
 *
 * @author hp
 */
public class cutomeradd extends javax.swing.JFrame {

    public static int enteredcustomerpos=1;

    /** Creates new form cutomeradd */
    public cutomeradd() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOTe modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        addCusotmer = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        addCusotmer.setText("Add");
        addCusotmer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCusotmerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(addCusotmer)
                .addContainerGap(98, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(addCusotmer)
                .addContainerGap(57, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    @SuppressWarnings("static-access")
    private void addCusotmerActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your …
Merosansar 0 Newbie Poster

but the values are equal then, what may be the reason that if statement is not executing

Merosansar 0 Newbie Poster
if(mail.equals(usermail) && date1.equals(date) && title1.equals(title))
            {
                System.out.println("record is matched");
                returnFlag = true;
                break;

         }

the if statement is not executing even though all the strings are equals.

Merosansar 0 Newbie Poster

I have loaded the rows of the data from the database in the list.Now,i am trying to display the list of datas on the JPanel which is loaded inside the parent JPanel on button click. I have retreived the list of data but not able to display the data on the JPanel.
Any guides will be appreciated.

Merosansar 0 Newbie Poster

I created a panel in the other components of inspector window in netbeans. I want to add and display this created panel inside the panel on button click which is inside the frame.But so far i am not able to do so. Any help will be appreciated

Merosansar 0 Newbie Poster

Making the list instance varaible global of the CandidateList class works. Now, I am trying to display the information of the list variable on the JTable using the DefaultTableModel on clicking the show button.But, when I try to to do so I am getting

NullPointerException at 
  at candidateinfo.VotersTableList.setTheCandidateTable(VotersTableList.java:90)
        at candidateinfo.CandidateList.showList(CandidateList.java:60)
        at gui.VotesForm.showJButton2ActionPerformed(VotesForm.java:154)
        at gui.VotesForm.access$200(VotesForm.java:22)
        at gui.VotesForm$3.actionPerformed(VotesForm.java:77)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6134)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5899)
        at java.awt.Container.processEvent(Container.java:2023)
        at java.awt.Component.dispatchEventImpl(Component.java:4501)
        at java.awt.Container.dispatchEventImpl(Container.java:2081)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
        at java.awt.Container.dispatchEventImpl(Container.java:2067)
        at java.awt.Window.dispatchEventImpl(Window.java:2458)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I have created VotersTableList to display the data in the JTable.

VotersTableList.java


package candidateinfo;

import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.awt.BorderLayout;



public class VotersTableList
{


    private JTable table=null;
    private JFrame frame=new JFrame("VotersTableList");

    private class VotersList extends DefaultTableModel
    {

        private List list=null;

        public VotersList(List list)
        {
        this.list=list;
        }


        @Override
        public int getColumnCount()
        {
        return 3;

        }

        @Override
        public int getRowCount()
        {

            return list.size();
        }

        @Override
        public Object getValueAt(int row,int column)
        {
            if(row>=list.size())
            {
            return null;
            }

            Candidate canvalues=(Candidate) list.get(row);

            if(column==0)
            {
                return canvalues.getFirstName();
            }

            else if(column==1)
            {

                return canvalues.getLastName();
            }

            else if(column==2)
            {

                return canvalues.getVotesReceived();
            }
            else
            {
             return null;
            }
        }




    }

    public void setTheCandidateTable() throws Exception
    {
           table.setModel(new VotersList(CandidateList.canlist));
           frame.getContentPane().add(table,BorderLayout.CENTER);
           frame.setSize(200, 200);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);


    }




 }

I am not finding the solution to this exception.
Any help will be appreciated.

Merosansar 0 Newbie Poster

The form consist of three textfields and two buttons(add and show buttons). User enters the candidate first name and last name and the respective number of votes received in textfields.On clicking the add button the candidate object is created and the candidate object is added to the arraylist object. On clicking the show button gives the actual size of the arraylist which is not happening.


Candidates.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author hp
 */
//import java.io.*;

public class Candidates {
    String firstname;
    String lastname;
    int votesreceived;

   
    public Candidates(String fname,String lname,int votes)
    {
    this.firstname=fname;
    this.lastname=lname;
    this.votesreceived=votes;
    }

    public String getFirstName()
    {
    return firstname;
    }
    
    public String getLastName()
    {
    return lastname;
    
    }
    
    public int getVotesReceived()
    {
    return votesreceived;
    }

}

VotesForm.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
 {
        // TODO add your handling code here:
        String fname=firstname.getText();
        String lname=lastname.getText();
        int votes=Integer.parseInt(votesreceived.getText());

        //System.out.println("Checking the voting system");
        System.out.println("Creating the candidate object");

        CandidateList canlist=new CandidateList();
        canlist.addCandidates(fname,lname,votes);

        firstname.setText("");
        lastname.setText("");
        votesreceived.setText("");

        
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    CandidateList canshow=new CandidateList();
    //canshow.showCandidates();
    //canshow.test();
    canshow.showCandidates();
    }

CandidateList.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author hp
 */
import java.util.*;
import java.util.ArrayList.*;

public class CandidateList {

    //instance variables
    
    //private List canlist;

    ArrayList canlist;
    public CandidateList()
    {
   // canlist=new LinkedList();
     canlist=new ArrayList();
    }

    //adding the candidates in the …
Merosansar 0 Newbie Poster

I am going through the java basic. I need some simple sample programme using the concept of class and interface with description.