available()函数获取的是当前文件指针到文件末尾还有多少字节。
比如刚打开文件就调用 bisavailable() 时,输出的是 1314 的话
bisread()读取了一个字节,所以在调用bisavailable()时就会输出 1313
具体代码如下:
import javaxswing;
import javaawtevent;
import javaawt;
public class Calculator extends JFrame implements ActionListener {
private JFrame jf;
private JButton[] allButtons;
private JButton clearButton;
private JTextField jtf;
public Calculator() {
//对图形组件实例化
jf=new JFrame("任静的计算器10:JAVA版");
jfaddWindowListener(new WindowAdapter(){
public void windowClosing(){
Systemexit(0);
}
});
allButtons=new JButton[16];
clearButton=new JButton("清除");
jtf=new JTextField(25);
jtfsetEditable(false);
String str="123+456-7890=/";
for(int i=0;i<allButtonslength;i++){
allButtons[i]=new JButton(strsubstring(i,i+1));
}
}
public void init(){
//完成布局
jfsetLayout(new BorderLayout());
JPanel northPanel=new JPanel();
JPanel centerPanel=new JPanel();
JPanel southPanel=new JPanel();
northPanelsetLayout(new FlowLayout());
centerPanelsetLayout(new GridLayout(4,4));
southPanelsetLayout(new FlowLayout());
northPaneladd(jtf);
for(int i=0;i<16;i++){
centerPaneladd(allButtons[i]);
}
southPaneladd(clearButton);
jfadd(northPanel,BorderLayoutNORTH);
jfadd(centerPanel,BorderLayoutCENTER);
jfadd(southPanel,BorderLayoutSOUTH);
addEventHandler();
}
//添加事件监听
public void addEventHandler(){
jtfaddActionListener(this);
for(int i=0;i<allButtonslength;i++){
allButtons[i]addActionListener(this);
}
clearButtonaddActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
CalculatorthisjtfsetText("");
}
});
}
//事件处理
public void actionPerformed(ActionEvent e) {
//在这里完成事件处理 使计算器可以运行
String action=egetActionCommand();
if(action=="+"||action=="-"||action==""||action=="/"){
}
}
public void setFontAndColor(){
Font f=new Font("宋体",FontBOLD,24);
jtfsetFont(f);
jtfsetBackground(new Color(0x8f,0xa0,0xfb));
for(int i=0;i<16;i++){
allButtons[i]setFont(f);
allButtons[i]setForeground(ColorRED);
}
}
public void showMe(){
init();
setFontAndColor();
jfpack();
jfsetVisible(true);
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public static void main(String[] args){
new Calculator()showMe();
}
}
以上就是关于java 小程序解释全部的内容,包括:java 小程序解释、如何用JAVA语言编写计算器小程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)