資源簡介
剛學一個半月的java,自己動手寫的一段代碼,部分參照網上的,將其編譯成.jar格式,再用jar2exe轉換成.exe格式,能夠在安裝有java的電腦上運行,不足之處還請多多指教!!
代碼片段和文件信息
import?java.awt.*;?
import?java.awt.event.*;?
import?javax.swing.*;?
public?class?Counter?extends?frame?{?
//?聲明三個面板的布局?
GridLayout?gl1?gl2?gl3;?
Panel?p0?p1?p2?p3;?
JTextField?tf1;?
TextField?tf2;?
Button?b0?b1?b2?b3?b4?b5?b6?b7?b8?b9?b10?b11?b12?b13?b14?
b15?b16?b17?b18?b19?b20?b21?b22?b23?b24?b25?b26;?
StringBuffer?str;//?顯示屏所顯示的字符串?
double?x?y;//?x和y都是運算數?
int?z;//?Z表示單擊了那一個運算符.0表示“+“1表示“-“2表示“*“3表示“/“?
static?double?m;//?記憶的數字?
public?Counter()?{?
gl1?=?new?GridLayout(1?4?10?0);//?實例化三個面板的布局?
gl2?=?new?GridLayout(4?1?0?15);?
gl3?=?new?GridLayout(4?5?10?15);?
tf1?=?new?JTextField(27);//?顯示屏?
tf1.setHorizontalAlignment(JTextField.RIGHT);?
tf1.setEnabled(false);
tf1.setBackground(Color.BLUE);
tf1.setText(“0“);?
tf2?=?new?TextField(10);//?顯示記憶的索引值?
tf2.setEditable(false);?
//?實例化所有按鈕、設置其前景色并注冊監聽器?
b0?=?new?Button(“Backspace“);?
b0.setForeground(Color.red);?
b0.addActionListener(new?Bt());?
b1?=?new?Button(“CE“);?
b1.setForeground(Color.red);?
b1.addActionListener(new?Bt());?
b2?=?new?Button(“C“);?
b2.setForeground(Color.red);?
b2.addActionListener(new?Bt());?
b3?=?new?Button(“MC“);?
b3.setForeground(Color.red);?
b3.addActionListener(new?Bt());?
b4?=?new?Button(“MR“);?
b4.setForeground(Color.red);?
b4.addActionListener(new?Bt());?
b5?=?new?Button(“MS“);?
b5.setForeground(Color.red);?
b5.addActionListener(new?Bt());?
b6?=?new?Button(“M+“);?
b6.setForeground(Color.red);?
b6.addActionListener(new?Bt());?
b7?=?new?Button(“7“);?
b7.setForeground(Color.blue);?
b7.addActionListener(new?Bt());?
b8?=?new?Button(“8“);?
b8.setForeground(Color.blue);?
b8.addActionListener(new?Bt());?
b9?=?new?Button(“9“);?
b9.setForeground(Color.blue);?
b9.addActionListener(new?Bt());?
b10?=?new?Button(“/“);?
b10.setForeground(Color.red);?
b10.addActionListener(new?Bt());?
b11?=?new?Button(“sqrt“);?
b11.setForeground(Color.blue);?
b11.addActionListener(new?Bt());?
b12?=?new?Button(“4“);?
b12.setForeground(Color.blue);?
b12.addActionListener(new?Bt());?
b13?=?new?Button(“5“);?
b13.setForeground(Color.blue);?
b13.addActionListener(new?Bt());?
b14?=?new?Button(“6“);?
b14.setForeground(Color.blue);?
b14.addActionListener(new?Bt());?
b15?=?new?Button(“*“);?
b15.setForeground(Color.red);?
b15.addActionListener(new?Bt());?
b16?=?new?Button(“%“);?
b16.setForeground(Color.blue);?
b16.addActionListener(new?Bt());?
b17?=?new?Button(“1“);?
b17.setForeground(Color.blue);?
b17.addActionListener(new?Bt());?
b18?=?new?Button(“2“);?
b18.setForeground(Color.blue);?
b18.addActionListener(new?Bt());?
b19?=?new?Button(“3“);?
b19.setForeground(Color.blue);?
b19.addActionListener(new?Bt());?
b20?=?new?Button(“-“);?
b20.setForeground(Color.red);?
b20.addActionListener(new?Bt());?
b21?=?new?Button(“1/X“);?
b21.setForeground(Color.blue);?
b21.addActionListener(new?Bt());?
b22?=?new?Button(“0“);?
b22.setForeground(Color.blue);?
b22.addAc
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???18071339??2011-10-20?21:02??Calculate.exe
?????文件???????5559??2011-10-20?18:55??Calculate.jar
?????文件????????479??2011-10-20?18:48??Counter$1.class
?????文件???????4217??2011-10-20?18:48??Counter$Bt.class
?????文件???????4789??2011-10-20?18:48??Counter.class
?????文件???????9045??2011-10-21?11:33??Calculate.java
-----------?---------??----------?-----??----
?????????????18095428????????????????????6
評論
共有 條評論