| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 943 人关注过本帖, 1 人收藏
标题:JAVA 计算器 实现了界面后应该怎么办
只看楼主 加入收藏
lyong689
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-11-10
收藏(1)
 问题点数:0 回复次数:3 
JAVA 计算器 实现了界面后应该怎么办
我实现了JAVA的界面设计,麻烦高手帮完成下代码。我也知道要添加响应机制,一个一个功能慢慢添加,但是实在是不知道应该怎样实现有关功能。怎样先谢谢了。我的界面代码如下:
import javax.swing.*;
import java.awt.*;
public class Buttons extends JFrame{
    JButton a1=new JButton("1");
    JButton a2=new JButton("2");
    JButton a3=new JButton("3");
    JButton b0=new JButton("+");
    JButton b1=new JButton("%");
    JButton b2=new JButton("sin");
    JButton a4=new JButton("4");
    JButton a5=new JButton("5");
    JButton a6=new JButton("6");
    JButton b3=new JButton("-");
    JButton b4=new JButton("开平方");
    JButton b5=new JButton("cos");
    JButton a7=new JButton("7");
    JButton a8=new JButton("8");
    JButton a9=new JButton("9");
    JButton b6=new JButton("*");
    JButton b7=new JButton("开立方");
    JButton b8=new JButton("tan");
    JButton a0=new JButton("0");
    JButton a=new JButton("-");
    JButton a10=new JButton(".");
    JButton b=new JButton("/");
    JButton b9=new JButton("log");
    JButton b10=new JButton("ctg");
    JButton c1=new JButton("清零");
    JButton c2=new JButton("退格");
    JButton c0=new JButton(" = ");
    JTextField d=new JTextField(23);
    JLabel d1=new JLabel("=");
    JTextField d2=new JTextField(18);
        public Buttons(){
        super("计算器--小罗制作");
        setBounds(500,350,412,215);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel pane2=new JPanel();
        pane2.add(d);
        pane2.add(d1);
        pane2.add(d2);
        JPanel pane1=new JPanel();
        GridLayout sf2=new GridLayout(3,1,0,4);
        pane1.setLayout(sf2);
        pane1.add(c0);
        pane1.add(c1);
        pane1.add(c2);
        JPanel pane=new JPanel();
        GridLayout sf1=new GridLayout(4,4);
        pane.setLayout(sf1);
        a1.setForeground(Color.red);
        a2.setForeground(Color.red);
        a3.setForeground(Color.red);
        a4.setForeground(Color.red);
        a5.setForeground(Color.red);
        a6.setForeground(Color.red);
        a7.setForeground(Color.red);
        a8.setForeground(Color.red);
        a9.setForeground(Color.red);
        a0.setForeground(Color.red);
        c0.setForeground(Color.red);
        c1.setForeground(Color.red);
        Font font=new Font("宋体",Font.PLAIN,24);
        b0.setFont(font);
        c0.setFont(font);
        b3.setFont(font);
        a10.setFont(font);
        Font font1=new Font("宋体",Font.PLAIN,18);
        b1.setFont(font1);
        b.setFont(font1);
        d.setFont(font1);
        d2.setFont(font1);
        a.setFont(font1);
        b6.setFont(font1);
        pane.add(a1);
        pane.add(a2);
        pane.add(a3);
        pane.add(b0);
        pane.add(a4);
        pane.add(a5);
        pane.add(a6);
        pane.add(b3);
        pane.add(a7);
        pane.add(a8);
        pane.add(a9);
        pane.add(b6);
        pane.add(a0);
        pane.add(a);
        pane.add(a10);
        pane.add(b);
        JPanel pane3=new JPanel();
        GridLayout sf4=new GridLayout(4,2);
        pane3.setLayout(sf4);
        pane3.add(b1);
        pane3.add(b2);
        pane3.add(b4);
        pane3.add(b5);
        pane3.add(b7);
        pane3.add(b8);
        pane3.add(b9);
        pane3.add(b10);
        JPanel pane0=new JPanel();
        BorderLayout sf3=new BorderLayout(3,0);
        pane0.setLayout(sf3);
        pane0.add("Center",pane3);
        pane0.add("East",pane1);
        pane0.add("North",pane2);
        pane0.add("West",pane);
        setContentPane(pane0);
    }
    public static void main(String args[]){
         Buttons f=new Buttons();
         f.setResizable(false);
         f.show();
    }
}

[[it] 本帖最后由 lyong689 于 2008-11-10 22:41 编辑 [/it]]
搜索更多相关主题的帖子: JAVA 计算器 界面 
2008-11-10 17:04
zacom
Rank: 2
等 级:论坛游民
威 望:2
帖 子:381
专家分:15
注 册:2007-9-15
收藏
得分:0 
添加响应机制..一个一个功能慢慢添加

没有最好只有更好
2008-11-10 20:57
zhong0711101
Rank: 2
等 级:论坛游民
帖 子:156
专家分:25
注 册:2008-7-15
收藏
得分:0 
[bo][un]lyong689[/un] 在 2008-11-10 17:04 的发言:[/bo]

我实现了JAVA的界面设计,麻烦高手帮完成下代码。我也知道要添加响应机制,一个一个功能慢慢添加,但是实在是不知道应该怎样实现有关功能。怎样先谢谢了。我的界面代码如下:
import javax.swing.*;
import java.a ...

添加事件处理机制
2008-11-15 03:58
freish
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1223
专家分:437
注 册:2007-6-1
收藏
得分:0 
计算器确实不是那么好写的,应该要用到逆波兰式

大部分简单计算器算3+2*5都是等于25……
2008-11-15 09:33
快速回复:JAVA 计算器 实现了界面后应该怎么办
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011664 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved