//NullCounter.java //Illustrates use of null layout //similar to Counting.java import java.awt.*; import java.applet.*; import java.awt.event.*; public class NullCounter 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"); public void init(){ this.setLayout(null); add(lblDisplay); lblDisplay.setLocation(100,0); lblDisplay.setSize(100,50); add(btnOne); btnOne.setLocation(0,0); btnOne.setSize(50,50); add(btnTwo); btnTwo.setLocation(50,50); btnTwo.setSize(50,50); add(btnThree); btnThree.setLocation(100,100); btnThree.setSize(50,50); add(btnFour); btnFour.setLocation(150,150); btnFour.setSize(50,50); //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