Java program that creates a photo album application. Which will load a collectio
ID: 671174 • Letter: J
Question
Java program that creates a photo album application. Which will load a collection of images and displays them in a album layout. The program will allow the user to tag images with metadata:
•Title for the photo
. Limited to 100 characters.
•Description for the photo
. Limited to 300 characters.
•Date taken
•Place taken
Functional Specs
1.Your album should be able to display the pictures sorted by Title, Date, and Place.
2.When the user clicks on a photo, data should be displayed.
3.The user should be able to add or remove pics.
*Please note the swing library cannot be used only scene (vBox,hBox, etc...)
Explanation / Answer
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class ImageDemo
{
public static void main(String[] args) throws Exception
{
new ImageDemo(args[0]);
}
public ImageDemo(final String filename) throws Exception
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
JFrame editorFrame = new JFrame("Image Demo");
editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
BufferedImage image = null;
try
{
image = ImageIO.read(new File(filename));
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
ImageIcon imageIcon = new ImageIcon(image);
JLabel jLabel = new JLabel();
jLabel.setIcon(imageIcon);
editorFrame.getContentPane().add(jLabel, BorderLayout.CENTER);
editorFrame.pack();
editorFrame.setLocationRelativeTo(null);
editorFrame.setVisible(true);
}
});
}
}
public class GridViewAdapter extends ArrayAdapter {
private Context context;
private int layoutResourceId;
private ArrayList data = new ArrayList();
public GridViewAdapter(Context context, int layoutResourceId, ArrayList data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.imageTitle = (TextView) row.findViewById(R.id.text);
holder.image = (ImageView) row.findViewById(R.id.image);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
ImageItem item = data.get(position);
holder.imageTitle.setText(item.getTitle());
holder.image.setImageBitmap(item.getImage());
return row;
}
static class ViewHolder {
TextView imageTitle;
ImageView image;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.