1

i want to create a j frame,user put a question value in J Text field and application display mathematical symbol but i have no idea about it is there is any package in java library or any other technology like quadratic question

a=5
b=10
c=15

display

ax^2+10x=15

D=b^2-4ac

alpha=(-b+root(D)/2a


beta=(-b-root(D)/2a  

put it is very ugly i want to display like math symbolic please give me any idea ,tutorial etc.... my code

    package linerEquations;

    import javax.swing.*;

    import java.awt.Font;
    import java.awt.event.*;

    class MatrixCalculator extends JFrame implements ActionListener{

        JLabel jlTitle,Xa1,Yb1,C1;
        JLabel Xa2,Yb2,C2;
        JPanel jp;
        JTextField jtXa1,jtYb1,jtC1;
        JTextField jtXa2,jtYb2,jtC2;
        JButton jbExit,jbClear,jbSolution,jbShowGraph;
        static MatrixCalculator fram;

        MatrixCalculator(){
            setTitle("Matrix Calculator");
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            getContentPane().setLayout(null);
            setSize(500,265);
            setResizable(false);
            //jPanle 
            jp=new JPanel();
            jp.setLocation(10, 11);
            jp.setLayout(null);
            jp.setSize(464,194);
            getContentPane().add(jp);
            //Title
            jlTitle =new JLabel("Linear Equestion of Two Variable");
            jlTitle.setFont(new Font("Tahoma", Font.BOLD, 19));
            jlTitle.setBounds(61,11,332,20);
            jp.add(jlTitle);
            //Label
            //Xa1
            Xa1 =new JLabel("Xa1= ");
            Xa1.setBounds(78,64,50,20);
            jp.add(Xa1);
            //Yb1
            Yb1 =new JLabel("Yb1= ");
            Yb1.setBounds(178,64,50,20);
            jp.add(Yb1);
            //C1
            C1 =new JLabel("C1= ");
            C1.setBounds(278,64,50,20);
            jp.add(C1);
            //JTextField
            //jtXa1
            jtXa1 =new JTextField();
            jtXa1.setBounds(108,64,50,20);
            jp.add(jtXa1);
            //jtYb1
            jtYb1 =new JTextField();
            jtYb1.setBounds(208,64,50,20);
            jp.add(jtYb1);
            //jtC1
            jtC1 =new JTextField();
            jtC1.setBounds(308,64,50,20);
            jp.add(jtC1);
            //Label  2
            //Xa2
            Xa2 =new JLabel("Xa2= ");
            Xa2.setBounds(78,94,50,20);
            jp.add(Xa2);
            //Yb2
            Yb2 =new JLabel("Yb2= ");
            Yb2.setBounds(178,94,50,20);
            jp.add(Yb2);
            //C2
            C2 =new JLabel("C2= ");
            C2.setBounds(278,94,50,20);
            jp.add(C2);
            //JTextField
            //jtXa2
            jtXa2 =new JTextField();
            jtXa2.setBounds(108,94,50,20);
            jp.add(jtXa2);
            //jtYb2
            jtYb2 =new JTextField();
            jtYb2.setBounds(208,94,50,20);
            jp.add(jtYb2);
            //jtC2
            jtC2 =new JTextField();
            jtC2.setBounds(308,94,50,20);
            jp.add(jtC2);

            //Button 
            //Solution Button
            jbSolution =new JButton("Solution");
            jbSolution.setBounds(20,150,80,30);
            jbSolution.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Solution(fram);

                }
            });
            jp.add(jbSolution);
            //ShowGraph Button
            jbShowGraph =new JButton("Show Graph");
            jbShowGraph.setBounds(108,150,117,30);
            jp.add(jbShowGraph);
            //Clear Button
            jbClear =new JButton("Clear");
            jbClear.setBounds(249,150,80,30);
            jp.add(jbClear);
            //Exit Button
            jbExit =new JButton("Exit");
            jbExit.setBounds(352,150,80,30);
            jbExit.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);

                }
            });
            jp.add(jbExit);

        }

        public static void main(String args[]){
            fram=new MatrixCalculator();
        }

        public void actionPerformed(ActionEvent e){

        }


    }
pratim_b
  • 1,160
  • 10
  • 29
anil
  • 143
  • 2
  • 4
  • 13

1 Answers1

3

You don't need any library, you can format the String as HTML and display it.

For example, if you want to display ax^2+10x=15 on the jbSolution button, you should do like this:

    int a=5, b=10, c=15;

    String j = "<html>"+a+"x<sup>2</sup>+"+b+" x = "+c+"</html>";
    jbSolution =new JButton(j);
    jbSolution.setBounds(20,150,130,30);

For D=b^2-4ac

String j = "<html>D = b<sup>2</sup> -  4ac</html>";

For beta=(-b-root(D)/2a

String j = "<html>beta=(-b-\u221AD)/2a</html>";
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51