Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Panel;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import java.sql.Date;
- import java.time.LocalDate;
- import java.time.LocalTime;
- import java.util.ArrayList;
- import java.util.List;
- public class SC1072771 {
- int i;
- public static Shop shop;
- public static Buyer buyer;
- public static void main(String[] args) {
- //INSTANCES NO TIME
- userInterface GUI = new userInterface(shop, buyer);
- }
- }
- class Shop{
- List<Request> visitReqBox = new ArrayList<Request>();
- private int deleted = 0;
- public void receiveRequest(Request request) {
- if (visitReqBox.size() != 0) {
- visitReqBox.remove(visitReqBox.size() - 1);
- deleted++;
- System.out.println(deleted);
- }
- visitReqBox.add(request);
- System.out.println("Request with ID " + visitReqBox.get(0).details());
- }
- }
- class Buyer{
- public Request createReq(int i, int buyers) {
- Request req = new Request(LocalDate.now(), LocalTime.now(), i, buyers);
- return req;
- }
- }
- class Request{
- LocalDate date;
- LocalTime time;
- int ID, buyers;
- public Request(LocalDate date, LocalTime time, int ID, int buyers) {
- this.date = date;
- this.time = time;
- this.ID = ID;
- this.buyers = buyers;
- }
- public String details() {
- return ("Request ID: "+this.ID+", " + this.buyers + "buyers, with timestamp: " +
- this.date + this.time);
- }
- }
- @SuppressWarnings("serial")
- class userInterface extends Frame {
- private static TextField display;
- public static Shop shop;
- public static Buyer buyer;
- final Button buttonShop, buttonBuyer, buttonStart;
- public userInterface(Shop shop, Buyer buyer) {
- userInterface.shop = shop;
- userInterface.buyer = buyer;
- new Frame("Click Away 2021");
- setLayout(null);
- setBackground(Color.red);
- buttonShop = new Button("Shop");
- buttonShop.setBounds(50,100,50,30);
- buttonShop.setForeground(Color.blue);
- buttonShop.addActionListener(new ButtonHandler("Shop"));
- buttonBuyer = new Button("Buyer");
- buttonBuyer.setBounds(50,190,50,30);
- buttonBuyer.setForeground(Color.blue);
- buttonBuyer.addActionListener(new ButtonHandler("Buyer"));
- buttonStart = new Button("Start");
- buttonStart.setBounds(50,150,50,30);
- buttonStart.setForeground(Color.blue);
- buttonStart.addActionListener(new ButtonHandler("Start"));
- add(buttonShop);
- add(buttonBuyer);
- add(buttonStart);
- display = new TextField("0");
- display.setEditable(false);
- display.setBounds(13, 55, 370, 30);
- add(display);
- setSize(400, 300);
- setLocation(40, 80);
- setVisible(true);
- setResizable(false);
- addWindowListener(new CloseWindowAndExit());
- }
- }
- class CloseWindowAndExit extends WindowAdapter {
- public void windowClosing(WindowEvent closeWindowAndExit) {
- System.exit(0);
- }
- }
- class ButtonHandler implements ActionListener {
- int i=0;
- Shop shop;
- Buyer buyer;
- String key;
- public ButtonHandler(String key) {
- this.key = key;
- }
- public void actionPerformed(ActionEvent pushingButton) {
- switch (this.key) {
- case "Shop":
- this.shop = new Shop();
- break;
- case "Buyer":
- this.buyer = new Buyer());
- break;
- case "Start":
- for (int j=0; j<40;j++) {
- this.shop(Buyer.createRequest(++i,3));
- System.out.println(this.shop.visitReqBox.get(0).details());
- }
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment