Newer
Older
POS_for_GUI / src / frames / MainFrame.java
student on 11 Apr 2022 2 KB [update]detail panel
package frames;

import java.awt.BorderLayout;
import java.util.HashMap;

import javax.swing.JFrame;
import javax.swing.JPanel;

import panels.*;
import resources.Customer;
import resources.CustomersModel;

//-------------------------------------------------------------------------
// 
public class MainFrame extends JFrame implements IMainFrame {

	// field
	private State state;
	
	// model
	private CustomersModel model;

	// panel
	private JPanel curPanel;

	// cache
	private MainPanel mainPanel;
	private ShowHistoryPanel historyPanel;

	// -------------------------------------------------------------------------
	// -------------------------------------------------------------------------
	// constructor
	// -------------------------------------------------------------------------
	//
	public MainFrame() {
		super("POS");

		this.setTitle("POS");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// initialize model
		model = new CustomersModel();
		
		// initialize Panels
		mainPanel = new MainPanel(this, model);
		historyPanel = new ShowHistoryPanel(this, model);

		// set visible
		historyPanel.setVisible(false);
		this.add(historyPanel, BorderLayout.CENTER);

		mainPanel.setVisible(true);
		this.add(mainPanel, BorderLayout.CENTER);
		
		// set current panel
		curPanel = mainPanel;
		
		// adjust window size
		this.pack();
		this.setVisible(true);
	}

	// -------------------------------------------------------------------------
	// -------------------------------------------------------------------------
	// public
	// -------------------------------------------------------------------------
	//
	public void reloadPanel(String destinationPanelName) {
		// main
		if (destinationPanelName.equals(State.MAIN)) {
			this.remove(this.mainPanel);
			MainPanel mainPanel = new MainPanel(this, model);
			this.add(mainPanel);
		}
		// history
		else if (destinationPanelName.equals(State.DETAIL)) {
			this.remove(this.historyPanel);
			ShowHistoryPanel historyPanel = new ShowHistoryPanel(this, model);
			this.add(historyPanel);
		}
	}

	// -------------------------------------------------------------------------
	// 
	public void showMainPanel(JPanel nowPanel) {
		getContentPane().removeAll();
		
		mainPanel.updateTableByTransition();
		
		add(mainPanel);
		validate();
		repaint();
	}

	// -------------------------------------------------------------------------
	//
	public void showHistoryPanel(JPanel nowPanel, int index) {
		getContentPane().removeAll();
		
		historyPanel.setVisible(true);
		historyPanel.updateListModelByIndex(index);		
		
		add(historyPanel);
		validate();
		repaint();
	}
}