我做了个实验,你看符合你要求不~ /* * Created on 2006-7-18 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package radio_test;import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JTextArea;/** * @author xiaoxianggua * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class RadioTest extends JFrame implements ActionListener{ public JCheckBox checkBox = new JCheckBox(); public JTextArea textArea = new JTextArea("hello word!"); public static void main(String[] args) { RadioTest myFrame = new RadioTest(); myFrame.setSize(400,300); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.setVisible(true);
/*
* Created on 2006-7-18
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package radio_test;import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextArea;/**
* @author xiaoxianggua
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class RadioTest extends JFrame implements ActionListener{ public JCheckBox checkBox = new JCheckBox();
public JTextArea textArea = new JTextArea("hello word!");
public static void main(String[] args) {
RadioTest myFrame = new RadioTest();
myFrame.setSize(400,300);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setVisible(true);
}
public RadioTest(){
Container container = getContentPane();
container.setLayout(new FlowLayout(FlowLayout.LEFT,10,20));
container.add(checkBox);
container.add(textArea);
textArea.setEnabled(false);
textArea.setVisible(true);
checkBox.addActionListener(this);
} /* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if(e.getSource() == checkBox){
if(textArea.isEnabled())
textArea.setEnabled(false);
else
textArea.setEnabled(true);
}
}
}
function check(obj){
document.getElementById("userId").disabled=obj.checked;
}
</script>
<input type="checkbox" onclick="check(obj);">choose
<input type="text" id="userId" disabled>默认为不选中