Guest User

PriceFetcher.java

a guest
Feb 10th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.50 KB | None | 0 0
  1. import java.awt.event.ActionEvent;  
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ItemEvent;
  4. import java.awt.event.ItemListener;
  5. import java.io.IOException;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JCheckBox;
  9. import javax.swing.JComboBox;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.JTextField;
  13.  
  14.  
  15. public class PriceFetcher {
  16.     static boolean StatTrak = false;
  17.     static boolean Souvenir = false;
  18.    
  19.     static double DollarPrice = 0;
  20.     static double EuroPrice = 0;
  21.     static double PoundPrice = 0;
  22.    
  23.     static double DollarTotal = 0;
  24.     static double EuroTotal = 0;
  25.     static double PoundTotal = 0;
  26.    
  27.     public static void main(String[] arg){
  28.        
  29.         final String[] WeaponNames = new String[38];
  30.         WeaponNames[0] = "AK-47";
  31.         WeaponNames[1] = "AUG";
  32.         WeaponNames[2] = "AWP";
  33.         WeaponNames[3] = "Desert Eagle";
  34.         WeaponNames[4] = "Dual Berettas";
  35.         WeaponNames[5] = "FAMAS";
  36.         WeaponNames[6] = "Five-SeveN";
  37.         WeaponNames[7] = "G3SG1";
  38.         WeaponNames[8] = "Galil AR";
  39.         WeaponNames[9] = "Glock-18";
  40.         WeaponNames[10] = "M249";
  41.         WeaponNames[11] = "M4A1-S";
  42.         WeaponNames[12] = "M4A4";
  43.         WeaponNames[13] = "Mac-10";
  44.         WeaponNames[14] = "MAG-7";
  45.         WeaponNames[15] = "MP7";
  46.         WeaponNames[16] = "MP9";
  47.         WeaponNames[17] = "Negev";
  48.         WeaponNames[18] = "Nova";
  49.         WeaponNames[19] = "P2000";
  50.         WeaponNames[20] = "P250";
  51.         WeaponNames[21] = "P90";
  52.         WeaponNames[22] = "PP-Bizon";
  53.         WeaponNames[23] = "Sawed-Off";
  54.         WeaponNames[24] = "SCAR-20";
  55.         WeaponNames[25] = "SSG 08";
  56.         WeaponNames[26] = "SG 553";
  57.         WeaponNames[27] = "Tec-9";
  58.         WeaponNames[28] = "UMP-45";
  59.         WeaponNames[29] = "USP-S";
  60.         WeaponNames[30] = "XM1014";
  61.         WeaponNames[31] = "Bayonet";
  62.         WeaponNames[32] = "M9 Bayonet";
  63.         WeaponNames[33] = "Gut Knife";
  64.         WeaponNames[34] = "Flip Knife";
  65.         WeaponNames[35] = "Case";
  66.         WeaponNames[36] = "Sticker Capsule";
  67.         WeaponNames[37] = "Sticker";
  68.        
  69.         final String[] Qualities = new String[5];
  70.         Qualities[0] = "Factory New";
  71.         Qualities[1] = "Minimal Wear";
  72.         Qualities[2] = "Field-Tested";
  73.         Qualities[3] = "Well-Worn";
  74.         Qualities[4] = "Battle-Scarred";
  75.        
  76.         final String[] StickerQualities = new String[3];
  77.         StickerQualities[0] = "Foil";
  78.         StickerQualities[1] = "Holo";
  79.         StickerQualities[2] = "None";
  80.        
  81.        
  82.         JFrame MainFrame = new JFrame(); // frame and self explanatory frame shit
  83.         MainFrame.setVisible(true);
  84.         MainFrame.setEnabled(true);
  85.         MainFrame.setBounds(0, 0, 340, 150);
  86.         MainFrame.setResizable(false);
  87.         MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  88.         MainFrame.setLayout(null);
  89.        
  90.         final JCheckBox CheckBoxTwo = new JCheckBox("Souvenir");
  91.        
  92.         final JLabel SkinLabel = new JLabel("Skin Name");
  93.         MainFrame.getContentPane().add(SkinLabel);
  94.         SkinLabel.setBounds(100, 0, 90, 20);
  95.  
  96.         final JLabel SkinLabel2 = new JLabel("Ex. Cobalt Halftone");
  97.         MainFrame.getContentPane().add(SkinLabel2);
  98.         SkinLabel2.setBounds(100, 45, 125, 20);
  99.        
  100.         final JTextField SkinField = new JTextField();
  101.         MainFrame.getContentPane().add(SkinField);
  102.         SkinField.setBounds(100, 25, 125, 20);
  103.        
  104.         JLabel WeaponLabel = new JLabel("Weapon Name");
  105.         MainFrame.getContentPane().add(WeaponLabel);
  106.         WeaponLabel.setBounds(5, 0, 125, 20);
  107.        
  108.         final JComboBox WeaponBox = new JComboBox(WeaponNames);
  109.         MainFrame.getContentPane().add(WeaponBox);
  110.         WeaponBox.setBounds(5, 25, 90, 20);
  111.        
  112.         final JCheckBox CheckBoxOne = new JCheckBox("StatTrak™");
  113.         MainFrame.getContentPane().add(CheckBoxOne);
  114.         CheckBoxOne.setBounds(1, 45, 90, 20);
  115.         CheckBoxOne.addItemListener(new ItemListener() { // fires if the box is checked or unchecked
  116.             public void itemStateChanged(ItemEvent e) {
  117.                 if(e.getStateChange() == ItemEvent.SELECTED){ // if it is selected
  118.                     StatTrak = true;
  119.                     Souvenir = false;
  120.                     CheckBoxTwo.setSelected(false);
  121.                     CheckBoxTwo.setEnabled(false);
  122.                 }else { // if it is not selected
  123.                     StatTrak = false;
  124.                     CheckBoxTwo.setEnabled(true);
  125.                 }
  126.             }
  127.         });
  128.        
  129.        
  130.         MainFrame.getContentPane().add(CheckBoxTwo);
  131.         CheckBoxTwo.setBounds(227, 45, 90, 20);
  132.         CheckBoxTwo.addItemListener(new ItemListener() { // fires if the box is checked or unchecked
  133.             public void itemStateChanged(ItemEvent e2) {
  134.                 if(e2.getStateChange() == ItemEvent.SELECTED){ // if it is selected
  135.                     StatTrak = false;
  136.                     Souvenir = true;
  137.                     CheckBoxOne.setSelected(false);
  138.                     CheckBoxOne.setEnabled(false);
  139.                 }else { // if it is not selected
  140.                     Souvenir = false;
  141.                     CheckBoxOne.setEnabled(true);
  142.                 }
  143.             }
  144.         });
  145.        
  146.         final JComboBox QualityBox = new JComboBox(Qualities);
  147.         MainFrame.getContentPane().add(QualityBox);
  148.         QualityBox.setBounds(230, 25, 90, 20);
  149.        
  150.         final JComboBox QualityBox2 = new JComboBox(StickerQualities);
  151.         MainFrame.getContentPane().add(QualityBox2);
  152.         QualityBox2.setBounds(230, 25, 90, 20);
  153.         QualityBox2.setEnabled(false);
  154.         QualityBox2.setVisible(false);
  155.        
  156.         final JLabel QualityLabel = new JLabel("Quality");
  157.         MainFrame.getContentPane().add(QualityLabel);
  158.         QualityLabel.setBounds(230, 0, 125, 20);
  159.        
  160.         JLabel PriceLabel = new JLabel("Price:");
  161.         MainFrame.getContentPane().add(PriceLabel);
  162.         PriceLabel.setBounds(5, 70, 35, 20);
  163.        
  164.         JLabel PriceLabel2 = new JLabel("Total:");
  165.         MainFrame.getContentPane().add(PriceLabel2);
  166.         PriceLabel2.setBounds(5, 95, 35, 20);
  167.        
  168.         final JTextField PriceField = new JTextField("$");
  169.         MainFrame.getContentPane().add(PriceField);
  170.         PriceField.setBounds(45, 70, 51, 20);
  171.         PriceField.setEditable(false);
  172.        
  173.         final JTextField PriceFieldTotal = new JTextField("0$");
  174.         MainFrame.getContentPane().add(PriceFieldTotal);
  175.         PriceFieldTotal.setBounds(45, 95, 51, 20);
  176.         PriceFieldTotal.setEditable(false);
  177.        
  178.         final JTextField PriceField2 = new JTextField("€");
  179.         MainFrame.getContentPane().add(PriceField2);
  180.         PriceField2.setBounds(100, 70, 51, 20);
  181.         PriceField2.setEditable(false);
  182.        
  183.         final JTextField PriceField2Total = new JTextField("0€");
  184.         MainFrame.getContentPane().add(PriceField2Total);
  185.         PriceField2Total.setBounds(100, 95, 51, 20);
  186.         PriceField2Total.setEditable(false);
  187.        
  188.         final JTextField PriceField3 = new JTextField("£");
  189.         MainFrame.getContentPane().add(PriceField3);
  190.         PriceField3.setBounds(155, 70, 51, 20);
  191.         PriceField3.setEditable(false);
  192.        
  193.         final JTextField PriceField3Total = new JTextField("0£");
  194.         MainFrame.getContentPane().add(PriceField3Total);
  195.         PriceField3Total.setBounds(155, 95, 51, 20);
  196.         PriceField3Total.setEditable(false);
  197.        
  198.         WeaponBox.addItemListener(new ItemListener() {
  199.             public void itemStateChanged(ItemEvent e) {
  200.                 int WeaponIndex = WeaponBox.getSelectedIndex();
  201.                 String WeaponName = WeaponNames[WeaponIndex];
  202.                 if(WeaponName=="Case"){
  203.                     SkinLabel.setEnabled(true);
  204.                     SkinField.setEnabled(true);
  205.                     SkinLabel2.setEnabled(true);
  206.                     QualityLabel.setEnabled(false);
  207.                     QualityBox.setEnabled(false);
  208.                     QualityBox.setVisible(true);
  209.                     CheckBoxOne.setEnabled(false);
  210.                     CheckBoxTwo.setEnabled(false);
  211.                     QualityBox2.setEnabled(false);
  212.                     QualityBox2.setVisible(false);
  213.                 }else if(WeaponName=="Sticker Capsule"){
  214.                     QualityLabel.setEnabled(false);
  215.                     QualityBox.setEnabled(false);
  216.                     QualityBox.setVisible(true);
  217.                     CheckBoxOne.setEnabled(false);
  218.                     CheckBoxTwo.setEnabled(false);
  219.                     SkinLabel.setEnabled(false);
  220.                     SkinField.setEnabled(false);
  221.                     SkinLabel2.setEnabled(false);
  222.                     QualityBox2.setEnabled(false);
  223.                     QualityBox2.setVisible(false);
  224.                 }else if(WeaponName=="Sticker"){
  225.                     QualityLabel.setEnabled(true);
  226.                     CheckBoxOne.setEnabled(false);
  227.                     CheckBoxTwo.setEnabled(false);
  228.                     SkinLabel.setEnabled(true);
  229.                     SkinField.setEnabled(true);
  230.                     SkinLabel2.setEnabled(true);
  231.                    
  232.                     QualityBox.setEnabled(false);
  233.                     QualityBox.setVisible(false);
  234.                    
  235.                     QualityBox2.setEnabled(true);
  236.                     QualityBox2.setVisible(true);
  237.                    
  238.                 }else{
  239.                     QualityLabel.setEnabled(true);
  240.                     QualityBox.setEnabled(true);
  241.                     QualityBox.setVisible(true);
  242.                     CheckBoxOne.setEnabled(true);
  243.                     CheckBoxTwo.setEnabled(true);
  244.                     SkinLabel.setEnabled(true);
  245.                     SkinField.setEnabled(true);
  246.                     SkinLabel2.setEnabled(true);
  247.                     QualityBox2.setEnabled(false);
  248.                     QualityBox2.setVisible(false);
  249.                 }
  250.             }
  251.         });
  252.        
  253.         JButton FetchButton = new JButton("Fetch Price");
  254.         MainFrame.getContentPane().add(FetchButton);
  255.         FetchButton.setBounds(210, 70, 110, 20);
  256.         FetchButton.addActionListener(new ActionListener() {
  257.             public void actionPerformed(ActionEvent e) {
  258.                 String SkinText = SkinField.getText();
  259.                 String SkinLetter = SkinField.getText().charAt(0) + " ";
  260.                 SkinLetter = SkinLetter.toUpperCase();
  261.                 SkinLetter = SkinLetter.replace(" ", "");
  262.                 SkinText = SkinLetter + SkinText.substring(1);
  263.                 SkinField.setText(SkinText);
  264.                
  265.                 if(SkinField.getText().contains(" ")==true){
  266.                     String SkinLetter2 = SkinField.getText().charAt(SkinField.getText().indexOf(" ")+1) + " ";
  267.                     SkinLetter2 = SkinLetter2.toUpperCase();
  268.                     SkinLetter2 = SkinLetter2.replace(" ", "");
  269.                     String SkinText2 = SkinText.substring(SkinField.getText().indexOf(" ")+2);
  270.                     SkinText = SkinText.substring(0, SkinField.getText().indexOf(" ")+1) + SkinLetter2 + SkinText2;
  271.                     SkinField.setText(SkinText);
  272.                 }
  273.                
  274.                
  275.                
  276.                 DollarPrice = 0;
  277.                 EuroPrice = 0;
  278.                 PoundPrice = 0;
  279.                
  280.                
  281.                 PriceField2.setText("€");
  282.                 PriceField3.setText("£");
  283.                 PriceField.setText("$");
  284.                
  285.                 int WeaponIndex = WeaponBox.getSelectedIndex();
  286.                 String WeaponName = WeaponNames[WeaponIndex];
  287.                
  288.                 int QualityIndex = 0;
  289.                 String Quality = "";
  290.                
  291.                 if(WeaponName=="Sticker"){
  292.                     QualityIndex = QualityBox2.getSelectedIndex();
  293.                     Quality = StickerQualities[QualityIndex];
  294.                 }else{
  295.                     QualityIndex = QualityBox.getSelectedIndex();
  296.                     Quality = Qualities[QualityIndex];
  297.                 }
  298.                
  299.                 String SkinName = SkinField.getText();
  300.                
  301.                 try {
  302.                     String Price = Read.Price(WeaponName, SkinName, Quality, StatTrak, Souvenir);
  303.                     PriceField.setText(Price + "$");
  304.                     if(Price!=null && Price!=""){
  305.                         double PriceD = Double.parseDouble(Price);
  306.                         double[] Conversions = Read.ConvertEuroPound(PriceD);
  307.                        
  308.                         DollarPrice = PriceD;
  309.                         EuroPrice = Read.round(PriceD*Conversions[0], 2);
  310.                         PoundPrice = Read.round(PriceD*Conversions[1], 2);
  311.                        
  312.                         String PriceEuro = Double.toString(Read.round(PriceD*Conversions[0], 2));
  313.                         String PricePound = Double.toString(Read.round(PriceD*Conversions[1], 2));
  314.                        
  315.                        
  316.                         if(PriceEuro.length()==3){
  317.                             PriceEuro = PriceEuro + "0";
  318.                         }
  319.                         if(PricePound.length()==3){
  320.                             PricePound = PricePound + "0";
  321.                         }
  322.                        
  323.                        
  324.                        
  325.                         PriceField2.setText(PriceEuro + "€");
  326.                         PriceField3.setText(PricePound + "£");
  327.                     }
  328.                 } catch (IOException e1) {
  329.                     e1.printStackTrace();
  330.                 }
  331.                
  332.                
  333.             }
  334.         });
  335.        
  336.         JButton AddTotalButton = new JButton("Add");
  337.         MainFrame.getContentPane().add(AddTotalButton);
  338.         AddTotalButton.setBounds(210, 95, 60, 20);
  339.         AddTotalButton.addActionListener(new ActionListener() {
  340.             public void actionPerformed(ActionEvent e) {
  341.                
  342.                 DollarTotal = DollarTotal + DollarPrice;
  343.                 EuroTotal = EuroTotal + EuroPrice;
  344.                 PoundTotal = PoundTotal + PoundPrice;
  345.                
  346.                 DollarTotal = Read.round(DollarTotal, 2);
  347.                 EuroTotal = Read.round(EuroTotal, 2);
  348.                 PoundTotal = Read.round(PoundTotal, 2);
  349.                
  350.                 PriceFieldTotal.setText(Double.toString(DollarTotal) + "$");
  351.                 PriceField2Total.setText(Double.toString(EuroTotal) + "€");
  352.                 PriceField3Total.setText(Double.toString(PoundTotal) + "£");
  353.                
  354.                
  355.                
  356.             }
  357.         });
  358.    
  359.         JButton ClearTotalButton = new JButton("CE");
  360.         MainFrame.getContentPane().add(ClearTotalButton);
  361.         ClearTotalButton.setBounds(270, 95, 50, 20);
  362.         ClearTotalButton.addActionListener(new ActionListener() {
  363.             public void actionPerformed(ActionEvent e) {
  364.             DollarTotal = 0;
  365.             EuroTotal = 0;
  366.             PoundTotal = 0;
  367.            
  368.            
  369.             PriceFieldTotal.setText(Double.toString(DollarTotal) + "$");
  370.             PriceField2Total.setText(Double.toString(EuroTotal) + "€");
  371.             PriceField3Total.setText(Double.toString(PoundTotal) + "£");  
  372.                    
  373.                
  374.             }
  375.         });
  376.        
  377.        
  378.        
  379.        
  380.        
  381.        
  382.        
  383.        
  384.        
  385.        
  386.        
  387.        
  388.        
  389.     }
  390.  
  391. }
Advertisement
Add Comment
Please, Sign In to add comment