几何图形器运用了java的基础知识和swing工具集完成,用了两天零碎的时间完成,使用工具:IDEA
主界面使用了菜单和下拉框,下拉框可以选择要进行的几何图形计算,并且添加了一个按钮,在上面放上图片,让界面不那么单调
通过编写该程序让我对多态有了更深的了解,BoxPanel类有两个组件,一个标签和一个文本框,水平对齐,其他类可以通过实现该类,获得整齐的组件排列
public class BoxPanel extends JPanel {
JTextField text;
public BoxPanel(String s,int n){
Box box=Box.createHorizontalBox();
box.add(new JLabel(s));
text=new JTextField(" ",n);
text.setHorizontalAlignment(JTextField.RIGHT);
text.setFont(new Font("Arial",Font.BOLD,15));
box.add(text);
add(box);
}
public JTextField getJText(){
return text;
}
}
Box box=Box.createVerticalBox();
bpwidth=new BoxPanel("请输入矩形的高: ",10);
widthText=bpwidth.getJText();
widthText.addFocusListener(this);
bpheight=new BoxPanel("请输入矩形的高",10);
heightText=bpheight.getJText();
heightText.addFocusListener(this);
buttonpanel=new JPanel();
resultButton=new JButton("计算结果 ");
resultButton.addActionListener(this);
clearButton=new JButton("清空");
clearButton.addActionListener(this);
buttonpanel.add(resultButton);
buttonpanel.add(clearButton);
本程序没有遇到什么困难的问题,顺利的写完,代码在我的github