bottom new JLabelHave fun playing this Tile Puzzle game

Bottom new jlabelhave fun playing this tile puzzle

This preview shows page 1 - 3 out of 3 pages.

bottom = new JLabel("Have fun playing this Tile Puzzle game",SwingConstants.CENTER);// ***** Task 3:// instantiate the JPanel component named top// Part 3 student code starts here:top=new JPanel();// set the layout of top to a 1-by-3 gridGridLayout layout = new GridLayout(1,3);top.setLayout(layout);contents.add(top, b1.NORTH);// instantiate the JButtons that determine the grid sizebutton1=new JButton("3-3");button2=new JButton("4-4");button3=new JButton("5-5");// add the buttons to JPanel toptop.add(button1);
top.add(button2);top.add(button3);// add JPanel top to the content pane as its north component// Part 3 student code ends here.// ***** Task 5:// Note: search for and complete Task 4 before performing this task// Part 5 student code starts here:// declare and instantiate an ActionListener// register the listener on the 3 buttonsbutton1.addActionListener(new ButtonListener());button2.addActionListener(new ButtonListener());button3.addActionListener(new ButtonListener());// that you declared in Task 1// Part 5 student code ends here.contents.add(bottom, BorderLayout.SOUTH);setSize(325, 325);setVisible(true);}// ***** Task 4:// create a private inner class that implements ActionListener// your method should identify which of the 3 buttons// was the source of the event// depending on which button was pressed,// call the setUpGame method of the Game class// with arguments 3, 4, or 5// the API of that method is:// public void setUpGame(int nSides)// At the end of the method call validate()// Part 4 student code starts here:public class ButtonListener implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif(e.getSource().equals(button1)){game.setUpGame(3);game.validate();}if(e.getSource().equals(button2)){game.setUpGame(4);game.validate();}if(e.getSource().equals(button3)){game.setUpGame(5);game.validate();}}}// Part 4 student code ends here.public static void main(String[] args){NestedLayoutPractice nl = new NestedLayoutPractice();
nl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture