Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class UI here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.JScrollPane;
- import java.awt.CardLayout;
- import javax.swing.table.DefaultTableModel;
- public class UI implements ItemListener
- {
- JPanel cards;
- final static String BUTTONPANEL = "View Inventory";
- final static String TEXTPANEL = "Add Inventory";
- final static String LOGIN = "Login";
- String passwordM = "test";
- String itemName = "";
- String priceNum = "";
- String quantityNum = "";
- DefaultTableModel tableSet;
- public void addComponentToPane(Container pane)
- {
- JPanel comboBoxPane = new JPanel();
- JTabbedPane tabbedPane = new JTabbedPane();
- JButton add = new JButton("ADD");
- JButton login = new JButton("LOGIN");
- JTextField item = new JTextField("", 20);
- JTextField price = new JTextField("", 20);
- JTextField quantity = new JTextField("", 20);
- JTextField user = new JTextField("", 20);
- JTextField pass = new JTextField("", 20);
- JPanel card = new JPanel();
- String comboBoxItems[] = {BUTTONPANEL, TEXTPANEL, LOGIN};
- JComboBox cb = new JComboBox(comboBoxItems);
- cb.setEditable(false);
- cb.addItemListener(this);
- comboBoxPane.add(cb);
- //creating the card
- card.add(new Label("Login: "));
- card.add(user);
- card.add(pass);
- card.add(login);
- JPanel card1 = new JPanel();
- JPanel card2 = new JPanel();
- card2.add(new JLabel("ITEM"));
- card2.add(item);
- card2.add(new JLabel("PRICE"));
- card2.add(price);
- card2.add(new JLabel("QUANTITY"));
- card2.add(quantity);
- card2.add(add);
- JPanel card3 = new JPanel();
- card3.add(new JTextField("WRITE",20));
- tabbedPane.addTab(LOGIN, card);
- tabbedPane.addTab(BUTTONPANEL, card1);
- tabbedPane.addTab(TEXTPANEL, card2);
- //creating the Jtable
- String[] columns = new String[] {
- "Item", "Price", "Quantity"
- };
- //actual data for the table in a 2d array
- Object[][] data = new Object[][] {
- };
- //create table with dataNum
- tableSet = new DefaultTableModel(data, columns);
- JTable table = new JTable(tableSet);
- //add the table to the frame
- card1.add(new JScrollPane(table));
- card1.setVisible(true);
- login.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String username = user.getText();
- String passName = pass.getText();
- if(passName == passwordM)
- {
- card.add(new JLabel("Welcome manager!"));
- }
- else
- {
- card.add(new JLabel("Try again buddy."));
- }
- }
- } );
- add.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- itemName = item.getText();
- priceNum = price.getText();
- quantityNum= quantity.getText();
- tableSet.addRow(new String[] {itemName, priceNum, quantityNum});
- item.setText("");
- price.setText("");
- quantity.setText("");
- }
- } );
- pane.add(tabbedPane, BorderLayout.CENTER);
- }
- public void itemStateChanged(ItemEvent evt) {
- CardLayout cl = (CardLayout)(cards.getLayout());
- cl.show(cards, (String)evt.getItem());
- }
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new JFrame("CardLayoutDemo");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Create and set up the content pane.
- UI demo = new UI();
- //Display the window.
- frame.pack();
- frame.setSize(300,300);
- frame.setVisible(true);
- demo.addComponentToPane(frame.getContentPane());
- //display
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args)
- {
- try {
- UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
- } catch (UnsupportedLookAndFeelException ex) {
- ex.printStackTrace();
- } catch (IllegalAccessException ex) {
- ex.printStackTrace();
- } catch (InstantiationException ex) {
- ex.printStackTrace();
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- }
- /* Turn off metal's use of bold fonts */
- UIManager.put("swing.boldMetal", Boolean.FALSE);
- //Schedule a job for the event dispatch thread:
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment