Question: I created a JButton on Netbeans that will upload a picture on AddCarForm. I need the then display the uploaded photo with the information on

I created a JButton on Netbeans that will upload a picture on AddCarForm. I need the then display the uploaded photo with the information on the Inventory File Reader. It simply adds the photo as a new button.

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package GUI; import Model.Car; import java.awt.Button; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; /** * * @author msalehan */ public class InventoryItemPanel extends JPanel{ private JLabel label = new JLabel("Car", SwingConstants.CENTER); private Button addCar = new Button ("Add Car");

private Button viewButton = new Button("View More Details");

Car car; ArrayList cars; public void buttonClicked(){ ViewCarForm cform = new ViewCarForm (cars,car); cform.setVisible(true); } //ArrayList cars, Car car public InventoryItemPanel (ArrayList cars, Car car) throws IOException{ viewButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { viewButton.setSize(156, 29); buttonClicked(); } }); addCar.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { AddCarForm frame = new AddCarForm(); frame.setVisible (true); } }); BufferedImage carPicture; try { carPicture = ImageIO.read (new File (".//src//images//" + car.getMake() + car.getModel() + ".jpg"));

} catch (Exception e) { carPicture = ImageIO.read(new File (".//src//images//")); } ImageIcon imageIcon = new ImageIcon(carPicture.getScaledInstance(156,75,1)); // carPicture.getScaledInstance (150,110, java.awt.Image.SCALE_DEFAULT) JLabel picLabel = new JLabel (imageIcon); add (picLabel); setLayout (new GridLayout (3,1)); this.cars= cars; this.car = car;

label.setText("

"+ car.getMake()+ " "+ car.getModel() + " " + car.getMiles()+" miles" + " $" +car.getPrice() + "

" ); add (label); add (viewButton); viewButton.setBounds(10, 100, 156, 29); } //

}

this is in AddCarForm.java (Where the File Chooser is located)

private void attachButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JFileChooser carPicChooser = new JFileChooser (FileSystemView.getFileSystemView().getHomeDirectory()); carPicChooser.setCurrentDirectory (new File (".//src//images//")); carPicChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); carPicChooser.showOpenDialog(null); carPicChooser.getFileFilter(); // carPicChooser.setAcceptAllFileFilterUsed(false); //FileNameExtensionFilter filter = new FileNameExtensionFilter("JPEG file", ".jpg", "jpeg"); //carPicChooser.addChoosableFileFilter(filter); File getFile = carPicChooser.getSelectedFile(); String fileName = getFile.getAbsolutePath(); jTextField1.setText(fileName);

}

Car.java

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Model; /** * * @author msalehan */ public class Car { private String make; private int year; private String model; private int price; private String color; private CarType carType; private Engine engine; private Interior interior; private Trunk trunk; private int miles; public Car (String make, String model,int year, int price, CarType carType, int miles, String color){ this.make = make; this.year = year; this.model = model; this.price = price; this.color = color; this.miles = miles; this.carType = carType; } public Car (String make, String model,int year, int price,CarType carType, int miles, String color, Engine engine, Interior interior, Trunk trunk){ this.make = make; this.year = year; this.model = model; this.price = price; this.color = color; this.miles = miles; this.carType = carType; this.interior =interior; this.engine = engine; this.trunk = trunk; }

public String getMake(){ return make; } public String getModel() { return model; } public int getYear (){ return year; } public int getPrice(){ return price; } public String getColor(){ return color; } public int getMiles(){ return miles; } public void SetType (CarType cartype){ cartype = carType; } public CarType getType (){ return carType; }

public void SetEngine(Engine engine){ this.engine = engine; } public Engine getEngine(){ return engine; } public void SetInterior(Interior interior){ this.interior = interior; } public Interior getInterior(){ return interior; } public void SetTrunk(Trunk trunk){ this.trunk = trunk;} public Trunk getTrunk (){ return trunk; } public String OpenTrunk() { return trunk.toString(); } public String CheckEngine(){ return engine.toString(); } public String CheckInterior(){return interior.toString();} public String ShowOptions(){return null;} public String toString(){ String carInfo = color + " " + year + " " + make + " " + model + "for $" + price; return carInfo; } public String CompareTo (Car otherCar){ return null; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!