| 1 | package Kalkulator; |
| 2 | |
| 3 | import javax.swing.*; |
| 4 | |
| 5 | /** |
| 6 | * This example shows how to create GUI application which can be run both |
| 7 | * as HTML embeded web applet and as standalone application |
| 8 | * @author harvie |
| 9 | */ |
| 10 | |
| 11 | class AppGui extends JPanel { |
| 12 | AppGui() { |
| 13 | setLayout(new java.awt.GridLayout(0, 2)); |
| 14 | |
| 15 | JLabel lblVklad = new JLabel("vklad"); |
| 16 | final JTextField txtVklad = new JTextField(); |
| 17 | |
| 18 | JLabel lblMira = new JLabel("urok. mira"); |
| 19 | final JTextField txtMira = new JTextField(); |
| 20 | |
| 21 | JLabel lblRoky = new JLabel("pocet let"); |
| 22 | final JTextField txtRoky = new JTextField(); |
| 23 | |
| 24 | JButton btnGo = new JButton("Go"); |
| 25 | final JLabel lblCelkem = new JLabel("zadej data"); |
| 26 | |
| 27 | add(lblVklad); |
| 28 | add(txtVklad); |
| 29 | add(lblMira); |
| 30 | add(txtMira); |
| 31 | add(lblRoky); |
| 32 | add(txtRoky); |
| 33 | add(btnGo); |
| 34 | add(lblCelkem); |
| 35 | |
| 36 | btnGo.addActionListener(new java.awt.event.ActionListener() { |
| 37 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
| 38 | double v = new Double(txtVklad.getText()); |
| 39 | double u = new Double(txtMira.getText()); |
| 40 | double r = new Double(txtRoky.getText()); |
| 41 | for(;r>0;r--) v += v*(u/100); |
| 42 | lblCelkem.setText(v+""); |
| 43 | } |
| 44 | }); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public class Kalkulator extends JApplet { |
| 49 | |
| 50 | public void init() { |
| 51 | getContentPane().add(new AppGui()); |
| 52 | } |
| 53 | |
| 54 | public static void main(String[] args) { |
| 55 | JFrame f = new JFrame("Applet window"); |
| 56 | f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
| 57 | f.setSize(640,480); |
| 58 | f.getContentPane().add(new AppGui()); |
| 59 | f.setVisible(true); |
| 60 | } |
| 61 | |
| 62 | // TODO overwrite start(), stop() and destroy() methods |
| 63 | } |