package kmiskaiciuoklis;
import java.awt.BorderLayout;
import javax.swing.JFrame;
//kmiGUI.java turinys
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
interface Interfeisas {
public JLabel item1 = null;
public JLabel item2 = null;
public JTextField mase = null;
public JTextField ugis = null;
public JButton mygtukas = null;
}
public class Main extends JFrame implements Interfeisas {
private JLabel item1;
private JLabel item2;
private JTextField mase;
private JTextField ugis;
private JButton mygtukas;
public float indeksas;
public Main () {
super("KMI skaiciuokle");
setLayout(new FlowLayout());
item1 = new JLabel("Mase: ");
item1.setToolTipText("Iveskite zmogaus mase kilogramais");
add(item1);
mase = new JTextField(10);
mase.setToolTipText("Iveskite zmogaus mase kilogramais");
add(mase);
item2 = new JLabel("Ugis: ");
item2.setToolTipText("Iveskite zmogaus ugi centimetrais");
add(item2);
ugis = new JTextField(10);
ugis.setToolTipText("Iveskite zmogaus ugi centimetrais");
add(ugis);
mygtukas = new JButton("Skaiciuoti");
add(mygtukas);
HandlerClass handler = new HandlerClass();
mygtukas.addActionListener(handler);
ImageIcon image = new ImageIcon("zmogeliukas.jpg");
//image.setLayout(new BorderLayout());
//JPanel.add(image, BorderLayout.SOUTH);
}
void storulis () {
if (indeksas > 25)
JOptionPane.showMessageDialog (null,"tu storas");
}
void skeletas (){
if (indeksas < 18)
JOptionPane.showMessageDialog(null,"per kudas,eik pavalgyk");
}
void normalus (){
if (indeksas >18 && indeksas <25)
JOptionPane.showMessageDialog(null,"esi normalus");
}
private class HandlerClass implements ActionListener {
public void actionPerformed (ActionEvent event) {
if (event.getSource() == mygtukas) {
try {
float u = Float.parseFloat(ugis.getText()), m = Float.parseFloat(mase.getText());
indeksas = (float)Math.round(m/(u*u/10000)*1000)/1000;
JOptionPane.showMessageDialog(null, "Kuno mases indeksas yra "+indeksas,"Apskaiciuotas KMI",JOptionPane.INFORMATION_MESSAGE);
}
catch (NumberFormatException e) {
System.out.println("error");
}
}
}
}
}