1个回答
展开全部
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Chooser {
public static void main(String[] args) {
final String MALE = "男";
final String FEMALE = "女";
JFrame f = new JFrame("Chooser");
final JRadioButton male = new JRadioButton("男");
final JRadioButton female = new JRadioButton("女");
final JTextField input = new JTextField();
JButton btn = new JButton("Go");
f.add(male);
f.add(female);
f.add(input);
f.add(btn);
f.setLayout(new GridLayout(2, 2));
f.setVisible(true);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btn.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
if(input.getText().equals(MALE)){
male.setSelected(true);
female.setSelected(false);
}else if(input.getText().equals(FEMALE)){
female.setSelected(true);
male.setSelected(false);
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
}
}
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Chooser {
public static void main(String[] args) {
final String MALE = "男";
final String FEMALE = "女";
JFrame f = new JFrame("Chooser");
final JRadioButton male = new JRadioButton("男");
final JRadioButton female = new JRadioButton("女");
final JTextField input = new JTextField();
JButton btn = new JButton("Go");
f.add(male);
f.add(female);
f.add(input);
f.add(btn);
f.setLayout(new GridLayout(2, 2));
f.setVisible(true);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btn.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
if(input.getText().equals(MALE)){
male.setSelected(true);
female.setSelected(false);
}else if(input.getText().equals(FEMALE)){
female.setSelected(true);
male.setSelected(false);
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询