Mã:
/*
* 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 times;
import com.sun.corba.se.spi.orbutil.fsm.Guard;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class abc {
private JFrame frmCalculate;
private JTextField textField;
private Double value1 = 0d;
private Double value2 = 0d;
private String regular = "";
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
abc window = new abc();
window.frmCalculate.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public abc() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmCalculate = new JFrame();
frmCalculate.setAlwaysOnTop(true);
frmCalculate.setTitle("Calculate");
frmCalculate.setBounds(100, 100, 271, 337);
frmCalculate.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmCalculate.getContentPane().setLayout(null);
JButton btn1 = new JButton("1");
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn1.getText());
textField.setText(String.valueOf(so));
}
});
btn1.setBounds(0, 51, 64, 49);
frmCalculate.getContentPane().add(btn1);
JButton btn2 = new JButton("2");
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn2.getText());
textField.setText(String.valueOf(so));
}
});
btn2.setBounds(64, 51, 64, 49);
frmCalculate.getContentPane().add(btn2);
JButton btn3 = new JButton("3");
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn3.getText());
textField.setText(String.valueOf(so));
}
});
btn3.setBounds(128, 51, 64, 49);
frmCalculate.getContentPane().add(btn3);
JButton btnCong = new JButton("+");
btnCong.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnCong.setBounds(192, 51, 64, 49);
frmCalculate.getContentPane().add(btnCong);
JButton btn4 = new JButton("4");
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn4.getText());
textField.setText(String.valueOf(so));
}
});
btn4.setBounds(0, 100, 64, 49);
frmCalculate.getContentPane().add(btn4);
JButton btn5 = new JButton("5");
btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn5.getText());
textField.setText(String.valueOf(so));
}
});
btn5.setBounds(64, 100, 64, 49);
frmCalculate.getContentPane().add(btn5);
JButton btn6 = new JButton("6");
btn6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn6.getText());
textField.setText(String.valueOf(so));
}
});
btn6.setBounds(128, 100, 64, 49);
frmCalculate.getContentPane().add(btn6);
JButton btnTru = new JButton("-");
btnTru.setBounds(192, 100, 64, 49);
frmCalculate.getContentPane().add(btnTru);
JButton btn7 = new JButton("7");
btn7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn7.getText());
textField.setText(String.valueOf(so));
}
});
btn7.setBounds(0, 149, 64, 49);
frmCalculate.getContentPane().add(btn7);
JButton btn8 = new JButton("8");
btn8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn8.getText());
textField.setText(String.valueOf(so));
}
});
btn8.setBounds(64, 149, 64, 49);
frmCalculate.getContentPane().add(btn8);
JButton btn9 = new JButton("9");
btn9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn9.getText());
textField.setText(String.valueOf(so));
}
});
btn9.setBounds(128, 149, 64, 49);
frmCalculate.getContentPane().add(btn9);
JButton btnNhan = new JButton("*");
btnNhan.setBounds(192, 149, 64, 49);
frmCalculate.getContentPane().add(btnNhan);
JButton btn0 = new JButton("0");
btn0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String gt = textField.getText();
if(gt.length() < 12)
if(gt.equals("0"))
gt = "";
long so = Long.parseLong(gt + btn0.getText());
textField.setText(String.valueOf(so));
}
});
btn0.setBounds(0, 198, 64, 49);
frmCalculate.getContentPane().add(btn0);
JButton btnCham = new JButton(".");
btnCham.setBounds(64, 198, 64, 49);
frmCalculate.getContentPane().add(btnCham);
JButton btnBang = new JButton("=");
btnBang.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnBang.setBounds(128, 198, 64, 49);
frmCalculate.getContentPane().add(btnBang);
JButton btnChia = new JButton("/");
btnChia.setBounds(192, 198, 64, 49);
frmCalculate.getContentPane().add(btnChia);
textField = new JTextField();
textField.setEditable(false);
textField.setBounds(0, 2, 256, 49);
frmCalculate.getContentPane().add(textField);
textField.setColumns(10);
JButton btnXoa = new JButton("C");
btnXoa.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText(null);
}
});
btnXoa.setBounds(0, 247, 256, 49);
frmCalculate.getContentPane().add(btnXoa);
addMouseListener(btnCong);
addMouseListener(btnBang);
}
private void addMouseListener(final JComponent component) {
component.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent event) {
if(!regular.equals("")){
value2 = Double.parseDouble(textField.getText());
textField.setText(value1+value2 +"");
}
if(((JButton) component).getText().equals("+")){
regular = "+";
value1 = Double.parseDouble(textField.getText());
textField.setText(null);
}
}
});
}
}
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...