import java.applet.*; import java.awt.*; public class acard extends Applet { Image imgs[]; MediaTracker Tracker1; int present_image=0; NewCanvas nCanvas; Button but_last,but_next; TextField Title; String [] what_is_it; Panel TopPanel; Panel ButtonPanel ; public void init() { what_is_it=new String[3]; what_is_it[0]="Little Deer"; what_is_it[1]="Big Deer"; what_is_it[2]="Rhino"; imgs=new Image[3]; Tracker1=new MediaTracker(this); for(int i=0;i<3;i++){ imgs[i] = getImage(getCodeBase(), "Image" + (i+1) + ".gif"); Tracker1.addImage(imgs[i],0); } showStatus("Loading Images"); try {Tracker1.waitForID(0);} catch (InterruptedException e){} showStatus(" "); // Now we build the Applet Layout begining with Fonts and Colors Font fnt24 =new Font("TimeRoman",Font.BOLD,24); Font fnt18 = new Font("TimeRoman",Font.BOLD,18); Font fnt14 = new Font("TimeRoman",Font.BOLD,14); Color umsl_red=new Color(200,61,61); Color umsl_yellow=new Color(240,180,60); // First create three panels, one for label and text, one for animal cards,and // one for buttons. TopPanel =new Panel(); nCanvas = new NewCanvas(imgs[present_image]); nCanvas.setLayout(new FlowLayout(FlowLayout.CENTER)); nCanvas.resize(imgs[present_image].getWidth(this),imgs[present_image].getHeight(this)); ButtonPanel = new Panel(); //Now lay out The AppletPanel setLayout(new BorderLayout()); setForeground(umsl_red); setBackground(umsl_yellow); add("North",TopPanel); add("Center",nCanvas); add("South",ButtonPanel); //Now the TopPanel TopPanel.setLayout(new BorderLayout()); Label lab = new Label("Animal Cards",Label.CENTER) ; lab.setFont(fnt18); TopPanel.add("North",lab ); Title=new TextField(15); Title.setEditable(false); Title.setForeground(Color.black); Title.setBackground(Color.lightGray); Title.setFont(fnt14); TopPanel.add("Center",Title); Title.setText(what_is_it[0]); // Finally, the ButtonPanel. ButtonPanel.setFont(fnt14); but_next=new Button("Next Picture"); but_last=new Button("Previous Picture"); ButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); ButtonPanel.add(but_next); ButtonPanel.add(but_last); } public void start(){ System.out.println("start"); if(present_image!=0) present_image=0; nCanvas.ChangeImage(imgs[0]); Title.setText(what_is_it[0]); } public boolean action(Event evt, Object obj) { if(evt.target instanceof Button){ if (evt.target ==but_next){ if(++present_image==3)present_image=0; } else{ if(--present_image<0)present_image=2; } nCanvas.ChangeImage(imgs[present_image]); nCanvas.paint(nCanvas.getGraphics()); Title.setText(what_is_it[present_image]); } return true; } } class NewCanvas extends Canvas{ Image im; public NewCanvas(Image im){ this.im=im; } public void ChangeImage(Image im){ this.im=im; } public void paint(Graphics g){ g. drawImage(im,1, 1,this); resize(im.getWidth(this),im.getHeight(this)); } }