import java.awt.*; import java.applet.*; public class PopUpFrame extends Applet { Color backcolor = Color.magenta; NewFrame myframe; Canvas justcolor = new Canvas(); Button getframe = new Button("Get Control Frame"); public void init() { setLayout(new BorderLayout()); myframe = new NewFrame(this); add("South",getframe); justcolor.setBackground(backcolor); add("Center",justcolor); } void changecolor(String newcolor) { if (newcolor.equals("blue")) justcolor.setBackground(Color.blue); else if (newcolor.equals("cyan")) justcolor.setBackground(Color.cyan); else if (newcolor.equals("back")) justcolor.setBackground(backcolor); } public boolean action(Event evt, Object arg) { if (evt.target instanceof Button) myframe.show(); return true; } } class NewFrame extends Frame { Button closewindow = new Button("Quit"); Button bluebutton = new Button("Change to Blue"); Button cyanbutton = new Button("Change to Cyan"); PopUpFrame outerparent; NewFrame(PopUpFrame parent) { outerparent = parent; setTitle("Change Color"); resize(300,300); setLayout(new GridLayout(3,1,2,2)); add(bluebutton); add(cyanbutton); add(closewindow); } public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { if(evt.target == bluebutton) outerparent.changecolor("blue"); if(evt.target == cyanbutton) outerparent.changecolor("cyan"); if(evt.target == closewindow) { hide(); outerparent.changecolor("back");} } return true; } }