java期末考试编程题 界面_救急啊!!!期末考试!怎样用JAVA的GUI(图形用户界面)来设计一个小程序!...
展开全部
给你找了一个,我试过,可以用
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.*;//GUi之前要吧这两个都引进来32313133353236313431303231363533e59b9ee7ad9431333363373733
public class Computer extends JFrame implements ActionListener
{
JButton a1,a2,a3,a4,a5,a6,a7,a8,a9,a0;
JButton b1,b2,b3,b4;
JButton c1,c2,c3,c4;
JTextField t1,t2;
JPanel p1,p2;
JLabel bq1,bq2;
String fuhao;
Double count,count2;
boolean chose=false,cliks;
public static void main(String[] args){
Computer l = new Computer();
}
public Computer(){
Font font = new Font("宋体", Font.BOLD, 36);
Font font2 = new Font("宋体", Font.BOLD, 20);
a1 = new JButton("1");
a1.setFont(font);
a1.addActionListener(this);
a2 = new JButton("2");
a2.setFont(font);
a2.addActionListener(this);
a3 = new JButton("3");
a3.setFont(font);
a3.addActionListener(this);
a4 = new JButton("4");
a4.setFont(font);
a4.addActionListener(this);
a5 = new JButton("5");
a5.setFont(font);
a5.addActionListener(this);
a6 = new JButton("6");
a6.setFont(font);
a6.addActionListener(this);
a7 = new JButton("7");
a7.setFont(font);
a7.addActionListener(this);
a8 = new JButton("8");
a8.setFont(font);
a8.addActionListener(this);
a9 = new JButton("9");
a9.setFont(font);
a9.addActionListener(this);
a0 = new JButton("0");
a0.setFont(font);
a0.addActionListener(this);
b1 = new JButton("清空");
b1.addActionListener(this);
b2 = new JButton("返回");
b2.addActionListener(this);
b3 = new JButton(".");
b3.addActionListener(this);
b4 = new JButton("=");
b4.addActionListener(this);
c1 = new JButton("+");
c1.addActionListener(this);
c2 = new JButton("-");
c2.addActionListener(this);
c3 = new JButton("x");
c3.addActionListener(this);
c4 = new JButton("÷");
c4.addActionListener(this);
t1 = new JTextField(25);
t2 = new JTextField(35);
t1.setFont(font2);
t2.setFont(font2);
p1 = new JPanel();
p2 = new JPanel();
bq1 = new JLabel("结");
bq2 = new JLabel("果");
p1.setLayout(new GridLayout(2,3));
p2.setLayout(new GridLayout(4,4));
p1.add(t1);p1.add(b1);p1.add(b2);
p1.add(t2);p1.add(bq1);p1.add(bq2 );
p2.add(a1);p2.add(a2);p2.add(a3);p2.add(c1);
p2.add(a4);p2.add(a5);p2.add(a6);p2.add(c2);
p2.add(a7);p2.add(a8);p2.add(a9);p2.add(c3);
p2.add(b3);p2.add(a0);p2.add(b4);p2.add(c4);
this.add(p1,BorderLayout.NORTH);
this.add(p2,BorderLayout.CENTER);
this.setSize(460,380);
this.setTitle("简易计算器");
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object temp = e.getSource();
if(temp == a1){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"1");
chose=false;
}
if(temp == a2){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"2");
chose=false;
}
if(temp == a3){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"3");
chose=false;
}
if(temp == a4){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"4");
chose=false;
}
if(temp == a5){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"5");
chose=false;
}
if(temp == a6){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"6");
chose=false;
}
if(temp == a7){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"7");
chose=false;
}
if(temp == a8){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"8");
chose=false;
}
if(temp == a9){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"9");
chose=false;
}
if(temp == a0){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"0");
chose=false;
}
if(temp==b3){
cliks=true;
for(int i=0;i
if('.'==t1.getText().charAt(i)){
cliks=false;
break;
}
if(cliks==true){
t1.setText(t1.getText()+".");
}
}
}
if(temp== c1){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "+";
}
if(temp== c2){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "-";
}
if(temp== c3){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "*";
}
if(temp== c4){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "÷";
}
if(temp==b1){
t1.setText("");
t2.setText("");
}
if(temp==b2){
String s=t1.getText();
t1.setText("");
for(int i=0;i
char a = s.charAt(i);
t1.setText(t1.getText()+a);
}
}
if(temp== b4){
count2=Double.parseDouble(t1.getText());
t1.setText("");
if(fuhao=="+"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count+count2+"");
chose=true;
}
if(fuhao=="-"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count-count2+"");
chose=true;
}
if(fuhao=="*"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count*count2+"");
chose=true;
}
if(fuhao=="÷"){
//int sum=count+count2;
if(count2==0){
t1.setText(count+""+fuhao+""+count2+"");
t2.setText("除数不能为0");
return;
}
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count/count2+"");
chose=true;
}
}
}
}
追问
谢谢了
本回答由提问者推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起
java期末考试编程题 界面_救急啊!!!期末考试!怎样用JAVA的GUI(图形用户界面)来设计一个小程序!...相关推荐
- java二级为什么没题库_为什么刷了那么多二级java试题,却依然提高不了分数?...
在等剧更新的时间,赶紧进来刷刷题.复习以下的二级java试题,看剧.刷题,两不耽误,非常完美! 下列不可作为java语言标识符的是( D ) A a1 B $1 C _1 D 11 有一段java应用 ...
- Java使用表格显示日历编程_用java图形用户界面实现: 编写一个日历程序,能实现显示日历等简单功能。...
http://blog.sina.cn/dpool/blog/s/blog_5d51780d0100bf74.html?vt=4本回答被网友采纳www.mh456.com防采集. import jav ...
- java集合到线程的考试_成都汇智动力-Java SE考试编程题总结
原标题:成都汇智动力-Java SE考试编程题总结 线程和进程的区别: (1)进程是运行中的程序,拥有自己独立的内存空间和资源; (2)一个进程可以有一个或多个线程组成,且至少有一个线程称为主线程; ...
- Python课程期末考试编程题自动批卷原理与实现模板
适用场合: 1)Python程序设计课程上机或实验作业自动批阅. 2)Python程序设计课程期末考试编程题的自动评分. 设计思路: 1)编写考试试卷程序文件,定义好每个试题的函数接口和预期功能,详细 ...
- 环评师c语言题目,C语言考试——编程题_文库吧
C语言考试--编程题_文库吧 2020-09-27 08:21:23 [导读]该数本身,比如153=13+53+33,故153是水仙花数).要求将判断某数是否素数的功.能编成一个独立的函数,然后在ma ...
- python考试编程题九道_一道逻辑推理题的程序实现(纯属娱乐)
一份逻辑推理题的程序求解(纯属自娱自乐) 闲来无聊,看到QQ空间上转载了一份变态推理题的,至少表示我看了十多分钟无处下手,认识的人中有大神居然真的做出来了...我不知道他是们那么做的,不过作为编程爱好 ...
- vivo2020届春季校园招聘在线编程考试--[编程题]vivo智能手机产能
vivo2020届春季校园招聘在线编程考试--[编程题]vivo智能手机产能 题目 解题思路 代码块 题目 在vivo产线上,每位职工随着对手机加工流程认识的熟悉和经验的增加,日产量也会不断攀升. 假 ...
- vivo2020届春季校园招聘在线编程考试--[编程题]数位之积
vivo2020届春季校园招聘在线编程考试--[编程题]数位之积 题目 解题思路 代码块 题目 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M 现给定任意正 ...
- 二级c语言编程题只要得出答案,计算机二级C语言考试编程题题库答案.docx
计算机二级C语言考试编程题题库答案 1.求100之内自然数中最大的能被17整除的数.void main(){ int i;for(i=100;i>0;i--)if(i%17==0)break;p ...
最新文章
- Boost.MultiIndex 使用随机访问索引的示例
- fork join框架_Java 7:Fork / Join框架示例
- 判断整数序列是不是二元查找树的后序遍历结果
- commvault备份mysql,备份MySQL数据库的4种方式
- Java多线程编程(3)--线程安全性
- 25 种代码坏味道总结+优化示例
- 查找某个数据,找到后把符合条件数据的一行复制到另外一个地方
- Spring基于注解管理bean(一文搞懂注解及使用注解)
- N沟道与P沟道增强型MOS管电压、原理、导通条件!
- 时钟同步与时间同步的区别
- 福禄克网络VERSIV(威测)电缆认证系统实现ROI更大化
- [精选转载]15天!我申论从60分到81.5分的复习经验
- CGfsb [XCTF-PWN]CTF writeup系列2
- linux识别硬盘时显示gpt,Ubuntu不识别GPT硬盘已有系统的解决方案
- code force 449 div2 C. Nephren gives a riddle
- c#和java部署pytorch同事识别两个图片_身份证OCR识别移动端amp;服务器
- java编写某计算器控制台程序_计算器 - 进阶的憨狗 - 博客园
- SAN存储和服务器虚拟化安装方案,基于SAN存储架构的x86服务器虚拟化测试方案.pdf...
- 中国电信LifePad欲争抢中国平板电脑市场
- 基于Android的短信应用开发(一)——界面设计开发