Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tudlonisir;
  7. import java.awt.Color;
  8. import java.text.DecimalFormat;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11. /**
  12. *
  13. * @author college36
  14. */
  15. public class TudloNISir {
  16. private static final DecimalFormat df2 = new DecimalFormat("#.##");
  17. /**
  18. * @param args the command line arguments
  19. */
  20.  
  21. public static JTextField TfSelectedP = new JTextField();
  22. public static JTextField TfPrice = new JTextField();
  23. public static JTextField TfQuantity = new JTextField();
  24. public static JTextField TfPayment = new JTextField();
  25.  
  26. public static void maoNi( String pro, double prc){
  27.  
  28. String m = JOptionPane.showInputDialog("Enter Quantity: (10 is the maximum)");
  29. Double number = Double.parseDouble(m);
  30. double price1 = prc;
  31. double max = 10;
  32. if(number <= max)
  33. {
  34. double totalpay = price1 * number;
  35. TfSelectedP.setText(""+ pro);
  36. TfPrice.setText("" + price1);
  37. TfQuantity.setText("" + number);
  38. TfPayment.setText("" + totalpay);
  39. }
  40. else
  41. {
  42. JOptionPane.showMessageDialog(null, "I said 10 is the Maximum",
  43. "Hey!", JOptionPane.ERROR_MESSAGE);
  44. }
  45.  
  46. }
  47.  
  48.  
  49. public static void main(String[] args) {
  50. // TODO code application logic here
  51.  
  52. JFrame jf = new JFrame();
  53.  
  54. jf.setVisible(true);
  55. jf.setSize(800, 600);
  56. jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57. jf.setLocationRelativeTo(null);
  58. jf.setLayout(null);
  59.  
  60.  
  61. JButton coke = new JButton();
  62. JButton jazz = new JButton();
  63. JButton sprite = new JButton();
  64. JButton seven_up = new JButton();
  65. JButton fanta = new JButton();
  66. JButton summit = new JButton();
  67. JButton pepsi = new JButton();
  68. JButton sparkle = new JButton();
  69.  
  70. JLabel Select_Pro = new JLabel();
  71. JLabel Selected_Pro = new JLabel();
  72. JLabel price = new JLabel();
  73. JLabel Selected_Quan = new JLabel();
  74. JLabel Total = new JLabel();
  75. JLabel PriceL = new JLabel();
  76. JLabel coke1 = new JLabel();
  77. JLabel sprite1 = new JLabel();
  78. JLabel fanta1 = new JLabel();
  79. JLabel pepsi1 = new JLabel();
  80.  
  81.  
  82. jf.add(Select_Pro);
  83. Select_Pro.setText("SELECT PRODUCT");
  84. Select_Pro.setBounds(180, 25, 180, 100);
  85.  
  86. jf.add(Selected_Pro);
  87. Selected_Pro.setText("SELECTED PRODUCT:");
  88. Selected_Pro.setBounds(500, 25, 180, 100);
  89. jf.add(TfSelectedP);
  90. TfSelectedP.setBounds(450, 100, 230, 25);
  91.  
  92.  
  93. jf.add(price);
  94. price.setText("PRICE:");
  95. price.setBounds(540, 90, 180, 100);
  96. jf.add(TfPrice);
  97. TfPrice.setBounds(450, 155, 230, 25);
  98.  
  99. jf.add(Selected_Quan);
  100. Selected_Quan.setText("SELECTED QUANTITY:");
  101. Selected_Quan.setBounds(500, 145, 180, 100);
  102. jf.add(TfQuantity);
  103. TfQuantity.setBounds(450, 210, 230, 25);
  104.  
  105. jf.add(Total);
  106. Total.setText("TOTAL PAYMENT:");
  107. Total.setBounds(515, 200, 180, 100);
  108. jf.add(TfPayment);
  109. TfPayment.setBounds(450, 265, 230, 25);
  110.  
  111. jf.add(coke);
  112. coke.setText("COKE");
  113. coke.setBounds(50, 100, 180, 25);
  114. coke.setBackground(Color.red);
  115.  
  116. jf.add(jazz);
  117. jazz.setText("JAZZ");
  118. jazz.setBounds(231, 100, 180, 25);
  119. jazz.setBackground(Color.pink);
  120.  
  121. jf.add(sprite);
  122. sprite.setText("SPRITE");
  123. sprite.setBounds(50, 126, 180, 25);
  124. sprite.setBackground(Color.green);
  125.  
  126. jf.add(seven_up);
  127. seven_up.setText("7 UP");
  128. seven_up.setBounds(231, 126, 180, 25);
  129. seven_up.setBackground(Color.pink);
  130.  
  131. jf.add(fanta);
  132. fanta.setText("FANTA");
  133. fanta.setBounds(50, 152, 180, 25);
  134. fanta.setBackground(Color.orange);
  135.  
  136. jf.add(summit);
  137. summit.setText("SUMMIT");
  138. summit.setBounds(231, 152, 180, 25);
  139. summit.setBackground(Color.blue);
  140. summit.setForeground(Color.white);
  141.  
  142. jf.add(pepsi);
  143. pepsi.setText("PEPSI");
  144. pepsi.setBounds(50, 178, 180, 25);
  145. pepsi.setBackground(Color.BLUE);
  146. pepsi.setForeground(Color.white);
  147.  
  148. jf.add(sparkle);
  149. sparkle.setText("SPARKLE");
  150. sparkle.setBounds(231, 178, 180, 25);
  151. sparkle.setBackground(Color.yellow);
  152.  
  153.  
  154. jf.add(PriceL);
  155. PriceL.setText(" PRICE LIST");
  156. PriceL.setBounds(203, 210, 180, 25);
  157.  
  158. jf.add(coke1);
  159. coke1.setText("COKE = Php 12.00 JAZZ = Php 8.00");
  160. coke1.setBounds(120, 230, 300, 25);
  161.  
  162. jf.add(sprite1);
  163. sprite1.setText(" SPRITE = Php 11.00 7 UP = Php 9.00");
  164. sprite1.setBounds(117, 250, 300, 25);
  165.  
  166. jf.add(fanta1);
  167. fanta1.setText(" FANTA = Php 11.00 SUMMIT = Php 10.00");
  168. fanta1.setBounds(117, 270, 300, 25);
  169.  
  170. jf.add(pepsi1);
  171. pepsi1.setText(" PEPSI = Php 12.00 SPARKLE = Php 8.00");
  172. pepsi1.setBounds(117, 290, 300, 25);
  173.  
  174.  
  175. coke.addActionListener((ActionEvent e) -> {
  176.  
  177. maoNi("COKE", 12.00);
  178.  
  179. });
  180.  
  181. jazz.addActionListener((ActionEvent e) -> {
  182. maoNi("JAZZ", 8.00);
  183. });
  184.  
  185. sprite.addActionListener((ActionEvent e) -> {
  186. maoNi("SPRITE", 11.00);
  187. });
  188.  
  189. seven_up.addActionListener((ActionEvent e) -> {
  190. maoNi("SEVEN UP", 9.00);
  191. });
  192.  
  193. fanta.addActionListener((ActionEvent e) -> {
  194. maoNi("FANTA", 11.00);
  195. });
  196.  
  197. summit.addActionListener((ActionEvent e) -> {
  198. maoNi("SUMMIT", 10.00);
  199. });
  200.  
  201. pepsi.addActionListener((ActionEvent e) -> {
  202. maoNi("PEPSI", 12.00);
  203. });
  204.  
  205. sparkle.addActionListener((ActionEvent e) -> {
  206. maoNi("SPARKLE", 8.00);
  207. });
  208.  
  209. }
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement