ArithmeticOperation.java
import java.awt.EventQueue;
import java.math.BigDecimal;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ArithmeticOperation extends JFrame {
private JPanel contentPane;
private JTextField text_fno;
private JTextField text_sno;
private JTextField text_ans;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ArithmeticOperation frame = new ArithmeticOperation();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ArithmeticOperation() {
setTitle("Arithmetic Opertion");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel_arithmetic = new JPanel();
panel_arithmetic.setBounds(40, 24, 417, 227);
contentPane.add(panel_arithmetic);
JLabel lblEnterNo = new JLabel("Enter No :-");
lblEnterNo.setBounds(10, 29, 61, 14);
lblEnterNo.setHorizontalAlignment(SwingConstants.RIGHT);
JLabel label = new JLabel("Enter No :-");
label.setBounds(10, 81, 61, 14);
label.setHorizontalAlignment(SwingConstants.RIGHT);
text_fno = new JTextField();
text_fno.setBounds(75, 26, 86, 20);
text_fno.setColumns(10);
text_sno = new JTextField();
text_sno.setBounds(75, 78, 86, 20);
text_sno.setColumns(10);
text_ans = new JTextField();
text_ans.setBounds(75, 125, 86, 20);
text_ans.setColumns(10);
JLabel lblAnswer = new JLabel("Answer :-");
lblAnswer.setBounds(10, 128, 61, 14);
lblAnswer.setHorizontalAlignment(SwingConstants.RIGHT);
JButton btnAdditon = new JButton("Additon");
btnAdditon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
BigDecimal fno=new BigDecimal(text_fno.getText());
BigDecimal sno=new BigDecimal(text_sno.getText());
try
{
BigDecimal ans=addition(fno, sno);
text_ans.setText(ans.toString());
} catch (Exception e2) {
// TODO: handle exception
JOptionPane.showMessageDialog(contentPane, "Error In Arithmetic Operation","Error",JOptionPane.ERROR_MESSAGE);
}
}
});
btnAdditon.setBounds(216, 25, 115, 23);
JButton btnSubstraction = new JButton("Substraction");
btnSubstraction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
BigDecimal fno=new BigDecimal(text_fno.getText());
BigDecimal sno=new BigDecimal(text_sno.getText());
try
{
BigDecimal ans=substraction(fno, sno);
text_ans.setText(ans.toString());
} catch (Exception e2) {
// TODO: handle exception
JOptionPane.showMessageDialog(contentPane, "Error In Arithmetic Operation","Error",JOptionPane.ERROR_MESSAGE);
}
}
});
btnSubstraction.setBounds(216, 59, 115, 23);
JButton btnMutltiplication = new JButton("Mutltiplication");
btnMutltiplication.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
BigDecimal fno=new BigDecimal(text_fno.getText());
BigDecimal sno=new BigDecimal(text_sno.getText());
try
{
BigDecimal ans=multiplication(fno, sno);
text_ans.setText(ans.toString());
} catch (Exception e2) {
// TODO: handle exception
JOptionPane.showMessageDialog(contentPane, "Error In Arithmetic Operation","Error",JOptionPane.ERROR_MESSAGE);
}
}
});
btnMutltiplication.setBounds(216, 93, 115, 23);
JButton btnDivison = new JButton("Divison");
btnDivison.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
BigDecimal fno=new BigDecimal(text_fno.getText());
BigDecimal sno=new BigDecimal(text_sno.getText());
try
{
BigDecimal ans=division(fno, sno);
text_ans.setText(ans.toString());
}
catch (ArithmeticException e2)
{
// TODO: handle exception
JOptionPane.showMessageDialog(contentPane, "Error In Arithmetic Operation","Error",JOptionPane.ERROR_MESSAGE);
}
catch (Exception e2) {
// TODO: handle exception
JOptionPane.showMessageDialog(contentPane, "Error In Arithmetic Operation","Error",JOptionPane.ERROR_MESSAGE);
}
}
});
btnDivison.setBounds(216, 128, 115, 23);
panel_arithmetic.setLayout(null);
panel_arithmetic.add(lblEnterNo);
panel_arithmetic.add(text_fno);
panel_arithmetic.add(btnAdditon);
panel_arithmetic.add(label);
panel_arithmetic.add(text_sno);
panel_arithmetic.add(btnSubstraction);
panel_arithmetic.add(btnDivison);
panel_arithmetic.add(lblAnswer);
panel_arithmetic.add(text_ans);
panel_arithmetic.add(btnMutltiplication);
}
public BigDecimal addition(BigDecimal fno,BigDecimal sno)
{
return fno.add(sno);
}
public BigDecimal substraction(BigDecimal fno,BigDecimal sno)
{
return fno.subtract(sno);
}
public BigDecimal multiplication(BigDecimal fno,BigDecimal sno)
{
return fno.multiply(sno);
}
public BigDecimal division(BigDecimal fno,BigDecimal sno)
{
return fno.divide(sno);
}
}
No comments:
Post a Comment