jbuilder 100例 java源码学习,非常不错,有需要朋友下来
源代码在线查看: valia.java~15~
package untitled1; import java.awt.*; import java.awt.event.*; import java.applet.*; import com.borland.jbcl.layout.*; public class valia extends Applet { boolean flag = false,flag1 = false,flag2 = false; double num; boolean isStandalone = false; TextField text1 = new TextField(); XYLayout xYLayout1 = new XYLayout(); Label label1 = new Label(); Checkbox checkbox1 = new Checkbox(); Checkbox checkbox2 = new Checkbox(); Label label2 = new Label(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public valia() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { text1.setFont(new java.awt.Font("Dialog", 0, 16)); text1.setText("0"); text1.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(FocusEvent e) { text1_focusLost(e); } }); this.setLayout(xYLayout1); label1.setFont(new java.awt.Font("Dialog", 0, 16)); label1.setText("输入数据"); checkbox1.setLabel("双精度"); checkbox1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { checkbox1_itemStateChanged(e); } }); checkbox2.setLabel("整形"); checkbox2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { checkbox2_itemStateChanged(e); } }); label2.setFont(new java.awt.Font("Dialog", 0, 16)); label2.setText("转换成"); this.add(text1, new XYConstraints(156, 70, 80, -1)); this.add(label1, new XYConstraints(50, 70, 80, -1)); this.add(checkbox1, new XYConstraints(155, 114, 72, 27)); this.add(checkbox2, new XYConstraints(155, 152, 69, 25)); this.add(label2, new XYConstraints(50, 110, 83, 27)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void checkbox1_itemStateChanged(ItemEvent e) { if (flag){ if (checkbox1.getState()){ flag1 = true; } else flag1 = false; repaint(); } } void text1_focusLost(FocusEvent e) { String str = text1.getText() ; if (str!=null){ try{ num = Double.parseDouble(str); flag = true; } catch(Exception ex){} } repaint(); } void checkbox2_itemStateChanged(ItemEvent e) { if (flag){ if (checkbox2.getState()){ flag2 = true; } else flag2 = false; repaint(); } } public void paint(Graphics g){ if (flag1 == true){ g.drawString(String.valueOf(num),100,200); } if (flag2 == true){ g.drawString(String.valueOf((int)(num)),100,250); } } }