Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*; //for listeners
  4.  
  5. public class QuoteGUI implements ActionListener
  6. {
  7. static JFrame mainWindow = new JFrame("Quick Cars Quote Generator");
  8. //create main window
  9.  
  10. JTabbedPane systemTabs = new JTabbedPane();
  11. //make the tabs
  12.  
  13. JPanel loginPanel = new JPanel();
  14. JPanel quotesPanel = new JPanel();
  15. //making the panels that will fill the tab
  16.  
  17. JLabel loginLabel = new JLabel("Quick Cars");
  18. //this is under the first tab, loginPanel
  19. JLabel loginTitleLabel = new JLabel("Enter Username and Password to log in:");
  20. //this is the title of the tab, loginpanel
  21. JLabel usernameLabel = new JLabel("Username");
  22. JLabel passwordLabel = new JLabel("Password");
  23. JTextField username = new JTextField("Username");
  24. //this is the textfield where the user enters their username
  25. JTextField password = new JTextField("Password");
  26. //this is the textfield where the user enters their password
  27. JButton login = new JButton("Login");
  28. //this is the button that logs the user in
  29.  
  30. JLabel quotesLabel = new JLabel("Quick Cars");
  31. //this is under the second tab, quotesPanel
  32. JLabel quotesTitleLabel = new JLabel("Options");
  33. JLabel quotesCustomerLabel = new JLabel("Enter Customer Data");
  34. JLabel quotesCarLabel = new JLabel("Enter Car Data");
  35. JLabel quotesPaymentLabel = new JLabel("Enter Loan Data");
  36.  
  37. JButton logout = new JButton("Logout");
  38. //this will log the user out
  39.  
  40. public void runBasicGUI()
  41. {
  42. //start of generic GUI code
  43. Toolkit theKit = mainWindow.getToolkit();
  44. Dimension wndSize=theKit.getScreenSize();
  45.  
  46. mainWindow.setBounds(10, 10, wndSize.width/2, 1000);
  47. //set positions then dimensions
  48. mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49. //tells the program to end when the X is pressed
  50.  
  51. GridLayout grid = new GridLayout(1,1);
  52. Container content = mainWindow.getContentPane();
  53. content.setLayout(grid);
  54. //end of generic GUI code
  55.  
  56. createloginPanel();
  57. createquotesPanel();
  58. //calls the method that creates the panels
  59.  
  60. systemTabs.addTab("Login", loginPanel);
  61. systemTabs.addTab("Quotes", quotesPanel);
  62. //adds the panels to the tabs
  63.  
  64. systemTabs.setSelectedIndex(0);
  65. //sets the tab to be selected
  66. systemTabs.setEnabledAt(1,false);
  67. //disables the tab
  68.  
  69. content.add(systemTabs);
  70.  
  71. mainWindow.setVisible(true);
  72. }
  73.  
  74. public void createloginPanel()
  75. {
  76. loginPanel.setLayout(null);
  77. loginLabel.setBounds(250, 10, 500, 40); //sets the bounds of the various components: x pos, y pos, x size, y size
  78. loginTitleLabel.setBounds(250, 100, 500, 30);
  79. usernameLabel.setBounds(150, 150, 100, 30);
  80. username.setBounds(250, 150, 200, 30);
  81. passwordLabel.setBounds(150, 200, 100, 30);
  82. password.setBounds(250, 200, 200, 30);
  83. login.setBounds(250, 250, 100, 25);
  84. login.addActionListener(this); //add a listener to the button
  85.  
  86. loginPanel.add(loginLabel); //adds the components to the panel
  87. loginPanel.add(loginTitleLabel);
  88. loginPanel.add(usernameLabel);
  89. loginPanel.add(username);
  90. loginPanel.add(passwordLabel);
  91. loginPanel.add(password);
  92. loginPanel.add(login);
  93. }
  94.  
  95. public void createquotesPanel()
  96. {
  97. quotesPanel.setLayout(null);
  98. quotesLabel.setBounds(250, 25, 500, 25);
  99. quotesTitleLabel.setBounds(20, 100, 500, 25);
  100. quotesCustomerLabel.setBounds(20, 300, 500, 25);
  101. quotesCarLabel.setBounds(20, 500, 500, 25);
  102. quotesPaymentLabel.setBounds(20, 700, 500, 25);
  103.  
  104. logout.setBounds(450, 10, 100, 25);
  105. logout.addActionListener(this); //adds a listener to the button
  106.  
  107. quotesPanel.add(quotesLabel);
  108. quotesPanel.add(logout);
  109. quotesPanel.add(quotesTitleLabel);
  110. quotesPanel.add(quotesCustomerLabel);
  111. quotesPanel.add(quotesCarLabel);
  112. quotesPanel.add(quotesPaymentLabel);
  113. }
  114.  
  115. public void actionPerformed(ActionEvent e)
  116. {
  117. if(e.getSource() == login)
  118. {
  119. String un = username.getText();
  120. String pw = password.getText();
  121.  
  122. if (un.equals("quickcars") && pw.equals("12345"))
  123. {
  124. systemTabs.setEnabledAt(1,true);
  125. systemTabs.setSelectedIndex(1);
  126. systemTabs.setEnabledAt(0, false);
  127. }
  128. }
  129.  
  130. if (e.getSource() == logout)
  131. {
  132. systemTabs.setEnabledAt(0, true);
  133. systemTabs.setEnabledAt(1, false);
  134. systemTabs.setSelectedIndex(0);
  135. }
  136. }
  137.  
  138. public static void main(String[] args)
  139. {
  140. QuoteGUI qg = new QuoteGUI();
  141. qg.runBasicGUI();
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement