Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3.  
  4. import javax.swing.*;
  5.  
  6. public class Costam
  7. {
  8.  
  9. static int postcode;
  10. static int amount = 29;
  11. static int bill;
  12.  
  13. static final JFrame frame = new JFrame();
  14. static final JLabel name = new JLabel();
  15. static final JFormattedTextField postcodeField = new JFormattedTextField(new Integer(0));
  16. static final JButton startShopping = new JButton("startShopping");
  17.  
  18. static void Costam()
  19. {
  20. frame.setTitle("Costam");
  21. frame.setSize(800, 600);
  22. frame.setLocationRelativeTo(null);
  23. frame.setLayout(null);
  24.  
  25.  
  26. name.setText("Welcome to ...");
  27. name.setBounds(100, 100, 200, 20);
  28. frame.add(name);
  29. name.setVisible(true);
  30. }
  31.  
  32. static void screen1 (Boolean flag)
  33. {
  34. name.setVisible(flag);
  35. postcodeField.setVisible(flag);
  36. startShopping.setVisible(flag);
  37. }
  38.  
  39.  
  40.  
  41. public static void main(String[] args)
  42. {
  43. frame.setTitle("Costam");
  44. frame.setSize(800, 600);
  45. frame.setLocationRelativeTo(null);
  46. frame.setLayout(null);
  47.  
  48.  
  49. name.setText("Welcome to ...");
  50. name.setBounds(100, 100, 200, 20);
  51. frame.add(name);
  52. name.setVisible(true);
  53.  
  54. postcodeField.setBounds(100, 300, 200, 20);
  55. postcodeField.setText(null);
  56. frame.add(postcodeField);
  57. postcodeField.setVisible(true);
  58.  
  59. final JLabel products = new JLabel();
  60. products.setText("Products");
  61. products.setBounds(100, 100, 200, 20);
  62. frame.add(products);
  63. products.setVisible(false);
  64.  
  65. final JLabel output = new JLabel();
  66. output.setBounds(100, 200, 200, 20);
  67. frame.add(output);
  68. output.setVisible(false);
  69.  
  70. startShopping.setBounds(100, 200, 200, 20);
  71. startShopping.addActionListener(new ActionListener()
  72. {
  73.  
  74. @Override
  75. public void actionPerformed(ActionEvent e)
  76. {
  77. screen1(false);
  78. postcode = (int) postcodeField.getValue();
  79. System.out.println(postcode);
  80. products.setVisible(true);
  81.  
  82. bill = postcode * amount;
  83. output.setText(Integer.toString(bill));
  84. output.setVisible(true);
  85.  
  86. }
  87. });
  88. frame.add(startShopping);
  89. startShopping.setVisible(true);
  90.  
  91.  
  92.  
  93.  
  94.  
  95. frame.setVisible(true);
  96.  
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement