Hello guys, so i want create little program which enter the number, ant program says triangle exist or not. So code :
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Panel extends JFrame implements ActionListener { JTextField one; JTextField two; JTextField three; JButton check; JPanel panele; JLabel answer; int a,b,c; public Panel() { panele = new JPanel(); panele.setSize(500,500); panele.setLayout(null); one = new JTextField(); one.setSize(120,30); one.setLocation(20,30); one.setFont(new Font("Arial",Font.BOLD,24)); two = new JTextField(); two.setSize(120,30); two.setLocation(20,65); two.setFont(new Font("Arial",Font.BOLD,24)); three = new JTextField(); three.setSize(120,30); three.setLocation(20,100); three.setFont(new Font("Arial",Font.BOLD,24)); check = new JButton("Check"); check.setSize(70,70); check.setLocation(170,30); add(panele); panele.add(one); panele.add(two); panele.add(three); panele.add(check); check.addActionListener(this); } public void actionPerformed(ActionEvent e) { try { a = (int) Integer.parseInt(one.getText()); b = (int) Integer.parseInt(two.getText()); c = (int) Integer.parseInt(three.getText()); }catch(Exception e1) { JOptionPane.showMessageDialog(null,"Only Numbers","Klaida",JOptionPane.ERROR_MESSAGE); } /* * Or triangle exist?? Formul : * a+b > c * a+c > b * c+b > a * */ if (a+b > c || a+c > b || c+b > a) { JOptionPane.showMessageDialog(null,"Exist","Atsakymas",JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null,"Not exist","Atsakymas",JOptionPane.INFORMATION_MESSAGE); } } }
So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist. How fix it? Can you help me? Thanks