master
mms37 2 years ago
parent 1bc540427a
commit 1b9bcaf4f2

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="github.lgooddatepicker.LGoodDatePicker" type="repository">
<properties maven-id="com.github.lgooddatepicker:LGoodDatePicker:11.2.1" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/lgooddatepicker/LGoodDatePicker/11.2.1/LGoodDatePicker-11.2.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -3,5 +3,6 @@
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="google.code.gson" level="project" />
<orderEntry type="library" name="github.lgooddatepicker.LGoodDatePicker" level="project" />
</component>
</module>

@ -1,46 +1,194 @@
package cmpt213.assignment3.packagedeliveries.view;
import com.github.lgooddatepicker.components.DateTimePicker;
import com.github.lgooddatepicker.optionalusertools.DateTimeChangeListener;
import com.github.lgooddatepicker.zinternaltools.DateTimeChangeEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDateTime;
public class Input extends JDialog implements ActionListener, DateTimeChangeListener {
private JLabel typeLabel;
private JPanel typePanel;
private JTextField typeTf;
private DateTimePicker dd, ed;
private LocalDateTime deliveryDate, expiryDate;
private JTextField nameField;
private JTextField noteField;
private JTextField priceField;
private JTextField weightField;
private JTextField dateField;
private int pType;
public class Input {
JTextField typeLabel;
public Input(Frame main){
public Input(Frame main) {
super(main, "add a package", true);
JPanel p = new JPanel();
String[] type={"book", "perishable", "electronic"};
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
JComboBox<String> packageType=new JComboBox<>(type);
String[] type = {"book", "perishable", "electronic"};
JComboBox<String> packageType = new JComboBox<>(type);
packageType.setPreferredSize(new Dimension(300, 30));
packageType.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String p=(String) packageType.getSelectedItem();
switch (p){
String p = (String) packageType.getSelectedItem();
switch (p) {
case "book":
typeTf.setVisible(true);
ed.setVisible(false);
typeLabel.setText("author name");
pType=0;
break;
case "perishable":
typeTf.setVisible(false);
ed.setVisible(true);
ed.addDateTimeChangeListener(new DateTimeChangeListener() {
@Override
public void dateOrTimeChanged(DateTimeChangeEvent dateTimeChangeEvent) {
expiryDate=ed.getDateTimePermissive();
}
});
typePanel.add(ed);
typeLabel.setText("expiry date");
pType=1;
break;
case "electronic":
case "electronic":
typeTf.setVisible(true);
ed.setVisible(false);
typeLabel.setText("handling fee");
pType=2;
}
}
});
JPanel name=new JPanel();
JLabel nameLabel=new JLabel();
JTextField namefield= new JTextField();
name.setLayout(new BoxLayout(name, BoxLayout.X_AXIS));
nameLabel.setText("name:");
nameLabel.setPreferredSize(new Dimension(50, 25));
name.add(nameLabel);
name.add(namefield);
// Panel for package name
nameField = new JTextField();
JPanel name = new JPanel();
JLabel nameLabel = new JLabel();
name.setLayout(new BoxLayout(name, BoxLayout.X_AXIS));
nameLabel.setText("name:");
nameLabel.setPreferredSize(new Dimension(50, 25));
name.add(nameLabel);
name.add(nameField);
name.setPreferredSize(new Dimension(200, 50));
p.add(packageType);
p.add(name);
JPanel note = new JPanel();
JLabel noteLabel = new JLabel();
noteField = new JTextField();
note.setLayout(new BoxLayout(note, BoxLayout.X_AXIS));
noteLabel.setText("note:");
noteLabel.setPreferredSize(new Dimension(50, 25));
note.add(noteLabel);
note.add(noteField);
note.setPreferredSize(new Dimension(200, 50));
p.add(note);
JPanel price = new JPanel();
JLabel priceLabel = new JLabel();
JTextField priceField = new JTextField();
price.setLayout(new BoxLayout(price, BoxLayout.X_AXIS));
priceLabel.setText("price:");
priceLabel.setPreferredSize(new Dimension(50, 25));
price.add(priceLabel);
price.add(priceField);
price.setPreferredSize(new Dimension(200, 50));
p.add(price);
JPanel weight = new JPanel();
JLabel weightLabel = new JLabel();
weightField = new JTextField();
weight.setLayout(new BoxLayout(weight, BoxLayout.X_AXIS));
weightLabel.setText("weight:");
weightLabel.setPreferredSize(new Dimension(50, 25));
weight.add(weightLabel);
weight.add(weightField);
weight.setPreferredSize(new Dimension(200, 50));
p.add(weight);
JPanel date = new JPanel();
JLabel dateLabel = new JLabel();
dateField = new JTextField();
date.setLayout(new BoxLayout(date, BoxLayout.X_AXIS));
dateLabel.setText("date:");
dateLabel.setPreferredSize(new Dimension(50, 25));
dd=new DateTimePicker();
dd.addDateTimeChangeListener(this);
date.add(dateLabel);
date.add(dd);
date.setPreferredSize(new Dimension(200, 50));
p.add(date);
typePanel=new JPanel();
typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.X_AXIS));
typeLabel=new JLabel();
typeLabel.setText("author:");
typeLabel.setPreferredSize(new Dimension(50, 25));
typeTf=new JTextField();
typePanel.add(typeLabel);
typePanel.add(typeTf);
typePanel.setPreferredSize(new Dimension(200, 50));
ed=new DateTimePicker();
p.add(typePanel);
JPanel actionButton = new JPanel();
actionButton.setLayout(new BoxLayout(actionButton, BoxLayout.X_AXIS));
JButton ok=new JButton("ok");
JButton cancel=new JButton("cancel");
ok.addActionListener(this);
cancel.addActionListener(this);
actionButton.add(ok);
actionButton.add(cancel);
p.add(actionButton);
// Dialog box dimensions
getContentPane().setSize(500, 500);
getContentPane().add(p);
pack();
this.setVisible(true);
}
@Override
public void dateOrTimeChanged(DateTimeChangeEvent dateTimeChangeEvent) {
deliveryDate=dd.getDateTimePermissive();
}
@Override
public void actionPerformed(ActionEvent e) {
String actionString=e.getActionCommand();
switch(actionString){
case "ok":
addPackage();
break;
case "cancel":
this.dispose();
break;
}
}
private void addPackage(){
String pName=nameField.getText();
String pNote=noteField.getText();
double pPrice=Double.parseDouble(priceField.getText());
double pWeight=Double.parseDouble(weightField.getText());
String pAuthor="";
double pHandlingFee=0.0;
if (pType==0){
pAuthor= typeTf.getText();
if (pAuthor.equals("")){
JOptionPane.showMessageDialog(this, "author name can not be empty", "error", JOptionPane.WARNING_MESSAGE);
return;
}
}
else if (pType==1){
pHandlingFee = Double.parseDouble(typeTf.getText());
if (pHandlingFee<=0){
JOptionPane.showMessageDialog(this, "Handling fee should be positive", "error", JOptionPane.WARNING_MESSAGE);
}
}
}
}

Loading…
Cancel
Save