package untitled2; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import com.borland.jbcl.layout.*; public class qchange extends Applet { double c[] = {1,2,3}; double d[] = {3,2,1}; double mid; double start; double end; int n = 0; int m = 0; boolean isStandalone = false; JRadioButton jRadioButton1 = new JRadioButton(); JRadioButton jRadioButton2 = new JRadioButton(); JRadioButton jRadioButton3 = new JRadioButton(); JRadioButton jRadioButton4 = new JRadioButton(); JRadioButton jRadioButton5 = new JRadioButton(); JRadioButton jRadioButton6 = new JRadioButton(); ButtonGroup buttonGroup1 = new ButtonGroup(); ButtonGroup buttonGroup2 = new ButtonGroup(); JTextField text1 = new JTextField(); JTextField text2 = new JTextField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); XYLayout xYLayout1 = new XYLayout(); /**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 qchange() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton1.setText("英吨"); jRadioButton1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { jRadioButton1_itemStateChanged(e); } }); this.setLayout(xYLayout1); jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton2.setText("磅"); jRadioButton2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { jRadioButton1_itemStateChanged(e); } }); jRadioButton2.addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsAdapter() { }); jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton3.setText("盎司"); jRadioButton3.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { jRadioButton1_itemStateChanged(e); } }); jRadioButton4.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton4.setText("吨"); jRadioButton4.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { jRadioButton2_itemStateChanged(e); } }); jRadioButton5.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton5.setText("千克"); jRadioButton5.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { jRadioButton2_itemStateChanged(e); } }); jRadioButton6.setFont(new java.awt.Font("Dialog", 0, 16)); jRadioButton6.setText("克"); jRadioButton6.addItemListener(new java.awt.event.ItemListener() { }); jButton1.setText("-->"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.setText(" jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); text1.setText("0"); text2.setText("0"); this.add(jRadioButton1, new XYConstraints(40, 24, -1, -1)); this.add(jRadioButton2, new XYConstraints(40, 56, -1, -1)); this.add(jRadioButton3, new XYConstraints(40, 88, -1, -1)); this.add(text1, new XYConstraints(40, 126, 72, 24)); this.add(jRadioButton5, new XYConstraints(214, 56, -1, -1)); this.add(jRadioButton4, new XYConstraints(214, 24, -1, -1)); this.add(jRadioButton6, new XYConstraints(214, 88, -1, -1)); this.add(text2, new XYConstraints(192, 126, 70, 25)); buttonGroup1.add(jRadioButton1); buttonGroup1.add(jRadioButton2); buttonGroup1.add(jRadioButton3); buttonGroup2.add(jRadioButton4); buttonGroup2.add(jRadioButton5); buttonGroup2.add(jRadioButton6); this.add(jButton2, new XYConstraints(123, 142, 58, 21)); this.add(jButton1, new XYConstraints(123, 115, 58, 21)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void jRadioButton1_itemStateChanged(ItemEvent e) { if (jRadioButton1.isSelected()) n = 1; if (jRadioButton2.isSelected()) n = 2; if (jRadioButton3.isSelected()) n = 3; } void jRadioButton2_itemStateChanged(ItemEvent e) { if (jRadioButton4.isSelected()) m = 1; if (jRadioButton5.isSelected()) m = 2; if (jRadioButton6.isSelected()) m = 3; } void jButton1_actionPerformed(ActionEvent e) { String str = text1.getText(); if (str!=null){ try{ start = Double.parseDouble(str); switch (n){ case 1: mid = start * c[0]; break; case 2: mid = start * c[1]; break; case 3: mid = start * c[2]; break; } switch (m){ case 1: end = mid / d[0]; break; case 2: end = mid / d[1]; break; case 3: end = mid / d[2]; break; } text2.setText(String.valueOf(end)); } catch(Exception ex){} } } void jButton2_actionPerformed(ActionEvent e) { String str = text2.getText(); if (str!=null){ try{ start = Double.parseDouble(str); switch (m){ case 1: mid = start * d[0]; break; case 2: mid = start * d[1]; break; case 3: mid = start * d[2]; break; } switch (n){ case 1: end = mid / c[0]; break; case 2: end = mid / c[1]; break; case 3: end = mid / c[2]; break; } text1.setText(String.valueOf(end)); } catch(Exception ex){} } } }