java界面设计器_java 图形界面设计制作计算器

在NETBEANS里写的我的代码如下:JSQ:packagewe;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassJSQextendsJFrameimplementsActionListener{floati=0;JPane...

在NETBEANS 里写的

我的代码如下:JSQ:

package we;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class JSQ extends JFrame implements ActionListener{

float i=0;

JPanel jp1=new JPanel();

JPanel jp2=new JPanel();

JPanel jp3=new JPanel();

JButton bt1=new JButton("+");

JButton bt2=new JButton("-");

JButton bt3=new JButton("*");

JButton bt4=new JButton("/");

JButton bt5=new JButton("1");

JButton bt6=new JButton("2");

JButton bt7=new JButton("3");

JButton bt8=new JButton("4");

JButton bt9=new JButton("5");

JButton bt10=new JButton("6");

JButton bt11=new JButton("7");

JButton bt12=new JButton("8");

JButton bt13=new JButton("9");

JButton bt14=new JButton("0");

JButton bt15=new JButton("=");

JLabel je=new JLabel("0");

public JSQ() {

super("计算器");

jp1.setBounds(50,150,300,200);

jp1.setBackground(new Color(100,100,150));

this.add(jp1);

jp2.setBounds(50,40,300,30);

jp2.setBackground(new Color(50,100,150));

this.add(jp2);

jp2.add(je);

jp3.setBounds(370,200,70,70);

jp3.setBackground(new Color(100,100,150));

this.add(jp3);

jp1.add(bt1);

jp1.add(bt2);

jp1.add(bt3);

jp1.add(bt4);

jp1.add(bt5);

jp1.add(bt6);

jp1.add(bt7);

jp1.add(bt8);

jp1.add(bt9);

jp1.add(bt10);

jp1.add(bt11);

jp1.add(bt12);

jp1.add(bt13);

jp1.add(bt14);

jp1.add(bt15);

bt1.addActionListener(this);

bt2.addActionListener(this);

bt3.addActionListener(this);

bt4.addActionListener(this);

bt5.addActionListener(this);

bt6.addActionListener(this);

bt7.addActionListener(this);

bt8.addActionListener(this);

bt9.addActionListener(this);

bt10.addActionListener(this);

bt11.addActionListener(this);

bt12.addActionListener(this);

bt13.addActionListener(this);

bt14.addActionListener(this);

bt15.addActionListener(this);

this.setLayout(null);

this.setSize(500,400);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

this.setVisible(true);/**

}

public void actionPerformed(ActionEvent e) {

}

}

Test和JSQ是分开的

Test:

package we;

public class Test {

public static void main(String[] args) {

JSQ jf=new JSQ();

}

}

我写到public void actionPerformed(ActionEvent e) {

}

} 以后就不会写了,不知道怎么实现按键的连续输入,之前写过一些,失败了,所以空着不会。

我想实现的是:先按“1”再按“2”键,标签显示12,不知道怎么实现。然后我按运算符加减乘除,标签上的数字不变,我再按一个数,然后标签上的12被删除,并且打印上我后面按的那个数,然后我再按等号,就会输出运算结果在标签3上,就像一般的计算器一样,要用到变量,不知道要不要用到append,大家帮帮我吧,期末成绩,我的分不多,谢谢了!!!

展开


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部