="justify">}
}
}
Додаток 4
java.applet.Applet; java.awt. *; java.util. *; class FormDemo extends Applet
{btReady;
chbox1;chbox2;grRadio;rd1;rd2;rd3;ch1;lbFirstName;lbSecondName;txtFirstName;txtSecondName;txta;void init ()
{= new Checkbox ( First ); (chbox1);=Label ( Enter your first name: ); (lbFirstName);=new TextField ( raquo ;, 30); (txtFirstName);=new Checkbox ( Second ); (chbox2);=Label ( Enter your second name: ); (lbSecondName);=new TextField ( raquo ;, 30) ; (txtSecondName);=new CheckboxGroup ();=new Checkbox ( Mode 1 ,, true);=new Checkbox ( Mode 2 ,, false);=new Checkbox ( Mode 3 ,, false); (rd1); (rd2); (rd3);=new Choice();.addItem(laquo;Whiteraquo;);.addItem(laquo;Greenraquo;);.addItem(laquo;Yellowraquo;);(ch1);(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);.setBackground(Color.yellow);= new TextArea ( raquo ;, 6, 45); (txta) ;. setBackground (Color.white);=new Button ( Ready ); (btReady);
} String getAppletInfo ()
{ Name: FormDemo raquo ;;
} void paint (Graphics g)
{dimAppWndDimension=() ;. setColor (Color.black) ;. drawRect (0, 0, .width - 1, .height - 1);
} boolean action (Event evt, obj)
{btn; str1, str2; (evt.target instanceof Button)
{(evt.target.equals (btReady))
{= (Button) evt.target;=txtFirstName.getText ();=txtSecondName.getText();(chbox1.getState()).append(str1);(chbox2.getState()).append(str2);(rd1.getState()).append(laquo;nMode 1 n ); (rd2.getState ()). Append ( nMode 2 n ); (rd3.getState ()). Append ( nMode 3 n );
}
{false;
} true;
} if (evt.target instanceof Choice)
{(evt.target.equals (ch1))
{(ch1.getSelectedIndex () == 0) .setBackground (Color.white); (ch1.getSelectedIndex () == 1) .setBackground (Color.green); (ch1.getSelectedIndex ( ) == 2) .setBackground (Color.yellow);
}
} false;
}
}
Додаток 5
java.awt. *; java.awt.event. *; javax.swing. *; class Player
{static void main (String [] args)
{. invokeLater (new Runnable ()
{void run ()
{frame=new CalculatorFrame () ;. setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ;. setVisible (true);
}
});
}
} CalculatorFrame extends JFrame
{CalculatorFrame ()
{( Calculator ); panel=new CalculatorPanel (); (panel); ();
}
} CalculatorPanel extends JPanel
{CalculatorPanel ()
{(new BorderLayout ());=0;== raquo ;;=true;=new JButton ( 0 ) ;. setEnabled (false); (display, BorderLayout. NORTH); insert=new InsertAction (); command=new CommandAction ();=new JPanel () ;. setLayout (new GridLayout (4, 4)); ( 7 raquo ;, insert); ( 8 raquo ;, insert); ( 9 raquo ;, insert); (/ raquo ;, command); ( 4 raquo ;, insert); ( 5 raquo ;, insert); ( 6 raquo ;, insert); ( * raquo ;, command); ( 1 raquo ;, insert); ( 2 raquo ;, insert); ( 3 raquo ;, insert); ( - raquo ;, command ( 0 raquo ;, insert); (. raquo ;, insert); (= raquo ;, command); ( + raquo ;, command);
(panel, BorderLayout.CENTER);
} void addButton (String label, ActionListener listener)
{button=new JButton (label) ;. addActionListener (listener) ;. add (button);
} class InsertAction implements ActionListener
{void actionPerformed (ActionEvent event)
{input=event.getActionCommand (); (start)
{. setText ( );=false;
}. setText (display.getText () + input);
}
} class CommandAction implements ActionListener
{void actionPerformed (ActionEvent event)
{command=event.getActionCommand (); (start)
{(command.equals ( - ))
{. setText (command);=false;
} lastCommand=command;