Ajp Suraj1
Ajp Suraj1
Submitted by:
This is to certify that Project report entitled " Online Spectacles Shop" is
submitted in the partial fulfillment of requirement for the award of the Diploma
in Computer Engineering by Maharashtra State Board of Technical Education as
record of student’s own work carried out by them under the guidance and
supervision at Ajeenkya DY Patil School of Engineering (Charholi), during the
academic year 2023-24.
ACKNOWLEDGEMEMT
Micro-Project Report
lOMoARcPSD|38973805
1. Rationale:
Java technology is widely used for web applications development. Based on the object-
oriented concepts and core Java concepts, this course will equip the students with the required
knowledge and skill of object-oriented programming approach needed for the development of
robust, powerful web applications. Through this course students will get hands-on experience
on GUI Technologies viz. AWT and Swings, event handling mechanisms and network
programming. The course also gives coverage to various web applications aspects like
Database Interaction, server-side components, and servlets.
A micro-project helps the students to develop skills specific to collaborative efforts, allowing
students to tackle more complex problems then they could do on their own.
4. Literature Review:
Swing components are part of the Java Foundation Classes (JFC) library used for creating
graphical user interfaces (GUIs) in Java applications. Swing provides a rich set of
components for building interactive and visually appealing desktop applications. Here are
some key Swing components:
1. JFrame:
`JFrame` is a top-level container that represents the main window of a Java application. It can
hold other Swing components and provides basic functionalities like resizing, minimizing,
and closing the window.
lOMoARcPSD|38973805
2. JPanel:
3. JButton:
`JButton` is a component that represents a clickable button. It is widely used for triggering
actions in response to user input.
4. JLabel:
`JLabel` is used for displaying a single line of read-only text or an image. It's often used to
provide descriptions or captions for other components.
5. JTextField:
`JTextField` is a text input component that allows the user to enter and edit a single line of text.
6. JTextArea:
`JTextArea` is a multi-line text input component. It allows the user to enter and edit multiple
lines of text.
7. JCheckBox:
8. JRadioButton:
`JRadioButton` is a component that represents a radio button. It's used in groups where only
one option can be selected at a time.
9. JComboBox:
`JComboBox` is a drop-down list that allows the user to select an item from a list of predefined
options.
10. JList:
`JList` is a component that displays a list of items. Users can select one or more items from the
list.
11. JScrollPane:
12. JSlider:
lOMoARcPSD|38973805
`JSlider` is used to allow the user to slide a knob within a bounded interval. It's commonly
used for settings like volume control.
These components are used to create menus in a Swing application. `JMenuBar` represents a
menu bar, `JMenu` represents a menu, and `JMenuItem` represents an item in a menu.
Swing provides various layout managers (such as `Flow Layout`, `Border Layout`, `Grid
Layout`, and `Grid BagLayout`) that determine how components are arranged within a
container.
Swing components are part of the Java Standard Edition (SE) platform and provide a
powerful framework for creating desktop applications with rich user interfaces. They allow
developers to create cross-platform applications that can run on any system with Java
support.
public Micro_Project() {
setTitle("Online Spectacle Shop"); setBounds(300, 100, 1200,
800);
getContentPane().setBackground(new Color(152, 115, 172)); setLayout(new
BorderLayout());
searchBar.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) { text =
searchBar.getText(); System.out.println(text);
}
lOMoARcPSD|38973805
@Override
public void keyReleased(KeyEvent e) {
}
});
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { String query =
text.toLowerCase(); for (JPanel bookListing : allSpecListings) {
String title = ((JLabel) ((JPanel)
bookListing.getComponent(1)).getComponent(0)).getText().toLowerCase();
bookListing.setVisible(title.contains(query));
}
System.out.println(query);
}
});
cartButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Show the CartDisplayScreen with the cart items.
new CartDisplayScreen(cartItems);
}
});
searchBarPanel.add(searchButton); searchBarPanel.add(rigidSpace);
searchBarPanel.add(cartButton); // Add the cart button searchPanel.add(searchBarPanel);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private JPanel createSpecListing(String title, String description,
String imageName) {
JPanel specsListing = new JPanel(); specsListing.setBackground(Color.WHITE);
specsListing.setLayout(new BorderLayout());
buyButton.setBackground(Color.WHITE); buyButton.setBorderPainted(false);
addToCartButton.setBackground(Color.WHITE); addToCartButton.setBorderPainted(false);
addToWishlistButton.setBackground(Color.WHITE);
addToWishlistButton.setBorderPainted(false);
addToCartButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { // Check if the spectacle
is already in the cart. SpectacleItem existingItem = findCartItem(title);
if (existingItem != null) {
// If it’s in the cart, increment the quantity.
existingItem.incrementQuantity();
} else {
// If it’s not in the cart, add it as a new item with quantity 1.
cartItems.add(new SpectacleItem(title, imageName, 1));
}
JOptionPane.showMessageDialog(Micro_Project.this, "Added to
Cart: " + title);
}
});
buyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(Micro_Project.this, "Button
Clicked: Buy Now");
}
});
addToWishlistButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(Micro_Project.this, "Button
Clicked: Add To Wishlist");
lOMoARcPSD|38973805
}
});
buttonsPanel.add(buyButton); buttonsPanel.add(addToCartButton);
buttonsPanel.add(addToWishlistButton);
return specsListing;
}
private SpectacleItem findCartItem(String name) { for
(SpectacleItem item : cartItems) { if
(item.getName().equals(name)) { return item;
} }
return null;
}
setVisible(true);
}
}
public class CartScreen extends JFrame { private String
selectedSpectacleName;
setVisible(true);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(Micro_Project::new);
}
}
lOMoARcPSD|38973805
lOMoARcPSD|38973805
lOMoARcPSD|38973805
9. Applications of Micro-Project:
10. Conclusion:
In conclusion, the completion of our advanced Java programming project, where we utilized
Swing components to design an online spectacles shop, marks a significant milestone in our
journey. Through meticulous design and implementation, we have created a seamless and
visually appealing platform that enhances the online shopping experience for customers
seeking eyewear. Leveraging the power of Swing components, we have crafted an intuitive
user interface, integrating features such as product catalogues, interactive image galleries,
shopping cart functionality, and secure payment gateways. Our project not only demonstrates
our mastery of Java programming but also showcases our ability to apply advanced concepts
in graphical user interface development. The successful implementation of this online
spectacles shop underscores our proficiency in both backend and frontend technologies,
setting the stage for future innovative projects in the realm of advanced Java programming
and usercentric application design.
11. Bibliography