home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-24 | 1.1 KB | 45 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class Applet6 extends Applet
- {
- TextField textField1;
-
- public void init()
- {
- textField1 = new TextField(5);
- add(textField1);
- textField1.setText("1");
- }
-
- public void paint(Graphics g)
- {
- g.drawString("Type a menu choice in the above box.", 20, 50);
- g.drawString("1. Red", 40, 75);
- g.drawString("2. Blue", 40, 95);
- g.drawString("3. Green", 40, 115);
- String s = textField1.getText();
- int choice = Integer.parseInt(s);
-
- if (choice == 1)
- g.setColor(Color.red);
- else if (choice == 2)
- g.setColor(Color.blue);
- else if (choice == 3)
- g.setColor(Color.green);
- else
- g.setColor(Color.black);
-
- if ((choice >= 1) && (choice <= 3))
- g.drawString("This is the color you chose.", 60, 140);
- else
- g.drawString("Invalid menu selection.", 60, 140);
- }
-
- public boolean action(Event event, Object arg)
- {
- repaint();
- return true;
- }
- }
-