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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | /* * 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 ; } } |