}
Додаток 11
javax.swing. *;
class ASampleGUIProgram
{static void main (String [] args)
{appleString; =. showInputDialog ( Enter number of apples: ); appleCount;=Integer.parseInt (appleString);
orangeString; =. showInputDialog ( Enter number of oranges: ); orangeCount;=Integer.parseInt (orangeString);
totalFruitCount;=appleCount + orangeCount;
. showMessageDialog (, The total number of fruits= + totalFruitCount);
. exit (0);
}
}
Додаток 12
javax.swing. *; java.awt. *;
class DukeApplet extends JApplet
{void init ()
{
() ;. setLayout (new BorderLayout ());
spacer=new JLabel ( ) ;. add (spacer, West ); niceLabel=new JLabel ( Java is fun! ); dukeIcon=new ImageIcon ( duke_waving.gif ) ;. setIcon (dukeIcon);
}
}
Додаток 13
java.awt. *; java.awt.event. *; java.util. *; javax.swing. *; javax.swing.Timer;
//to resolve conflict with java.util.Timer
class TimerTest
{static void main (String [] args)
{listener=new TimePrinter ();
//construct a timer that calls the listener
//once every 10 secondst=new Timer (10000, listener) ;. start ();
. showMessageDialog (null, Quit program? ) ;. exit (0);
}
}
TimePrinter implements ActionListener
{void actionPerformed (ActionEvent event)
{now=new Date () ;. out.println ( At the tone, the time is + now) ;. getDefaultToolkit (). beep ();
}
}