Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package application; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io . File; import java.io . IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import

package application;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXDatePicker;
public class PetGUI implements ActionListener {
JFrame frame, addWindow, searchWindow, displayWindow;
JMenuBar menuBar;
JMenu fileMenu, helpMenu;
JMenuItem add, modify, display, report, exit, helpContents, about;
JButton addButton, displayButton, showFileDialogButton, modifyButton;
List pets;
JPanel addPanel, genderPanel, searchPanel, modifyPanel, displayPanel;
JLabel nameLabel, photoLabel, typeLabel, colorLabel, genderLabel, isSterilizedLabel, pedigreeLabel, dateEntryLabel, vaccineOneLabel, vaccineTwoLabel, vaccineThreeLabel;
JTextField nameField, typeField, colorField, pedigreeField, dateEntryField;
JFileChooser fileDialog;
JRadioButton male, female;
ButtonGroup genderGroup;
JCheckBox isSterilizedChkBox, pedigreeChkBox, vaccineOneChkBox, vaccineTwoChkBox, vaccineThreeChkBox;
JXDatePicker picker;
Image selectedImage;
PetGUI(){
pets = new ArrayList();
frame = new JFrame();
add = new JMenuItem("Add New Pet");
modify = new JMenuItem("Modify a Pet");
display = new JMenuItem("Display Pet Info");
report = new JMenuItem("Report");
exit = new JMenuItem("Exit");
add.addActionListener(this);
modify.addActionListener(this);
display.addActionListener(this);
report.addActionListener(this);
exit.addActionListener(this);
helpContents = new JMenuItem("Help contents");
about = new JMenuItem("About");
helpContents.addActionListener(this);
about.addActionListener(this);
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
helpMenu = new JMenu("Help");
fileMenu.add(add);
fileMenu.add(modify);
fileMenu.add(display);
fileMenu.add(report);
fileMenu.add(exit);
helpMenu.add(helpContents);
helpMenu.add(about);
menuBar.add(fileMenu);
menuBar.add(helpMenu);
frame.add(menuBar);
frame.setJMenuBar(menuBar);
frame.setLayout(null);
frame.setSize(400,400);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()== add){
addWindow = new JFrame();
addWindow.setSize(500,500);
addWindow.setDefaultCloseOperation(1);
addWindow.setTitle("Add Pet");
addPanel = new JPanel();
addPanel.setLayout(new GridLayout(13,2));
nameLabel = new JLabel("Name:");
addPanel.add(nameLabel);
nameField = new JTextField();
nameField.setBounds(10,30,100,30);
addPanel.add(nameField);
photoLabel = new JLabel("Photo:");
addPanel.add(photoLabel);
fileDialog = new JFileChooser();
showFileDialogButton = new JButton("Open File");
showFileDialogButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int returnVal = fileDialog.showOpenDialog(addWindow);
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fileDialog.getSelectedFile();
try {
selectedImage = ImageIO.read(file);
} catch (IOException e1){
e1.printStackTrace();
}
} else {
}
}
});
addPanel.add(showFileDialogButton);
addWindow.setVisible(true);
typeLabel = new JLabel("Type:");
addPanel.add(typeLabel);
typeField = new JTextField();
typeField.setBounds(10,70,100,30);
addPanel.add(typeField);
colorLabel = new JLabel("Color:");
addPanel.add(colorLabel);
colorField = new JTextField();
colorField.setBounds(10,70,100,30);
addPanel.add(colorField);
genderLabel = new JLabel("Gender:");
addPanel.add(genderLabel);
male = new JRadioButton("Male");;
female = new JRadioButton("Female");
genderGroup = new ButtonGroup();
male.setBounds(10,70,50,30);
female.setBounds(50,70,100,30);
genderGroup.add(male);
genderGroup.add(female);
genderPanel = new JPanel();
genderPanel.setLayout(new GridLayout(1,3));
genderPanel.add(male);
genderPanel.add(female

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write a paper on application development in detail

Answered: 1 week ago