I have created a static Main class called ProductButtonTestDriver, that will run my class ProductButton.java- the prof wants a picture of each coffee shop item, with the name and price to appear in a button, then a check box if the customer selects that item- I am only on the first part as of yet- I can't get a productname nor productprice to appear as a button, that is then checked off if the custoomer wants that item? I am new to Java and learning as I go. The code below does not look pretty, I have no comments, not proper spacing, try to overlook this. I have put a great deal of effort in this if that counts for something?!- I have checked a number of resources, but am getting confused- can someone help me?:0)

package productbuttontestdriver;

import java.awt.*;
import javax.swing.*;

public class ProductButton extends JButton {

    ImageIcon image1;
    JLabel label1, label2, label3, label4, label5, label6;
      double coffee = 3.75;
    The name of the product.
   private String productName;
    The price for which we will sell the product
   private double productPrice;

    Creates a button that will display an image of the product
    (assumed to be stored in a file starting with the specified
    name and ending with ".jpg"), the specified product name,
    and the specified price (formatted properly); the text is 
    displayed below the image and is centered.
    @param name The product name.
    @param price The selling price for this product.
   public ProductButton (String name, double price) {
      /* Add code here (& only here) to complete this class. */
            name="Coffee: $" ;
       productPrice = price;
       productName = name;
       ImageIcon icon = new ImageIcon ("coffee.jpg");
       label1 = new JLabel ("Coffee: $" + coffee, icon, SwingConstants.CENTER);
    ProductButton() {
     setLayout(new FlowLayout());
    image1=new ImageIcon(getClass().getResource("coffee.jpg"));
    label1=new JLabel(image1);
    add(label1);  }
    Retrieves the product name.
    @return The product name.
   public String getName() { 
      return productName; 

    Retrieves the selling price.
    @return The price for which we will sell the product.
   public double getPrice() { 
      return productPrice; 


package productbuttontestdriver;

import java.awt.*;
import javax.swing.*;

public class ProductButtonTestDriver {
        public static void main(String[] args){
        JFrame frame = new JFrame("Selection");
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(200, 200));
        frame.getContentPane().add(new ProductButton());

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This question has already been answered. Start a new discussion instead.