计算器java代码报告 java计算器程序代码( 二 )


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
【计算器java代码报告 java计算器程序代码】}// /editor-fold
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private class jisuanAC implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if(e.getSource()== addBtn)
{
int number1 = Integer.parseInt(num1.getText());
int number2 = Integer.parseInt(num2.getText());
int rs = number1 + number2;
result.setText(String.valueOf(rs));
}
}
}
// Variables declaration - do not modify
private javax.swing.JButton addBtn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField num1;
private javax.swing.JTextField num2;
private javax.swing.JTextField result;
}
这是只有一个加法的例子!希望帮到你
用java程序编写一个计算器给你一个参考,希望不要被百度吞了当晚餐
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Calculator {
//计算器面板
private JFrame f = new JFrame("Calculator");
//输入面扳
private JPanel inputPanel = new JPanel();
//加减乘除面板
private JPanel operationPanel = new JPanel();
//数字面板
private JPanel buttonsPanel = new JPanel();
//输入数据文本框
private JTextField input = new JTextField(20);
//退格键
private JButton backspace = new JButton("BackSpace");
//清空
private JButton CE = new JButton("CE");
//删除
private JButton C = new JButton("C");
//四则运算符号键
private JButton add = new JButton("+");
private JButton sub = new JButton("-");
private JButton mul = new JButton("*");
private JButton div = new JButton("/");
//小数点
private JButton decimal = new JButton(".");
//等号
private JButton equal = new JButton("=");
//数字键
private JButton zero = new JButton("0");
private JButton one = new JButton("1");
private JButton two = new JButton("2");
private JButton three = new JButton("3");
private JButton four = new JButton("4");
private JButton five = new JButton("5");
private JButton six = new JButton("6");
private JButton seven = new JButton("7");
private JButton eight = new JButton("8");
private JButton nine = new JButton("9");
private String num1 = "";//保存第一个运算数字

推荐阅读