home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-02-05 | 1.2 KB | 51 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class Applet7 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);
-
- switch(choice)
- {
- case 1:
- g.setColor(Color.red);
- break;
- case 2:
- g.setColor(Color.blue);
- break;
- case 3:
- g.setColor(Color.green);
- break;
- default:
- 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;
- }
- }
-