package Assignment2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class AuctionDialog extends JFrame implements ActionListener {
`    private JLabel lblOutput;`
    private JTextField tfBidder;
    private JTextField tfPainting;
    private JTextField tfAmount;
    private JTextArea taOutput;
    private JButton btnSubmit;
    private Painting paintings;
    private Bid bids;
    private Auction artworkAuction;


    public AuctionDialog( )
    {

       artworkAuction = new Auction("");

       JLabel lblBidder = new JLabel("Bidder ID:");
        tfBidder= new JTextField(10);
       JLabel lblPainting = new JLabel("Painting ID:");
        tfPainting = new JTextField(10);
       JLabel lblAmount = new JLabel("Amount");
        tfAmount = new JTextField();
        taOutput = new JTextArea();
        taOutput.setEditable(false);
        taOutput.setColumns(20);
        taOutput.setRows(3);
        taOutput.setLineWrap(true);
       btnSubmit= new JButton ("Submit");
        btnSubmit.addActionListener(this);

        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(5,2));
        p1.add(lblBidder);
        p1.add(tfBidder);
        p1.add(lblPainting);
        p1.add(tfPainting);
        p1.add(lblAmount);
        p1.add(tfAmount);
        p1.add(new Label()); //dummy
        p1.add(btnSubmit);
        //textArea
        JPanel p2 = new JPanel();
        p2.add(taOutput);

        Container c = getContentPane();
        c.add(p1, BorderLayout.NORTH);
        c.add(p2, BorderLayout.SOUTH);

       setTitle("Making a Bid");
       // pack to organize the size
       pack();
       setLocationRelativeTo(null);
       setVisible(true);
       setResizable(false);


    }

    //I need help in this area...
     public void actionPerformed (ActionEvent e)
    {
    //can someone help me how to search an existing object in an arrayList
       String input = tfBidder.getText();
            ArrayList<Bidder> bidders = artworkAuction.getBidders();//??
            for (Bidder b: bidders)
            { 
                if(b.getBidderId().equals(input))
                {
                    taOutput.append(input);//??
                }else
                {
                    taOutput.append("invalid bidder");
                }
            }

    }

}

can someone help me how to search an existing object in an arrayList.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.