Wonders of the World Java Code
I was assigned a special task by my professor to write a code on wonders of the world. The objective of the code was to read a provided set of images and database and replicate a system that would sort the images in specified orders. There were three types of specifications provided
1. Natural
2. Temperature
3. Accessibility
After selection another window opens in which the output is displayed, the output contains a series of images sorted in the selected order.
This “window-2″ has four buttons.
“First”, “Next”, “Previous” and “Last”, each does a task specified by its title and moves images in that order.
If you want the source code for this program, comment on this post.
* @(#)WondersApp.java
*
*
* @author Qambar Raza
* @version 1.00 2012/2/16
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class WondersApp extends JDialog
implements ActionListener {
private WondersViewer wondersViewerObject;
private JButton jButtonFirst;
private JButton jButtonNext;
private JButton jButtonPrevious;
private JButton jButtonLast;
private ImageJPanel wonderImage;
private WondersApp wondersAppObj;
public int currentIndex;
public WondersApp(JFrame owner, String title, boolean modal) {
super( owner, title, modal );
currentIndex = 0;
if ( owner instanceof Frame ) {
wondersViewerObject = (WondersViewer) owner;
}
wondersAppObj = this;
initializeComponents();
}
//initializing GUI
public void initializeComponents() {
//JDialog dialog = this;
Container contentPane = this.getContentPane();
contentPane.setLayout( new BorderLayout());
setSize(WondersProperties.WINDOW2_WIDTH, WondersProperties.WINDOW2_HEIGHT);
try {
JPanel p = new JPanel(new FlowLayout());
p.add(createButtonBozims(jButtonFirst, “First”));
p.add(createButtonBozims(jButtonNext, “Next”));
p.add(createButtonBozims(jButtonPrevious, “Previous”));
p.add(createButtonBozims(jButtonLast, “Last”));
p.setBackground(WondersProperties.ORANGE_BOZIMS);
add(p , BorderLayout.SOUTH);
wonderImage = loadImage(wondersViewerObject.wondersDataAccessor.wondersDataArrayList.get(0).getImage());
System.out.println(wondersViewerObject.wondersDataAccessor.wondersDataArrayList.get(0).toString());
add(wonderImage, BorderLayout.CENTER);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
public ImageJPanel loadImage(String imageName) {
ImageJPanel image = new ImageJPanel(System.getProperty(“user.dir”) + WondersProperties.IMAGES_PATH + imageName);
return image;
}
public void changeImage(String imageName) {
wonderImage.changeImage(System.getProperty(“user.dir”) + WondersProperties.IMAGES_PATH + imageName);
}
public JButton createButtonBozims(JButton button, String title) {
button = new JButton(title);
button.setBackground( WondersProperties.ORANGE_BOZIMS );
button.setBorder( BorderFactory.createRaisedBevelBorder() );
button.setForeground( Color.white );
button.setPreferredSize( new Dimension( WondersProperties.BUTTON2_WIDTH, WondersProperties.BUTTON_HEIGHT ) );
button.setActionCommand(title.toLowerCase());
button.setMinimumSize( new Dimension( WondersProperties.BUTTON2_WIDTH, WondersProperties.BUTTON_HEIGHT ) );
button.setCursor (new Cursor (Cursor.HAND_CURSOR));
button.addActionListener( wondersAppObj );
return button;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
ArrayList<WondersData> temp = wondersViewerObject.wondersDataAccessor.wondersDataArrayList;
if ( command.equals(“first”) ) {
currentIndex = 0;
} else if ( command.equals(“next”) ) {
if ((currentIndex + 1) >= temp.size() ) {
currentIndex = 0;
} else {
currentIndex++;
}
} else if ( command.equals(“previous”) ) {
if ((currentIndex – 1) < 0 ) {
currentIndex = temp.size() – 1;
} else {
currentIndex–;
}
} else if ( command.equals(“last”) ) {
currentIndex = temp.size() – 1;
}
/* System.out.println(“Index:” + currentIndex);*/
System.out.println(temp.get(currentIndex).toString());
changeImage(temp.get(currentIndex).getImage());
}
}



