-1

我试图将单选按钮设置为背景以允许用户选择。

这是代码..

public class FirstWindow extends JFrame {

    private JTextField search;
    private JRadioButton author,title,both;
    private ButtonGroup grp;

    public FirstWindow() {
       super("My App");
       setLayout(new BorderLayout());

    JLabel backGround = new JLabel(new ImageIcon("C:\\Users\\Kareem Abdo\\Desktop\\3.Jpg"));
    backGround.setLayout(null);
    add(backGround);

    search = new JTextField("Search...");
    search.setFont(new Font("Arial",Font.PLAIN,16));
    search.setSize(150, 30);
    search.setLocation(20, 20);
    backGround.add(search);

    author = new JRadioButton("Author",true);
    author.setLocation(20, 25);
    backGround.add(author);

    title = new JRadioButton("Title",false);
    title.setLocation(25, 25);
    backGround.add(title);

    both = new JRadioButton("Both",false);
    both.setLocation(250, 250);
    backGround.add(both);

    grp = new ButtonGroup();
    grp.add(author);
    grp.add(title);
    grp.add(both);

但是单选按钮没有出现在屏幕上!

4

1 回答 1

3
于 2013-07-13T10:00:04.747 回答