该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我自己做出了外部外形模块,找了很多资料,大致的思路是:
1,先创建外部界面,外圈用BorderLayout,内部用GridLayout,做出计算器面板。
2,为每个button注册监听器并且实现点击按钮上面的JTextArea板块会输出相应的按钮内容。
3,把每种情况都用if,else提前编写好,使用时可以满足所有计算。
但现在卡在了第二监听器注册完之后没办法实现点击之后JTextArea会输出对应文字,还有第三部没有任何思路,不知从何处下手。。。
下面是我的代码,求各位大神帮忙修改完成。。。我的第一个java项目,实在是没办法了。。
packageaa;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
@SuppressWarnings("serial")
publicclassCalculatorextendsJFrame{
publicCalculator(){
//TODO自动生成的方法存根
JFramecal=newJFrame("亲戚计算器");
cal.setLayout(newBorderLayout());
cal.setSize(500,600);
cal.setLocationRelativeTo(null);
JTextAreatf=newJTextArea(6,24);
tf.setBorder(BorderFactory.createLineBorder(Color.red,2));
tf.setEditable(false);
JPaneljp=newJPanel();
jp.setLayout(newGridLayout(4,4));
ButtonListenerbtnListener=newButtonListener();
Buttonbt1=newButton("父");
bt1.setBounds(5,120,55,55);
bt1.setBackground(newColor(95,95,95));
bt1.setForeground(Color.white);
bt1.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt1);
bt1.addActionListener(btnListener);
Buttonbt2=newButton("母");
bt2.setBounds(5,120,55,55);
bt2.setBackground(newColor(95,95,95));
bt2.setForeground(Color.white);
bt2.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt2);
bt2.addActionListener(btnListener);
Buttonbt3=newButton("CE");
bt3.setBounds(5,120,55,55);
bt3.setBackground(newColor(95,95,95));
bt3.setForeground(Color.white);
bt3.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt3);
bt3.addActionListener(btnListener);
Buttonbt4=newButton("AC");
bt4.setBounds(5,120,55,55);
bt4.setBackground(newColor(95,95,95));
bt4.setForeground(Color.white);
bt4.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt4);
bt4.addActionListener(btnListener);
Buttonbt5=newButton("兄");
bt5.setBounds(5,120,55,55);
bt5.setBackground(newColor(95,95,95));
bt5.setForeground(Color.white);
bt5.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt5);
bt5.addActionListener(btnListener);
Buttonbt6=newButton("弟");
bt6.setBounds(5,120,55,55);
bt6.setBackground(newColor(95,95,95));
bt6.setForeground(Color.white);
bt6.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt6);
bt6.addActionListener(btnListener);
Buttonbt7=newButton("姐");
bt7.setBounds(5,120,55,55);
bt7.setBackground(newColor(95,95,95));
bt7.setForeground(Color.white);
bt7.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt7);
bt7.addActionListener(btnListener);
Buttonbt8=newButton("妹");
bt8.setBounds(5,120,55,55);
bt8.setBackground(newColor(95,95,95));
bt8.setForeground(Color.white);
bt8.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt8);
bt8.addActionListener(btnListener);
Buttonbt9=newButton("夫");
bt9.setBounds(5,120,55,55);
bt9.setBackground(newColor(95,95,95));
bt9.setForeground(Color.white);
bt9.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt9);
bt9.addActionListener(btnListener);
Buttonbt10=newButton("妻");
bt10.setBounds(5,120,55,55);
bt10.setBackground(newColor(95,95,95));
bt10.setForeground(Color.white);
bt10.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt10);
bt10.addActionListener(btnListener);
Buttonbt11=newButton("子");
bt11.setBounds(5,120,55,55);
bt11.setBackground(newColor(95,95,95));
bt11.setForeground(Color.white);
bt11.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt11);
bt11.addActionListener(btnListener);
Buttonbt12=newButton("女");
bt12.setBounds(5,120,55,55);
bt12.setBackground(newColor(95,95,95));
bt12.setForeground(Color.white);
bt12.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt12);
bt12.addActionListener(btnListener);
Buttonbt13=newButton("+");
bt13.setBounds(5,120,55,55);
bt13.setBackground(newColor(95,95,95));
bt13.setForeground(Color.white);
bt13.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt13);
bt13.addActionListener(btnListener);
Buttonbt14=newButton("=");
bt14.setBounds(5,120,55,55);
bt14.setBackground(newColor(95,95,95));
bt14.setForeground(Color.white);
bt14.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt14);
bt14.addActionListener(btnListener);
Buttonbt15=newButton("");
bt15.setBounds(5,120,55,55);
bt15.setBackground(newColor(95,95,95));
bt15.setForeground(Color.white);
bt15.setFont(newFont("宋体",Font.BOLD,20));
jp.add(bt15);
bt15.addActionListener(btnListener);
Buttonbt16=newButton("");
bt16.setBounds(5,120,55,55);
bt16.setBackground(newColor(95,95,95))