hi danpost
this is another one of the calculator that i have to build. this one is the triangle. I am getting 2 errors with it. I am trying to use the MigLayout api but it is giving me an error saying: it is telling me to create a class with a constructor
do I have to create a class called MigLayout with a constructor and why
another error am getting is. am trying to do this: frame.getContentPane().add(clear) and I am getting this error:
no suitable method found for add(String)
method Component.add(PopupMenu) is not applicable
(argument mismatch; String cannot be converted to PopupMenu)
method Container.add(Component) is not applicable
(argument mismatch; String cannot be converted to Component)
can u tell me what does that error meant and how can i fix it. here is the codes that I use. and also can u tell me if the calculation is correct.
the question is to find the area of a triangle, using a java gui and it is valid triangle.
here is the codes.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package quadratric;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Triangle_Calculator extends JFrame implements ActionListener {
public Triangle_Calculator(){
JButton clear = new JButton("clear");
JButton exit = new JButton("exit");
Tools tls = new Tools();
}
public static void main(String[]args ){
JFrame frame = new JFrame("Testing MigLayout");
JPanel contentPane = new JPanel(new MigLayout("fillx")); the error is right now
//row 1
JLabel areaLabel = new JLabel("Area of Triangle");
areaLabel.setFont(areaLabel.getFont().deriveFont(16.0f));
areaLabel.setHorizontalAlignment(JLabel.CENTER);
contentPane.add(areaLabel,"spanx, growx, wrap");
frame.setTitle("Triangle Calculator");
frame.getContentPane().add("clear"); the another error is right here
//row 2
JLabel sideA = new JLabel("sideA");
contentPane.add(sideA, "alignx trailing");
JTextField sideAfield = new JTextField();
sideAfield.setColumns(6);
contentPane.add(sideAfield,"alignx leading wrap");
//row3
JLabel sideB = new JLabel("Side B");
contentPane.add(sideB, "alignx trailing");
JTextField sideBfield = new JTextField();
sideBfield.setColumns(6);
contentPane.add(sideBfield, "alignx leading, wrap");
//row 4
JLabel sideC = new JLabel("Side C");
contentPane.add(sideC, "alignx trailing");
JTextField sideCfield = new JTextField();
sideCfield.setColumns(6);
contentPane.add(sideCfield,"alignx leading, wrap");
//row 5
JButton calbtn = new JButton("Calculator Area");
contentPane.add(calbtn, "spanx, grows");
JTextField ans = new JTextField("ans");
calbtn.addActionListener(null);
frame.setContentPane(contentPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equalsIgnoreCase("exit"))
System.exit(0);
if(e.getActionCommand().equalsIgnoreCase("clear"))
if(e.getActionCommand().equalsIgnoreCase("ans"))
}
private double areaTriangle(double sideA,double sideB,double sideC){
if(isTriangleValid(sideA, sideB,sideC) == true){
System.out.println(areaTriangle(sideA,sideB, sideC));
}
return 0;
}
public boolean isTriangleValid(double sideA, double sideB, double sideC){
if((sideA + sideB) > sideC && (sideA + sideC) > sideB && (sideB + sideC) > sideA){
return true;
}
else{
}
return false;
}
}


