Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.37 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.ActionEvent;
  7.  
  8.  
  9. public class PegLogic extends JFrame
  10. {
  11.     private static String pegOne = "o";
  12.     private static String pegTwo = "o";
  13.     private static String pegThree = "o";
  14.     private static String pegFour = "o";
  15.     private static String pegFive = "o";
  16.     private static JButton boxOne;
  17.     private static JButton boxTwo;
  18.     private static JButton boxThree;
  19.     private static JButton boxFour;
  20.     private static JButton boxFive;
  21.     private static JButton boxSix;
  22.     private static JButton boxSeven;
  23.     private static JButton boxEight;
  24.     private static JButton boxNine;
  25.     private static JButton boxTen;
  26.     private static JButton boxEleven;
  27.     private static JButton boxTwelve;
  28.     private static JButton boxThirteen;
  29.     private static JButton boxFourteen;
  30.     private static JButton boxFifteen;
  31.     private static JButton boxSixteen;
  32.     private static JButton boxSeventeen;
  33.     private static JButton boxEighteen;
  34.     private static JButton boxNineteen;
  35.     private static JButton boxTwenty;
  36.     private static JButton boxTwentyOne;
  37.     private static JButton boxTwentyTwo;
  38.     private static JButton boxTwentyThree;
  39.     private static JButton boxTwentyFour;
  40.     private static JButton boxTwentyFive;
  41.     private static JButton boxTwentySix;
  42.     private static JButton boxTwentySeven;
  43.     private static JButton boxTwentyEight;
  44.     private static JButton boxTwentyNine;
  45.     private static JButton boxThirty;
  46.     private static JButton boxThirtyOne;
  47.     private static JButton boxThirtyTwo;
  48.     private static JButton boxThirtyThree;
  49.     private static JButton boxThirtyFour;
  50.     private static JButton boxThirtyFive;
  51.     private static JButton boxThirtySix;
  52.     private static JButton boxThirtySeven;
  53.     private static JButton boxThirtyEight;
  54.     private static JButton boxThirtyNine;
  55.     private static JButton boxForty;
  56.     private static JButton boxFortyOne;
  57.     private static JButton boxFortyTwo;
  58.     private static JButton boxFortyThree;
  59.     private static JButton boxFortyFour;
  60.     private static JButton boxFortyFive;
  61.     private static JButton boxFortySix;
  62.     private static JButton boxFortySeven;
  63.     private static JButton boxFortyEight;
  64.     private static JButton boxFortyNine;
  65.  
  66.  
  67.     //boolean pegButtonOnePressed = true;
  68.  
  69.     static Icon holePic;
  70.     static Icon peggedHolePic;
  71.  
  72.     //class PegLogic implements ActionListener
  73.     //{
  74.     //public void actionPerformed(ActionEvent e)
  75.         //{
  76.             //if(
  77.  
  78.     //}
  79.  
  80.  
  81.     public PegLogic()
  82.     {
  83.         setLayout(new GridLayout(7,7));
  84.  
  85.         boxOne = new JButton();
  86.         add(boxOne);
  87.  
  88.         boxTwo = new JButton();
  89.         add(boxTwo);
  90.  
  91.         boxThree = new JButton();
  92.         add(boxThree);
  93.  
  94.         boxFour = new JButton();
  95.         add(boxFour);
  96.  
  97.         boxFive = new JButton();
  98.         add(boxFive);
  99.  
  100.         boxSix = new JButton();
  101.         add(boxSix);
  102.  
  103.         boxSeven = new JButton();
  104.         add(boxSeven);
  105.  
  106.         boxEight = new JButton();
  107.         add(boxEight);
  108.  
  109.         boxNine = new JButton();
  110.         add(boxNine);
  111.  
  112.  
  113.         boxTen = new JButton();
  114.         add(boxTen);
  115.  
  116.         boxEleven = new JButton();
  117.         add(boxEleven);
  118.  
  119.  
  120.         boxTwelve = new JButton();
  121.         add(boxTwelve);
  122.  
  123.         boxThirteen = new JButton();
  124.         add(boxThirteen);
  125.  
  126.         boxFourteen = new JButton();
  127.         add(boxFourteen);
  128.  
  129.         boxFifteen = new JButton();
  130.         add(boxFifteen);
  131.  
  132.         boxSixteen = new JButton();
  133.         add(boxSixteen);
  134.  
  135.         boxSeventeen = new JButton();
  136.         add(boxSeventeen);
  137.  
  138.         boxEighteen = new JButton();
  139.         add(boxEighteen);
  140.  
  141.         boxNineteen = new JButton();
  142.         add(boxNineteen);
  143.  
  144.  
  145.         boxTwenty = new JButton();
  146.         add(boxTwenty);
  147.  
  148.         boxTwentyOne = new JButton();
  149.         add(boxTwentyOne);
  150.  
  151.         boxTwentyTwo = new JButton();
  152.         add(boxTwentyTwo);
  153.  
  154.         boxTwentyThree = new JButton();
  155.         add(boxTwentyThree);
  156.  
  157.         boxTwentyFour = new JButton();
  158.         add(boxTwentyFour);
  159.  
  160.         boxTwentyFive = new JButton();
  161.         add(boxTwentyFive);
  162.  
  163.         boxTwentySix = new JButton();
  164.         add(boxTwentySix);
  165.  
  166.         boxTwentySeven = new JButton();
  167.         add(boxTwentySeven);
  168.  
  169.         boxTwentyEight = new JButton();
  170.         add(boxTwentyEight);
  171.  
  172.         boxTwentyNine = new JButton();
  173.         add(boxTwentyNine);
  174.  
  175.  
  176.         boxThirty = new JButton();
  177.         add(boxThirty);
  178.  
  179.         boxThirtyOne = new JButton();
  180.         add(boxThirtyOne);
  181.  
  182.         boxThirtyTwo = new JButton();
  183.         add(boxThirtyTwo);
  184.  
  185.         boxThirtyThree = new JButton();
  186.         add(boxThirtyThree);
  187.  
  188.         boxThirtyFour = new JButton();
  189.         add(boxThirtyFour);
  190.  
  191.         boxThirtyFive = new JButton();
  192.         add(boxThirtyFive);
  193.  
  194.         boxThirtySix = new JButton();
  195.         add(boxThirtySix);
  196.  
  197.         boxThirtySeven = new JButton();
  198.         add(boxThirtySeven);
  199.  
  200.         boxThirtyEight = new JButton();
  201.         add(boxThirtyEight);
  202.  
  203.         boxThirtyNine = new JButton();
  204.         add(boxThirtyNine);
  205.  
  206.  
  207.  
  208.         boxForty = new JButton();
  209.         add(boxForty);
  210.  
  211.         boxFortyOne = new JButton();
  212.         add(boxFortyOne);
  213.  
  214.         boxFortyTwo = new JButton();
  215.         add(boxFortyTwo);
  216.  
  217.         boxFortyThree = new JButton();
  218.         add(boxFortyThree);
  219.  
  220.         boxFortyFour = new JButton();
  221.         add(boxFortyFour);
  222.  
  223.         boxFortyFive = new JButton();
  224.         add(boxFortyFive);
  225.  
  226.         boxFortySix = new JButton();
  227.         add(boxFortySix);
  228.  
  229.         boxFortySeven = new JButton();
  230.         add(boxFortySeven);
  231.  
  232.         boxFortyEight = new JButton();
  233.         add(boxFortyEight);
  234.  
  235.         boxFortyNine = new JButton();
  236.         add(boxFortyNine);
  237.  
  238.  
  239.  
  240. {
  241.  
  242.         ButtonHandler handler = new ButtonHandler();
  243.         //boxOne.addActionListener(handler);
  244.         //boxTwo.addActionListener(handler);
  245.         //boxThree.addActionListener(handler);
  246.         //boxFour.addActionListener(handler);
  247.         //boxFive.addActionListener(handler);
  248.         //boxSix.addActionListener(handler)
  249.         //boxSeven.addActionListener(handler);
  250.         //boxEight.addActionListener(handler)
  251.         //boxNine.addActionListener(handler)
  252.         //PegFillThirteen.addActionListener(handler)
  253.         //boxThreeteeddActionListener(handler)
  254.         //PegFillFifteen.addActionListener(handler)
  255.         //boxThreeteen.addActionListener(handler)
  256.         boxEighteen.addActionListener(handler);
  257.         boxTwentyFive.addActionListener(handler);
  258.  
  259.  
  260.  
  261.         printWelcome();
  262.         printpegBoard();
  263.     }
  264.  
  265.     private class ButtonHandler implements ActionListener
  266.  
  267.     {
  268.         public void actionPerformed(ActionEvent event)
  269.  
  270.     {
  271.  
  272.         if(event.getSource() == boxEighteen)
  273.         boxEighteen.setIcon(holePic);
  274.  
  275.         if(event.getSource() == boxTwentyFive)
  276.     }
  277.  
  278. }
  279.  
  280.  
  281.     }
  282.  
  283.  
  284.  
  285.  
  286. public void printWelcome()
  287.         {
  288.     System.out.println("Welcome to Peg Pyramid! \n");
  289.         }
  290.  
  291. public void printpegBoard()
  292.  
  293. {
  294. System.out.println(pegOne);
  295. System.out.println(pegTwo);
  296. System.out.println(pegThree);
  297. System.out.println(pegFour);
  298. System.out.println(pegFive);
  299.  
  300.  
  301.  
  302. //holePic = new ImageIcon(getClass().getResource("PegHoleBit1.jpg"));
  303. //boxOne.setIcon(holePic); - boxOne Mock Space
  304.  
  305. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  306. //boxTwo.setIcon(peggedHolePic); - boxTwo Mock Space
  307.  
  308. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  309. boxThree.setIcon(peggedHolePic);
  310.  
  311. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  312. boxFour.setIcon(peggedHolePic);
  313.  
  314. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  315. boxFive.setIcon(peggedHolePic);
  316.  
  317. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  318. //boxSix.setIcon(peggedHolePic); - boxSix mock space
  319.  
  320. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  321. //boxSeven.setIcon(peggedHolePic); - boxSeven mock space
  322.  
  323. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  324. //boxEight.setIcon(peggedHolePic); - boxEight mock space
  325.  
  326. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  327. //boxNine.setIcon(peggedHolePic); - boxNine mock space
  328.  
  329. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  330. boxTen.setIcon(peggedHolePic);
  331.  
  332. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  333. boxEleven.setIcon(peggedHolePic);
  334.  
  335. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  336. boxTwelve.setIcon(peggedHolePic);
  337.  
  338. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  339. //boxThirteen.setIcon(peggedHolePic); - boxThirteen Mock Space
  340.  
  341. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  342. //boxFourteen.setIcon(peggedHolePic); - boxFourteen mock space
  343.  
  344. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  345. boxFifteen.setIcon(peggedHolePic);
  346.  
  347. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  348. boxSixteen.setIcon(peggedHolePic);
  349.  
  350. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  351. boxSeventeen.setIcon(peggedHolePic);
  352.  
  353. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  354. boxEighteen.setIcon(peggedHolePic);
  355.  
  356. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  357. boxNineteen.setIcon(peggedHolePic);
  358.  
  359. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  360. boxTwenty.setIcon(peggedHolePic);
  361.  
  362. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  363. boxTwentyOne.setIcon(peggedHolePic);
  364.  
  365. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  366. boxTwentyTwo.setIcon(peggedHolePic);
  367.  
  368. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  369. boxTwentyThree.setIcon(peggedHolePic);
  370.  
  371. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  372. boxTwentyFour.setIcon(peggedHolePic);
  373.  
  374. holePic = new ImageIcon(getClass().getResource("PegHoleBit1.jpg"));
  375. boxTwentyFive.setIcon(holePic);
  376.  
  377. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  378. boxTwentySix.setIcon(peggedHolePic);
  379.  
  380. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  381. boxTwentySeven.setIcon(peggedHolePic);
  382.  
  383. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  384. boxTwentyEight.setIcon(peggedHolePic);
  385.  
  386.  
  387. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  388. boxTwentyNine.setIcon(peggedHolePic);
  389.  
  390. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  391. boxThirty.setIcon(peggedHolePic);
  392.  
  393. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  394. boxThirtyOne.setIcon(peggedHolePic);
  395.  
  396. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  397. boxThirtyTwo.setIcon(peggedHolePic);
  398.  
  399. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  400. boxThirtyThree.setIcon(peggedHolePic);
  401.  
  402. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  403. boxThirtyFour.setIcon(peggedHolePic);
  404.  
  405. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  406. boxThirtyFive.setIcon(peggedHolePic);
  407.  
  408.  
  409. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  410. //boxThirtySix.setIcon(peggedHolePic); - boxThirtySix mock space
  411.  
  412. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  413. //boxThirtySeven.setIcon(peggedHolePic); - boxThirtySeven mock space
  414.  
  415. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  416. boxThirtyEight.setIcon(peggedHolePic);
  417.  
  418. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  419. boxThirtyNine.setIcon(peggedHolePic);
  420.  
  421. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  422. boxForty.setIcon(peggedHolePic);
  423.  
  424. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  425. //boxFortyOne.setIcon(peggedHolePic); - boxFortyOne mock space
  426.  
  427. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  428. //boxFortyTwo.setIcon(peggedHolePic); - boxFortyTwo mock space
  429.  
  430.  
  431.  
  432. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  433. //boxFortyThree.setIcon(peggedHolePic); boxFortyThree mock space
  434.  
  435. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  436. //boxFortyFour.setIcon(peggedHolePic); boxFortyFour mock space
  437.  
  438. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  439. boxFortyFive.setIcon(peggedHolePic);
  440.  
  441. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  442. boxFortySix.setIcon(peggedHolePic);
  443.  
  444. peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  445. boxFortySeven.setIcon(peggedHolePic);
  446.  
  447. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  448. //boxFortyEight.setIcon(peggedHolePic); - boxFortyEight mock space
  449.  
  450. //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
  451. //boxFortyNine.setIcon(peggedHolePic); - boxFortyNine mock space
  452.  
  453.  
  454. }
  455.  
  456.  
  457.  
  458. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement