Professional Documents
Culture Documents
Animal Forms Exercise
Animal Forms Exercise
Create the following view in Java and make sure that the text underneath the pictures change
according to the animal you clicked. Make sure to download the pictures from the internet and resize
them as 100 X 130.
/*
File imageC = new File("src//images//chincilla.png");
File imageK = new File("src//images//kapibara.png");
File imageH = new File("src//images//hamster.png");
*/
setTitle(title);
setSize(600,500);
setLayout(new FlowLayout());
//when the form is closed, shut down the application
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*if (imageC.exists())
System.out.println("Chincilla picture is found");
if (imageH.exists())
System.out.println("Hamster picture is found");
if (imageK.exists())
System.out.println("Kapibara picture is found");
*/
animalLabel.setFont(new Font("Verdana",Font.BOLD,26));
add(btnChin);
add(btnKap);
add(btnHam);
add(animalLabel);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnChin){
animalLabel.setText("you like chincillas!");
}
else if (e.getSource() == btnKap){
animalLabel.setText("you like kapibaras!");
}
else if (e.getSource() == btnHam){
animalLabel.setText("you like hamsters!");
}
}
}