Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*; //for listeners
- public class QuoteGUI implements ActionListener
- {
- static JFrame mainWindow = new JFrame("Quick Cars Quote Generator");
- //create main window
- JTabbedPane systemTabs = new JTabbedPane();
- //make the tabs
- JPanel loginPanel = new JPanel();
- JPanel quotesPanel = new JPanel();
- //making the panels that will fill the tab
- JLabel loginLabel = new JLabel("Quick Cars");
- //this is under the first tab, loginPanel
- JLabel loginTitleLabel = new JLabel("Enter Username and Password to log in:");
- //this is the title of the tab, loginpanel
- JLabel usernameLabel = new JLabel("Username");
- JLabel passwordLabel = new JLabel("Password");
- JTextField username = new JTextField("Username");
- //this is the textfield where the user enters their username
- JTextField password = new JTextField("Password");
- //this is the textfield where the user enters their password
- JButton login = new JButton("Login");
- //this is the button that logs the user in
- JLabel quotesLabel = new JLabel("Quick Cars");
- //this is under the second tab, quotesPanel
- JLabel quotesTitleLabel = new JLabel("Options");
- JLabel quotesCustomerLabel = new JLabel("Enter Customer Data");
- JLabel quotesCarLabel = new JLabel("Enter Car Data");
- JLabel quotesPaymentLabel = new JLabel("Enter Loan Data");
- JButton logout = new JButton("Logout");
- //this will log the user out
- public void runBasicGUI()
- {
- //start of generic GUI code
- Toolkit theKit = mainWindow.getToolkit();
- Dimension wndSize=theKit.getScreenSize();
- mainWindow.setBounds(10, 10, wndSize.width/2, 1000);
- //set positions then dimensions
- mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //tells the program to end when the X is pressed
- GridLayout grid = new GridLayout(1,1);
- Container content = mainWindow.getContentPane();
- content.setLayout(grid);
- //end of generic GUI code
- createloginPanel();
- createquotesPanel();
- //calls the method that creates the panels
- systemTabs.addTab("Login", loginPanel);
- systemTabs.addTab("Quotes", quotesPanel);
- //adds the panels to the tabs
- systemTabs.setSelectedIndex(0);
- //sets the tab to be selected
- systemTabs.setEnabledAt(1,false);
- //disables the tab
- content.add(systemTabs);
- mainWindow.setVisible(true);
- }
- public void createloginPanel()
- {
- loginPanel.setLayout(null);
- loginLabel.setBounds(250, 10, 500, 40); //sets the bounds of the various components: x pos, y pos, x size, y size
- loginTitleLabel.setBounds(250, 100, 500, 30);
- usernameLabel.setBounds(150, 150, 100, 30);
- username.setBounds(250, 150, 200, 30);
- passwordLabel.setBounds(150, 200, 100, 30);
- password.setBounds(250, 200, 200, 30);
- login.setBounds(250, 250, 100, 25);
- login.addActionListener(this); //add a listener to the button
- loginPanel.add(loginLabel); //adds the components to the panel
- loginPanel.add(loginTitleLabel);
- loginPanel.add(usernameLabel);
- loginPanel.add(username);
- loginPanel.add(passwordLabel);
- loginPanel.add(password);
- loginPanel.add(login);
- }
- public void createquotesPanel()
- {
- quotesPanel.setLayout(null);
- quotesLabel.setBounds(250, 25, 500, 25);
- quotesTitleLabel.setBounds(20, 100, 500, 25);
- quotesCustomerLabel.setBounds(20, 300, 500, 25);
- quotesCarLabel.setBounds(20, 500, 500, 25);
- quotesPaymentLabel.setBounds(20, 700, 500, 25);
- logout.setBounds(450, 10, 100, 25);
- logout.addActionListener(this); //adds a listener to the button
- quotesPanel.add(quotesLabel);
- quotesPanel.add(logout);
- quotesPanel.add(quotesTitleLabel);
- quotesPanel.add(quotesCustomerLabel);
- quotesPanel.add(quotesCarLabel);
- quotesPanel.add(quotesPaymentLabel);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource() == login)
- {
- String un = username.getText();
- String pw = password.getText();
- if (un.equals("quickcars") && pw.equals("12345"))
- {
- systemTabs.setEnabledAt(1,true);
- systemTabs.setSelectedIndex(1);
- systemTabs.setEnabledAt(0, false);
- }
- }
- if (e.getSource() == logout)
- {
- systemTabs.setEnabledAt(0, true);
- systemTabs.setEnabledAt(1, false);
- systemTabs.setSelectedIndex(0);
- }
- }
- public static void main(String[] args)
- {
- QuoteGUI qg = new QuoteGUI();
- qg.runBasicGUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement