当前位置: 代码迷 >> Java相关 >> JAVA 计算器 实现了界面后应该怎么办
  详细解决方案

JAVA 计算器 实现了界面后应该怎么办

热度:483   发布时间:2008-11-10 17:04:53.0
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  计算器  界面  

----------------解决方案--------------------------------------------------------
添加响应机制..一个一个功能慢慢添加
----------------解决方案--------------------------------------------------------
[bo][un]lyong689[/un] 在 2008-11-10 17:04 的发言:[/bo]

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

添加事件处理机制
----------------解决方案--------------------------------------------------------
计算器确实不是那么好写的,应该要用到逆波兰式

大部分简单计算器算3+2*5都是等于25……
----------------解决方案--------------------------------------------------------
  相关解决方案