资源简介
JAVA WindowBuilder 制作的简易粗暴的计算器,适合初学者。
package 计算器;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
public class 计算器5 extends JFrame {
private JPanel contentPane;
private JTextField textField;
private double v1, v2, value;
private char operator;
private boolean reop = false;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
计算器5 frame = new 计算器5();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
代码片段和文件信息
package 计算器;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.Layoutstyle.ComponentPlacement;
public class 计算器5 extends Jframe {
private JPanel contentPane;
private JTextField textField;
private double v1 v2 value;
private char operator;
private boolean reop = false;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
计算器5 frame = new 计算器5();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static int getSubCount_2(String str String key) {
int count = 0;
int index = 0;
while ((index = str.indexOf(key index)) != -1) {
index = index + key.length();
count++;
}
return count;
}
/**
* Create the frame.
*/
public 计算器5() {
setResizable(false);
JButton button_4 = new JButton(“0“);
button_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(reop ==true&&oo==1) textField.setText(““);
if((textField.getText().indexOf(‘0‘)==-1||textField.getText().charAt(0)!=‘0‘||textField.getText().indexOf(‘0‘) String text = textField.getText() +‘0‘;
textField.setText(text);oo=0;
}
}
});
JButton btnNewButton = new JButton(“7“);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(reop ==true&&oo==1)textField.setText(““);
String text = textField.getText() +‘7‘;
textField.setText(text);oo=0;
}
});
JButton btnNewButton_1 = new JButton(“4“);
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(reop ==true&&oo==1)textField.setText(““);
String text = textField.getText() +‘4‘;
textField.setText(text);oo=0;
}
});
JButton btnNewButton_2 = new JButton(“1“);
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(reop ==true&&oo==1)textField.setText(““);
String text = textField.getText() +‘1‘;
textField.setText(text);oo=0;
}
});
JButton btnNewButton_3 = new JButton(“8“);
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(reop ==true&&oo==1)textField.setText(““);
String text = textField.getText
- 上一篇:android根据经纬度获取地址
- 下一篇:Java面向对象程序设计(源代码)
相关资源
- Java面向对象程序设计(源代码)
- 农行Java笔试题
- 康博嘉信息科技有限公司Java笔试题
- java笔试题大集合及答案另附各大公司
- Bezier曲线代码 java
- JAVA链表实现类数据结构学习
- javaSwing万年历小程序
- iOS日志框CocoaLumberjack 使用demo,包含
- java编程思想(第四版)书中源码及习
- LZW实现Java压缩解压
- java实现数据的备份与恢复jar包
- java3D显示一个球的代码
- 利用Java3D1.4制成的动态爬山算法
- Activiti7视频教程Java通用型工作流开发
- 基于Java的课堂随机点名器
- 基于Java的课堂_随机点名器
- 使用java实现的Bezier曲线
- java + sql 银行管理系统
- QR分解的Java实现
- ISM解释结构模型算法的JAVA
- Java+ajax写的登录
- Java多人聊天室(有登录注册)
- 根据配置文件自动构造Bean类
- 基于java-web的图书管理系统带源码
- 大文件上传的javawebuploader包括前台和
- Java-保存计算过程的计算器
- SpringBoot集成Elasticsearch已实现各种ES操
- java 抽奖系统jar 完整版
- JSP 和 JavaBean连接sql server验证登录
- 基于JAVA的小区物业管理系统 论文
评论
共有 条评论