Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class PegLogic extends JFrame
- {
- private static String pegOne = "o";
- private static String pegTwo = "o";
- private static String pegThree = "o";
- private static String pegFour = "o";
- private static String pegFive = "o";
- private static JButton boxOne;
- private static JButton boxTwo;
- private static JButton boxThree;
- private static JButton boxFour;
- private static JButton boxFive;
- private static JButton boxSix;
- private static JButton boxSeven;
- private static JButton boxEight;
- private static JButton boxNine;
- private static JButton boxTen;
- private static JButton boxEleven;
- private static JButton boxTwelve;
- private static JButton boxThirteen;
- private static JButton boxFourteen;
- private static JButton boxFifteen;
- private static JButton boxSixteen;
- private static JButton boxSeventeen;
- private static JButton boxEighteen;
- private static JButton boxNineteen;
- private static JButton boxTwenty;
- private static JButton boxTwentyOne;
- private static JButton boxTwentyTwo;
- private static JButton boxTwentyThree;
- private static JButton boxTwentyFour;
- private static JButton boxTwentyFive;
- private static JButton boxTwentySix;
- private static JButton boxTwentySeven;
- private static JButton boxTwentyEight;
- private static JButton boxTwentyNine;
- private static JButton boxThirty;
- private static JButton boxThirtyOne;
- private static JButton boxThirtyTwo;
- private static JButton boxThirtyThree;
- private static JButton boxThirtyFour;
- private static JButton boxThirtyFive;
- private static JButton boxThirtySix;
- private static JButton boxThirtySeven;
- private static JButton boxThirtyEight;
- private static JButton boxThirtyNine;
- private static JButton boxForty;
- private static JButton boxFortyOne;
- private static JButton boxFortyTwo;
- private static JButton boxFortyThree;
- private static JButton boxFortyFour;
- private static JButton boxFortyFive;
- private static JButton boxFortySix;
- private static JButton boxFortySeven;
- private static JButton boxFortyEight;
- private static JButton boxFortyNine;
- //boolean pegButtonOnePressed = true;
- static Icon holePic;
- static Icon peggedHolePic;
- //class PegLogic implements ActionListener
- //{
- //public void actionPerformed(ActionEvent e)
- //{
- //if(
- //}
- public PegLogic()
- {
- setLayout(new GridLayout(7,7));
- boxOne = new JButton();
- add(boxOne);
- boxTwo = new JButton();
- add(boxTwo);
- boxThree = new JButton();
- add(boxThree);
- boxFour = new JButton();
- add(boxFour);
- boxFive = new JButton();
- add(boxFive);
- boxSix = new JButton();
- add(boxSix);
- boxSeven = new JButton();
- add(boxSeven);
- boxEight = new JButton();
- add(boxEight);
- boxNine = new JButton();
- add(boxNine);
- boxTen = new JButton();
- add(boxTen);
- boxEleven = new JButton();
- add(boxEleven);
- boxTwelve = new JButton();
- add(boxTwelve);
- boxThirteen = new JButton();
- add(boxThirteen);
- boxFourteen = new JButton();
- add(boxFourteen);
- boxFifteen = new JButton();
- add(boxFifteen);
- boxSixteen = new JButton();
- add(boxSixteen);
- boxSeventeen = new JButton();
- add(boxSeventeen);
- boxEighteen = new JButton();
- add(boxEighteen);
- boxNineteen = new JButton();
- add(boxNineteen);
- boxTwenty = new JButton();
- add(boxTwenty);
- boxTwentyOne = new JButton();
- add(boxTwentyOne);
- boxTwentyTwo = new JButton();
- add(boxTwentyTwo);
- boxTwentyThree = new JButton();
- add(boxTwentyThree);
- boxTwentyFour = new JButton();
- add(boxTwentyFour);
- boxTwentyFive = new JButton();
- add(boxTwentyFive);
- boxTwentySix = new JButton();
- add(boxTwentySix);
- boxTwentySeven = new JButton();
- add(boxTwentySeven);
- boxTwentyEight = new JButton();
- add(boxTwentyEight);
- boxTwentyNine = new JButton();
- add(boxTwentyNine);
- boxThirty = new JButton();
- add(boxThirty);
- boxThirtyOne = new JButton();
- add(boxThirtyOne);
- boxThirtyTwo = new JButton();
- add(boxThirtyTwo);
- boxThirtyThree = new JButton();
- add(boxThirtyThree);
- boxThirtyFour = new JButton();
- add(boxThirtyFour);
- boxThirtyFive = new JButton();
- add(boxThirtyFive);
- boxThirtySix = new JButton();
- add(boxThirtySix);
- boxThirtySeven = new JButton();
- add(boxThirtySeven);
- boxThirtyEight = new JButton();
- add(boxThirtyEight);
- boxThirtyNine = new JButton();
- add(boxThirtyNine);
- boxForty = new JButton();
- add(boxForty);
- boxFortyOne = new JButton();
- add(boxFortyOne);
- boxFortyTwo = new JButton();
- add(boxFortyTwo);
- boxFortyThree = new JButton();
- add(boxFortyThree);
- boxFortyFour = new JButton();
- add(boxFortyFour);
- boxFortyFive = new JButton();
- add(boxFortyFive);
- boxFortySix = new JButton();
- add(boxFortySix);
- boxFortySeven = new JButton();
- add(boxFortySeven);
- boxFortyEight = new JButton();
- add(boxFortyEight);
- boxFortyNine = new JButton();
- add(boxFortyNine);
- {
- ButtonHandler handler = new ButtonHandler();
- //boxOne.addActionListener(handler);
- //boxTwo.addActionListener(handler);
- //boxThree.addActionListener(handler);
- //boxFour.addActionListener(handler);
- //boxFive.addActionListener(handler);
- //boxSix.addActionListener(handler)
- //boxSeven.addActionListener(handler);
- //boxEight.addActionListener(handler)
- //boxNine.addActionListener(handler)
- //PegFillThirteen.addActionListener(handler)
- //boxThreeteeddActionListener(handler)
- //PegFillFifteen.addActionListener(handler)
- //boxThreeteen.addActionListener(handler)
- boxEighteen.addActionListener(handler);
- boxTwentyFive.addActionListener(handler);
- printWelcome();
- printpegBoard();
- }
- private class ButtonHandler implements ActionListener
- {
- public void actionPerformed(ActionEvent event)
- {
- if(event.getSource() == boxEighteen)
- boxEighteen.setIcon(holePic);
- if(event.getSource() == boxTwentyFive)
- }
- }
- }
- public void printWelcome()
- {
- System.out.println("Welcome to Peg Pyramid! \n");
- }
- public void printpegBoard()
- {
- System.out.println(pegOne);
- System.out.println(pegTwo);
- System.out.println(pegThree);
- System.out.println(pegFour);
- System.out.println(pegFive);
- //holePic = new ImageIcon(getClass().getResource("PegHoleBit1.jpg"));
- //boxOne.setIcon(holePic); - boxOne Mock Space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxTwo.setIcon(peggedHolePic); - boxTwo Mock Space
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThree.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFour.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFive.setIcon(peggedHolePic);
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxSix.setIcon(peggedHolePic); - boxSix mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxSeven.setIcon(peggedHolePic); - boxSeven mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxEight.setIcon(peggedHolePic); - boxEight mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxNine.setIcon(peggedHolePic); - boxNine mock space
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxEleven.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwelve.setIcon(peggedHolePic);
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxThirteen.setIcon(peggedHolePic); - boxThirteen Mock Space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFourteen.setIcon(peggedHolePic); - boxFourteen mock space
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFifteen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxSixteen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxSeventeen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxEighteen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxNineteen.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwenty.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyOne.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyTwo.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyThree.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyFour.setIcon(peggedHolePic);
- holePic = new ImageIcon(getClass().getResource("PegHoleBit1.jpg"));
- boxTwentyFive.setIcon(holePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentySix.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentySeven.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyEight.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxTwentyNine.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirty.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyOne.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyTwo.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyThree.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyFour.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyFive.setIcon(peggedHolePic);
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxThirtySix.setIcon(peggedHolePic); - boxThirtySix mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxThirtySeven.setIcon(peggedHolePic); - boxThirtySeven mock space
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyEight.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxThirtyNine.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxForty.setIcon(peggedHolePic);
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyOne.setIcon(peggedHolePic); - boxFortyOne mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyTwo.setIcon(peggedHolePic); - boxFortyTwo mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyThree.setIcon(peggedHolePic); boxFortyThree mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyFour.setIcon(peggedHolePic); boxFortyFour mock space
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFortyFive.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFortySix.setIcon(peggedHolePic);
- peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- boxFortySeven.setIcon(peggedHolePic);
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyEight.setIcon(peggedHolePic); - boxFortyEight mock space
- //peggedHolePic = new ImageIcon(getClass().getResource("FilledPegHole1.jpg"));
- //boxFortyNine.setIcon(peggedHolePic); - boxFortyNine mock space
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement