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);
}
//need help here
public void actionPerformed (ActionEvent e)
{`Inline Code Example Here`
//how to search 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");
}
}
}
}
marvin.lerias
0
Newbie Poster
Recommended Answers
Jump to PostThat code looks OK. What help do you need?
Jump to PostYour method should add one line to the text area for each bidder in the array list, so you need to debug the actionPerformed by adding a number of simple print statements to display the values of the main variables as the method executes. You need to answer questions like …
Jump to PostDoes OP needs to revalidate/repaint the textArea object because the OP builds the UI in
AuctionDialog
constructor but appends contents inactionPerformed()
?
All 9 Replies
marvin.lerias
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
marvin.lerias
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
stultuske
1,116
Posting Maven
Featured Poster
marvin.lerias
0
Newbie Poster
marvin.lerias
0
Newbie Poster
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.