mirror of
https://github.com/danog/WarehouseClient.git
synced 2024-11-30 04:29:06 +01:00
First public version
This commit is contained in:
commit
f3171781e3
73
build.xml
Normal file
73
build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="WarehouseClient" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project WarehouseClient.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="WarehouseClient-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
1420
nbproject/build-impl.xml
Normal file
1420
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=2973ab54
|
||||
build.xml.script.CRC32=905fd709
|
||||
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=2973ab54
|
||||
nbproject/build-impl.xml.script.CRC32=9958223d
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
|
81
nbproject/project.properties
Normal file
81
nbproject/project.properties
Normal file
@ -0,0 +1,81 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=WarehouseClient
|
||||
application.vendor=root
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/WarehouseClient.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.HTTP.jar=/root/NetBeansProjects/HTTPPayloads/dist/HTTP.jar
|
||||
file.reference.WarehouseLibrary.jar=/root/NetBeansProjects/WarehouseLibrary/dist/WarehouseLibrary.jar
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.WarehouseLibrary.jar}:\
|
||||
${file.reference.HTTP.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=warehouseclient.WarehouseClient
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
project.license=gpl30
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
16
nbproject/project.xml
Normal file
16
nbproject/project.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>WarehouseClient</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1"/>
|
||||
</configuration>
|
||||
</project>
|
56
src/ui/CheckoutButton.java
Normal file
56
src/ui/CheckoutButton.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import Main.Client;
|
||||
import Main.ClientException;
|
||||
import Payloads.ServerException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class CheckoutButton extends JButton implements ActionListener {
|
||||
private Client client;
|
||||
public CheckoutButton(Client client) {
|
||||
super("Checkout");
|
||||
this.client = client;
|
||||
this.addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
client.commit();
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null, ex.getMessage(), "Errore I/O", ERROR_MESSAGE);
|
||||
} catch (ServerException ex) {
|
||||
JOptionPane.showMessageDialog(null, String.format("%d: %s", ex.getPayload().getResponseCode(), ex.getPayload().getResponseDescription()), "Errore del server", ERROR_MESSAGE);
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "OK!");
|
||||
}
|
||||
}
|
62
src/ui/TableButton.java
Normal file
62
src/ui/TableButton.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import Main.Client;
|
||||
import Main.ClientException;
|
||||
import Main.Container;
|
||||
import Main.Warehouse;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class TableButton extends JButton {
|
||||
private Boolean isWarehouse = true;
|
||||
private Client client;
|
||||
public TableButton(Boolean isWarehouse, Client client) {
|
||||
super();
|
||||
this.isWarehouse = isWarehouse;
|
||||
this.client = client;
|
||||
this.setText(isWarehouse ? "Buy" : "Remove");
|
||||
}
|
||||
|
||||
public void press(Integer productID) {
|
||||
try {
|
||||
if (isWarehouse) {
|
||||
client.addToCart(productID);
|
||||
} else {
|
||||
client.removeFromCart(productID);
|
||||
}
|
||||
} catch (ClientException ex) {
|
||||
JOptionPane.showMessageDialog(this, ex.getMessage(), "Errore", ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
src/ui/TableButtonRenderer.java
Normal file
33
src/ui/TableButtonRenderer.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class TableButtonRenderer implements TableCellRenderer {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
return (JButton) value;
|
||||
}
|
||||
}
|
78
src/ui/TableModel.java
Normal file
78
src/ui/TableModel.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import Main.Client;
|
||||
import Main.Container;
|
||||
import Main.Warehouse;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class TableModel extends AbstractTableModel {
|
||||
private String[] columnNames = new String [] {"ID", "Description", "Price", "Count", "Buy"};
|
||||
private final Container container;
|
||||
private final TableButton button;
|
||||
|
||||
TableModel(Client client, Container container) {
|
||||
Boolean isWarehouse = container instanceof Warehouse;
|
||||
this.columnNames[4] = isWarehouse ? "Buy" : "Remove";
|
||||
this.container = container;
|
||||
this.button = new TableButton(isWarehouse, client);
|
||||
}
|
||||
public TableButton getButton() {
|
||||
return button;
|
||||
}
|
||||
/*
|
||||
Table model methods
|
||||
*/
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return container.getProductCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return this.columnNames.length;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getColumnName(int col) {
|
||||
return columnNames[col];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return container.getNthProductCollection(rowIndex).getID();
|
||||
case 1:
|
||||
return container.getNthProductCollection(rowIndex).getDescription();
|
||||
case 2:
|
||||
return container.getNthProductCollection(rowIndex).getPrice();
|
||||
case 3:
|
||||
return container.getNthProductCollection(rowIndex).getCount();
|
||||
case 4:
|
||||
return button;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
47
src/ui/TableMouseListener.java
Normal file
47
src/ui/TableMouseListener.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.JTable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class TableMouseListener extends MouseAdapter {
|
||||
private final JTable table;
|
||||
|
||||
public TableMouseListener(JTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int column = table.getColumnModel().getColumnIndexAtX(e.getX()); // get the coloum of the button
|
||||
int row = e.getY() / table.getRowHeight(); //get the row of the button
|
||||
System.out.println("got");
|
||||
/*Checking the row or column is valid or not*/
|
||||
if (row < table.getRowCount() && row >= 0 && column < table.getColumnCount() && column >= 0) {
|
||||
Object value = table.getValueAt(row, column);
|
||||
if (value instanceof TableButton) {
|
||||
((TableButton) value).press((Integer) table.getValueAt(row, 0));
|
||||
table.getRootPane().repaint(); // Redraw all tables
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
src/ui/TableScrollPane.java
Normal file
67
src/ui/TableScrollPane.java
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ui;
|
||||
|
||||
import Main.Client;
|
||||
import Main.Container;
|
||||
import java.awt.Dimension;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class TableScrollPane extends JScrollPane {
|
||||
public TableScrollPane(Client client, Container container) {
|
||||
super();
|
||||
final JTable table = new JTable(new TableModel(client, container));
|
||||
final TableCellRenderer renderer = new TableButtonRenderer();
|
||||
final TableMouseListener listener = new TableMouseListener(table);
|
||||
table.setRowHeight(30);
|
||||
TableColumn column;
|
||||
for (int i = 0; i < table.getColumnCount(); i++) {
|
||||
column = table.getColumnModel().getColumn(i);
|
||||
switch (i) {
|
||||
case 1:
|
||||
column.setPreferredWidth(150); // second column is bigger
|
||||
break;
|
||||
case 4:
|
||||
column.setPreferredWidth(30); // second column is bigger
|
||||
column.setCellRenderer(renderer);
|
||||
break;
|
||||
default:
|
||||
column.setPreferredWidth(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
|
||||
table.setFillsViewportHeight(true);
|
||||
table.addMouseListener(listener);
|
||||
|
||||
this.setBorder(BorderFactory.createTitledBorder (BorderFactory.createEtchedBorder (),
|
||||
container.getClass().getSimpleName(),
|
||||
TitledBorder.CENTER,
|
||||
TitledBorder.TOP));
|
||||
|
||||
this.setViewportView(table);
|
||||
}
|
||||
}
|
85
src/warehouseclient/WarehouseClient.java
Normal file
85
src/warehouseclient/WarehouseClient.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package warehouseclient;
|
||||
|
||||
import Main.Client;
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import ui.CheckoutButton;
|
||||
import ui.TableScrollPane;
|
||||
/**
|
||||
*
|
||||
* @author Studente
|
||||
*/
|
||||
public class WarehouseClient {
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
public static void createAndShowGUI(Client client) {
|
||||
JFrame frame = new JFrame("Client");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.add(new CheckoutButton(client), BorderLayout.CENTER);
|
||||
|
||||
frame.getContentPane().add(new TableScrollPane(client, client.getWarehouse()),BorderLayout.PAGE_START);
|
||||
frame.getContentPane().add(new TableScrollPane(client, client.getCart()),BorderLayout.CENTER );
|
||||
frame.getContentPane().add(panel, BorderLayout.PAGE_END);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(WarehouseClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(WarehouseClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(WarehouseClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(WarehouseClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
createAndShowGUI(new Client("localhost", 9090));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(WarehouseClient.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user