import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Tooriistariba extends JApplet { public Tooriistariba() { getContentPane().setLayout (new BorderLayout()); JToolBar toolbar = new JToolBar(); JButton myButton = new JButton("Nupp"); toolbar.add(myButton); toolbar.addSeparator(); toolbar.add (new Checkbox ("Märkeruut")); getContentPane().add (toolbar, BorderLayout.NORTH); toolbar = new JToolBar(); Icon icon = new AnOvalIcon(Color.red); myButton = new JButton(icon); toolbar.add(myButton); icon = new AnOvalIcon(Color.blue); myButton = new JButton(icon); toolbar.add(myButton); icon = new AnOvalIcon(Color.green); myButton = new JButton(icon); toolbar.add(myButton); toolbar.addSeparator(); icon = new AnOvalIcon(Color.magenta); myButton = new JButton(icon); toolbar.add(myButton); getContentPane().add (toolbar, BorderLayout.SOUTH); } class AnOvalIcon implements Icon { Color color; public AnOvalIcon (Color c) { color = c; } public void paintIcon (Component c, Graphics g, int x, int y) { g.setColor(color); g.fillOval ( x, y, getIconWidth(), getIconHeight()); } public int getIconWidth() { return 20; } public int getIconHeight() { return 10; } } }