java编写的仿win7简单计算器小程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
源程序代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class CalculationTest{
public static void main(String [] argv)
{
EventQueue.invokeLater(new Runnable(){
public void run()
{
JFrame frame=new CalculationFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class CalculationFrame extends JFrame{
public CalculationFrame()
{
setTitle("计算机 made by 蓝月追风");
CalculationPanel panel=new CalculationPanel();
add(panel);
this.setSize(300, 350);
}
}
class CalculationPanel extends JPanel
{
public CalculationPanel()
{
this.setLayout(new GridLayout(2,1));
JPanel buttonPanel=new ButtonPanel();
JPanel showPanel=new ShowPanel();
add(showPanel);
add(buttonPanel);
}
private class ShowPanel extends JPanel
{
ShowPanel()
{
panel=new JPanel();
down=new JTextArea(1,10);
up=new JTextArea(1,10);
panel.setLayout(new GridLayout(2,1));
panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
down.setEditable(false);
down.setFont(new Font("Serifs",Font.BOLD,25));
up.setEditable(false);
// lastShow.setBackground(Color.red);
// showArea.setBackground(Color.BLUE);
down.setEditable(false);
down.setText("0");
panel.setPreferredSize(new Dimension(210,75));
panel.add(up);
panel.add(down);
add(panel);
setBorder(BorderFactory.createEmptyBorder(5, 3, 1, 3));
}
private JPanel panel;
}
private class ButtonPanel extends JPanel
{
public ButtonPanel()
{
start=true;
equals=false;
total=true;
result=0;
button=new JButton[17];
ActionListener NA=new numberAction();
ActionListener CA=new commendAction();
GridBagLayout gridbag=new GridBagLayout();
setLayout(gridbag);
GridBagConstraints gbc;
int
gridx,gridy,gridwidth,gridheight,anchor,fill,ipadx,ipady;
double weightx,weighty;
Insets inset=new Insets(3,3,3,3);
gridx=0;gridy=0;gridwidth=1;gridheight=1;anchor=GridBagConstraint s.CENTER;
fill=GridBagConstraints.BOTH;
ipadx=0;ipady=0;
weightx=0;weighty=0;
button[0]=new JButton("0");
gridy=3;gridx=0;
gridwidth=2;
gbc=new
GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,a nchor,fill,inset,ipadx,ipady);
gridbag.setConstraints(button[0], gbc);
add(button[0]);