import java.applet.*; import java.awt.*; import java.awt.event.*; public class AddOrder2 extends Applet { public void init() { setBackground(new Color(225,225, 255)); try { FrameForApplet frameForApplet = new FrameForApplet("A frame"); } catch (Throwable e) { System.out.println("Can't use Frame: " + e); return; } } public void paint(Graphics g) { g.drawString("A Frame appears with some components", 10 , 25); } } // END OF Class AddOrder2 final class FrameForApplet extends Frame implements WindowListener { DashHolder dashHolder; static Frame frame; FrameForApplet(String s) { super(s); setLayout(new FlowLayout()); frame = this; setBounds(400, 100, 400, 150); dashHolder = new DashHolder(100, 40); add(dashHolder); show(); dashHolder.addTopComponent(); addWindowListener(this); } public void windowOpened(WindowEvent we){} public void windowClosed(WindowEvent we){} public void windowIconified(WindowEvent we){} public void windowDeiconified(WindowEvent we){} public void windowActivated(WindowEvent we){} public void windowDeactivated(WindowEvent we){} public void windowClosing(WindowEvent we) { if (we.getSource() == this) { setVisible(false); dispose(); } } } // END OF Class FrameForApplet class DashHolder extends Panel { Button button; int height = 0; int width = 0; DashHolder(int width, int height) { this.width = width; this.height = height; setBackground(Color.yellow); } final void addTopComponent() { button = new Button("Button"); FrameForApplet.frame.add(button, 0); button.setSize(button.getPreferredSize()); button.setLocation(230, 35); } public final Dimension getMinimumSize() { return(new Dimension(width, height)); } public final Dimension getPreferredSize() { return(getMinimumSize()); } } // END OF Class DashHolder