内容发布更新时间 : 2024/11/16 2:48:55星期一 下面是文章的全部内容请认真阅读。
openMenuItem.setText(\fileMenu.add(openMenuItem); saveMenuItem.setText(\fileMenu.add(saveMenuItem);
saveAsMenuItem.setText(\fileMenu.add(saveAsMenuItem);
exitMenuItem.setText(\
exitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitMenuItemActionPerformed(evt); } });
fileMenu.add(exitMenuItem); menuBar.add(fileMenu); helpMenu.setText(\
contentsMenuItem.setText(\helpMenu.add(contentsMenuItem); aboutMenuItem.setText(\helpMenu.add(aboutMenuItem); editMenu.setText(\cutMenuItem.setText(\editMenu.add(cutMenuItem); copyMenuItem.setText(\editMenu.add(copyMenuItem); pasteMenuItem.setText(\editMenu.add(pasteMenuItem); deleteMenuItem.setText(\editMenu.add(deleteMenuItem); helpMenu.add(editMenu); menuBar.add(helpMenu);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane());
getContentPane().setLayout(layout); layout
.setHorizontalGroup(layout .createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout
.createSequentialGroup() .addContainerGap() .addGroup( layout
.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING,
false) .addGroup( layout .createSequentialGroup()
.addComponent(
.addGap(21, 21, 21))); layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout
.createSequentialGroup() .addGap(26, 26, 26) .addComponent( txtText, javax.swing.GroupLayout.PREFERRED_SIZE,
64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup( layout
.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent( //其他按键功能设置已省略 jButton26,
javax.swing.GroupLayout.PREFERRED_SIZE,38,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton32, javax.swing.GroupLayout.PREFERRED_SIZE,83,
javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(60,Short.MAX_VALUE)));
pack(); }
boolean isOperPressed = false; //为true时输入下一个数字时清屏
int oper = 0; //1实现加, 2实现减, 3实现乘, 4实现除, 5实现取余 int number1 = 0; //参与运算的第一个数字,保存在number1中
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { //←按键,实现回退功能
String s = txtText.getText(); //获取屏幕上的字符串 int num = Integer.parseInt(s); //转换为整形 num = num / 10;
s = Integer.toString(num); //转换为字符型 txtText.setText(s); //显示到屏幕上 }
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { //C按键,实现清屏功能 txtText.setText(\ }
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { //CE按键,实现初始化功能 txtText.setText(\ isOperPressed = false; oper = 0; number1 = 0; }
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
//取余
if(oper !=0){ //if else 语句实现连运算 下同 dengyu(); oper=5; } else{
String s = txtText.getText();
number1 = Integer.parseInt(s); //保存屏幕上的数字 oper = 5;
isOperPressed = true; //清屏 } }
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) { //除
if(oper !=0){ dengyu(); oper=4; } else{
String s = txtText.getText(); number1 = Integer.parseInt(s); oper = 4;
isOperPressed = true; } }
private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) { //乘
if(oper !=0){ dengyu(); oper=3; } else{
String s = txtText.getText(); number1 = Integer.parseInt(s); oper = 3;
isOperPressed = true; } }
private void jButton26ActionPerformed(java.awt.event.ActionEvent evt) { //减
if(oper !=0){ dengyu();