///Md. Alamgir Hossain
////Dept. of Computer Science & Engineering
///Jessore University of Scoence & Technology
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;
import javax.swing.border.BevelBorder;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URL;
public class Main_Frame extends JFrame {
private JPanel contentPane;
private JTextField txtdisplay;
/**
* Launch the application.
*/
double firstnum;
double secondnum;
double res;
String operation;
String ans;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main_Frame frame = new Main_Frame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main_Frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
setLocationRelativeTo(null);
setBounds(100, 100, 231, 282);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
txtdisplay = new JTextField();
txtdisplay.setFont(new Font("Monotype Corsiva", Font.PLAIN, 15));
txtdisplay.setHorizontalAlignment(SwingConstants.RIGHT);
txtdisplay.setBounds(10, 11, 210, 29);
contentPane.add(txtdisplay);
txtdisplay.setColumns(10);
JButton btnNewButton = new JButton("C");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
txtdisplay.setText("");
}
});
btnNewButton.setBounds(10, 62, 45, 23);
contentPane.add(btnNewButton);
final JButton btn7 = new JButton("7");
btn7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String your_enter_num = txtdisplay.getText() + btn7.getText();
txtdisplay.setText(your_enter_num);
}
});
btn7.setBounds(10, 94, 45, 23);
contentPane.add(btn7);
final JButton btn8 = new JButton("8");
btn8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String your_enter_num = txtdisplay.getText() + btn8.getText();
txtdisplay.setText(your_enter_num);
}
});
btn8.setBounds(65, 94, 45, 23);
contentPane.add(btn8);
final JButton btn9 = new JButton("9");
btn9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn9.getText();
txtdisplay.setText(your_enter_num);
}
});
btn9.setBounds(120, 94, 45, 23);
contentPane.add(btn9);
JButton button_3 = new JButton("*");
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
firstnum = Double.parseDouble(txtdisplay.getText());
txtdisplay.setText("");
operation = "*";
}
});
button_3.setBounds(175, 94, 45, 23);
contentPane.add(button_3);
final JButton btn4 = new JButton("4");
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn4.getText();
txtdisplay.setText(your_enter_num);
}
});
btn4.setBounds(10, 128, 45, 23);
contentPane.add(btn4);
final JButton btn5 = new JButton("5");
btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn5.getText();
txtdisplay.setText(your_enter_num);
}
});
btn5.setBounds(65, 128, 45, 23);
contentPane.add(btn5);
final JButton btn6 = new JButton("6");
btn6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn6.getText();
txtdisplay.setText(your_enter_num);
}
});
btn6.setBounds(120, 128, 45, 23);
contentPane.add(btn6);
JButton button_7 = new JButton("-");
button_7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
firstnum = Double.parseDouble(txtdisplay.getText());
txtdisplay.setText("");
operation = "-";
}
});
button_7.setBounds(175, 128, 45, 23);
contentPane.add(button_7);
final JButton btn1 = new JButton("1");
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn1.getText();
txtdisplay.setText(your_enter_num);
}
});
btn1.setBounds(10, 160, 45, 23);
contentPane.add(btn1);
final JButton btn2 = new JButton("2");
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn2.getText();
txtdisplay.setText(your_enter_num);
}
});
btn2.setBounds(65, 162, 45, 23);
contentPane.add(btn2);
final JButton btn3 = new JButton("3");
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn3.getText();
txtdisplay.setText(your_enter_num);
}
});
btn3.setBounds(120, 162, 45, 23);
contentPane.add(btn3);
JButton button_11 = new JButton("+");
button_11.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
firstnum = Double.parseDouble(txtdisplay.getText());
txtdisplay.setText("");
operation = "+";
}
});
button_11.setBounds(175, 162, 45, 23);
contentPane.add(button_11);
final JButton btn0 = new JButton("0");
btn0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btn0.getText();
txtdisplay.setText(your_enter_num);
}
});
btn0.setBounds(10, 194, 45, 23);
contentPane.add(btn0);
final JButton btnp = new JButton(".");
btnp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String your_enter_num = txtdisplay.getText() + btnp.getText();
txtdisplay.setText(your_enter_num);
}
});
btnp.setFont(new Font("Times New Roman", Font.PLAIN, 12));
btnp.setBounds(65, 194, 45, 23);
contentPane.add(btnp);
JButton button_14 = new JButton("+/-");
button_14.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double x= Double.parseDouble(String.valueOf(txtdisplay.getText()));
x = x * (-1);
txtdisplay.setText(String.valueOf(x));
}
});
button_14.setFont(new Font("Tahoma", Font.PLAIN, 8));
button_14.setBounds(120, 196, 45, 23);
contentPane.add(button_14);
JButton button_15 = new JButton("=");
button_15.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
secondnum = Double.parseDouble(txtdisplay.getText());
if(operation == "+")
{
res = firstnum + secondnum;
ans = String.format("%.0f", res);
txtdisplay.setText(ans);
}
else if(operation == "-")
{
res = firstnum - secondnum;
ans = String.format("%.0f", res);
txtdisplay.setText(ans);
}
else if(operation == "*")
{
res = firstnum * secondnum;
ans = String.format("%.0f", res);
txtdisplay.setText(ans);
}
else if(operation == "/")
{
res = firstnum / secondnum;
ans = String.format("%.0f", res);
txtdisplay.setText(ans);
}
else if(operation == "%")
{
res = firstnum % secondnum;
ans = String.format("%.0f", res);
txtdisplay.setText(ans);
}
}
});
button_15.setBounds(175, 196, 45, 23);
contentPane.add(button_15);
JButton button_16 = new JButton("%");
button_16.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
firstnum = Double.parseDouble(txtdisplay.getText());
txtdisplay.setText("");
operation = "%";
}
});
button_16.setBounds(65, 62, 45, 23);
contentPane.add(button_16);
JButton btnBk = new JButton("B");
btnBk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String back = null;
if(txtdisplay.getText().length()>0)
{
StringBuilder strbldr = new StringBuilder(txtdisplay.getText());
strbldr.deleteCharAt(txtdisplay.getText().length()-1);
back = strbldr.toString();
txtdisplay.setText(back);
}
}
});
btnBk.setBounds(120, 62, 45, 23);
contentPane.add(btnBk);
JButton button_18 = new JButton("/");
button_18.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
firstnum = Double.parseDouble(txtdisplay.getText());
txtdisplay.setText("");
operation = "/";
}
});
button_18.setBounds(175, 62, 45, 23);
contentPane.add(button_18);
JPanel panel = new JPanel();
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
try {
String url ="http://alamgir-hossain.simplesite.com/";
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
panel.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, new Color(102, 0, 0)));
panel.setBounds(46, 225, 145, 25);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblDesignBy = new JLabel("Design by ");
lblDesignBy.setFont(new Font("Monotype Corsiva", Font.BOLD, 15));
lblDesignBy.setBounds(6, 3, 133, 20);
panel.add(lblDesignBy);
lblDesignBy.setHorizontalAlignment(SwingConstants.CENTER);
}
}
No comments:
Post a Comment