//PnlCounter.java //Illustrates use of panels //similar to Counting.java import java.awt.*; import java.applet.*; import java.awt.event.*; public class PnlCounter extends Applet implements ActionListener{ //create components Label lblDisplay = new Label(); Button btnOne = new Button("One"); Button btnTwo = new Button("Two"); Button btnThree = new Button("Three"); Button btnFour = new Button("Four"); Panel pnlControls = new Panel(); public void init(){ this.setLayout(new BorderLayout()); add(lblDisplay, BorderLayout.CENTER); add(pnlControls, BorderLayout.SOUTH); //set up the panel pnlControls.setLayout(new GridLayout(1,0)); pnlControls.add(btnOne); pnlControls.add(btnTwo); pnlControls.add(btnThree); pnlControls.add(btnFour); //register listeners btnOne.addActionListener(this); btnTwo.addActionListener(this); btnThree.addActionListener(this); btnFour.addActionListener(this); //pretty up the output lblDisplay.setFont(new Font("SansSerif", Font.BOLD, 40)); lblDisplay.setAlignment(Label.CENTER); } // end init public void actionPerformed(ActionEvent e){ String theCommand = e.getActionCommand(); if (theCommand.equals("One")){ lblDisplay.setText("Ichi"); } else if (theCommand.equals("Two")){ lblDisplay.setText("Nii"); } else if (theCommand.equals("Three")){ lblDisplay.setText("San"); } else if (theCommand.equals("Four")){ lblDisplay.setText("Shi"); } // end if } // end actionPerformed } // end class def