資源簡(jiǎn)介
使用了Swing組件各種布局對(duì)計(jì)算機(jī)界面進(jìn)行設(shè)計(jì)
、GridLayout,JPanel....,其中還包含菜單的設(shè)計(jì)等。
代碼片段和文件信息
package?分?jǐn)?shù)計(jì)算器設(shè)計(jì)1;
/*
使用布局管理器時(shí),使用setPreferredSize方法:
jbutton.setPreferredSize(new?Dimension(wh));
使用絕對(duì)布局時(shí):
jbutton.setBounds(xywh);
public?GridLayout(int?rows
??????????????????int?cols
??????????????????int?hgap
??????????????????int?vgap)創(chuàng)建具有指定行數(shù)和列數(shù)的網(wǎng)格布局。?布局中的所有組件都具有相同的大小。?
此外,水平和垂直間隙被設(shè)置為指定的值。?每個(gè)列之間放置水平間隙。?在每行之間放置垂直間隙。?
rows和cols中的一個(gè)但不是兩者可以為零,這意味著可以將任意數(shù)量的對(duì)象放置在一行或一列中。?
所有GridLayout遵循這一個(gè)。?
參數(shù)?
rows?-?行,值為零表示任意數(shù)量的行?
cols?-?值為零,表示任意數(shù)量的列?
hgap?-?水平間隙?
vgap?-?垂直間隙?
*/
import?java.awt.*;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.IOException;
import?javax.swing.*;
//import?javax.swing.border.Border;
//import?javax.xml.stream.events.Comment;
public?class?WindowFractions1?extends?Jframe?implements?ActionListener{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?4584598253426846160L;
JMenuBar?menubar;//菜單條
JMenu?menu1menu2;//菜單、幫助
JMenuItem?item1item2;//化簡(jiǎn)、操作說(shuō)明
private?final?String?N[]=?{“7““8““9““4““5““6““1“
“2““3““0““/““-“};
private?final?String?COMMAND[]=?{“<-““C““=““next“};
private?final?String?s[]=?{“+““-““*““/“};
JTextField?text1text2text3text;
JLabel?labelwarn1warn2;
JPanel?p1p2p12p3;
JPanel?pNpMpC;
JComboBox?combox;
JButton?button1button2;
JButton?n[]=new?JButton[N.length];
JButton?command[]=new?JButton[COMMAND.length];
ComputerListener1?computer;
OperatorListener1?operator;
public?WindowFractions1()?{
init();
setBounds(300300420350);
setVisible(true);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
//this.pack();
setResizable(false);
}
/*jlabel.setFont(new???java.awt.Font(“Dialog“???1???15));???
“dialog”代表字體,1代表樣式(1是粗體,0是平常的)15是字號(hào)
//設(shè)置字體
jlabel.setForeground(Color.red);
//設(shè)置顏色
*/
void?init()?{
menubar=new?JMenuBar();
menu1=new?JMenu(“編輯“);
menu2=new?JMenu(“幫助“);
item1=new?JMenuItem(“化簡(jiǎn)“);
item2=new?JMenuItem(“操作說(shuō)明“);
menu1.add(item1);
menu2.add(item2);
menubar.add(menu1);
menubar.add(menu2);
setJMenuBar(menubar);
item1.addActionListener(this);
item2.addActionListener(this);
//setLayout(new?FlowLayout());
//對(duì)組件初始化
text1=new?JTextField(“輸入分?jǐn)?shù)“);
text2=new?JTextField(“輸入分?jǐn)?shù)“);
text3=new?JTextField();
text3.setEditable(false);?//?只能顯示,不能編輯
//?文本框中的內(nèi)容采用右對(duì)齊方式
????????text1.setHorizontalAlignment(JTextFie
評(píng)論
共有 條評(píng)論