Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface isSelected jRadioButton方法不起作用_User Interface_Jradiobutton - Fatal编程技术网

User interface isSelected jRadioButton方法不起作用

User interface isSelected jRadioButton方法不起作用,user-interface,jradiobutton,User Interface,Jradiobutton,我为单选按钮选择的isSelected方法不起作用,即使我在运行程序时选择了它们,我对java gui编码还是很陌生,因此请大家解释一下,我正在发布整个gui的类代码。我正在使用eclipse swing designer public class gui { private JFrame frame; private final ButtonGroup buttonGroup = new ButtonGroup(); /** * Launch the application. */

我为单选按钮选择的isSelected方法不起作用,即使我在运行程序时选择了它们,我对java gui编码还是很陌生,因此请大家解释一下,我正在发布整个gui的类代码。我正在使用eclipse swing designer

 public class gui {

private JFrame frame;
private final ButtonGroup buttonGroup = new ButtonGroup();

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                gui window = new gui();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 * @throws FileNotFoundException 
 */
public gui() throws FileNotFoundException {
    initialize();
}

/**
 * Initialize the contents of the frame.
 * @throws FileNotFoundException 
 */
private void initialize() throws FileNotFoundException {
    FileReader reader=new FileReader("C:\\Users\\kkj\\workspace\\javaproject\\src\\Database.txt");
    Scanner in=new Scanner(reader);
    BList Restaurant=new BList();
    BList ATM=new BList();
    BList Hospital=new BList();
    BList Hotels=new BList();
    BList Petrol=new BList();
    final Llist locations=new Llist();
    System.out.println("Loading");

    while(in.hasNextLine())

    {
        BNode bnode=new BNode();
        bnode.name=in.nextLine();
        //System.out.println(bnode.name);
        String type=in.nextLine();
        bnode.loc=in.nextLine();
        if(type.equals("Restaurant"))
        {
            Restaurant.insert(bnode);

        }
        if(type.equals("ATM"))
        {
            ATM.insert(bnode);

        }
        if(type.equals("Hospital"))
        {
            Hospital.insert(bnode);

        }
        if(type.equals("Hotels"))
        {
            Hotels.insert(bnode);

        }
        if(type.equals("Petrol"))
        {
            Petrol.insert(bnode);

        }



    }
    FileReader reader2=new FileReader("C:\\Users\\kkj\\workspace\\javaproject\\src\\locations.txt");
    Scanner inL=new Scanner(reader2);
    int s=0;

    while(inL.hasNextLine())
    {
        LNode loc=new LNode();
        loc.Name=inL.nextLine();
        loc.dist=s++;
        BNode temp;
        temp=Restaurant.head;
        while(temp.next!=null)
            {   if(temp.loc.equals(loc.Name))
                {loc.rest=temp;break;}
                temp=temp.next;
            }



        temp=Hospital.head;
        while(temp.next!=null)
        {   if(temp.loc.equals(loc.Name))
            {loc.Hospital=temp;break;}
            temp=temp.next;
        }

        temp=Hotels.head;
        while(temp.next!=null)
        {   if(temp.loc.equals(loc.Name))
            {loc.Hotels=temp;break;}
            temp=temp.next;
        }
        //loc.hotels=temp;
        temp=ATM.head;
        while(temp.next!=null)
        {   if(temp.loc.equals(loc.Name))
            {loc.ATM=temp;break;}
            temp=temp.next;
        }

        locations.insert(loc);
    }




    System.out.println("Loaded");
    System.out.println(">>>>>>>>>>>Restaurants<<<<<<<<<<<<");
    Restaurant.disp();
    System.out.println(">>>>>>>>>>>Hotels<<<<<<<<<<<<");
    Hotels.disp();
    System.out.println(">>>>>>>>>>>Hospital<<<<<<<<<<<<");
    Hospital.disp();
    System.out.println(">>>>>>>>>>>ATM's<<<<<<<<<<<<");
    ATM.disp();
    System.out.println(">>>>>>>>>>>Locations<<<<<<<<<<<<");
    locations.disp();

    final String curr="Bsk";
    String locin;
    final String typein="Hospital";
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);







    JRadioButton rdbtnBsk = new JRadioButton("Bsk");
    buttonGroup.add(rdbtnBsk);
    rdbtnBsk.setBounds(26, 35, 109, 23);
    frame.getContentPane().add(rdbtnBsk);

    JRadioButton rdbtnKoramangala = new JRadioButton("Koramangala");
    buttonGroup.add(rdbtnKoramangala);
    rdbtnKoramangala.setBounds(26, 72, 109, 23);
    frame.getContentPane().add(rdbtnKoramangala);

    JRadioButton rdbtnMgRoad = new JRadioButton("MG Road");
    buttonGroup.add(rdbtnMgRoad);
    rdbtnMgRoad.setBounds(26, 125, 109, 23);
    frame.getContentPane().add(rdbtnMgRoad);
    if(rdbtnBsk.isSelected())
        {
            locin="Bsk";
        }
    if(rdbtnKoramangala.isSelected())
    {
        locin="Koramangala";
    }
    if(rdbtnMgRoad.isSelected())
    {
        locin="MG Road";
    }
    else System.exit(2);
    final String locinn=locin;

    JButton btnOutput = new JButton("output");
    btnOutput.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) 
        {
            Output out1=new Output();
            System.out.println(">>>>>>>>>>>"+typein+" in "+locinn+"<<<<<<<<<<<<");
            out1.display(locations, locinn, typein,curr);
        }
    });
    btnOutput.setBounds(182, 193, 89, 23);
    frame.getContentPane().add(btnOutput);

        }
private class SwingAction extends AbstractAction {
    public SwingAction() {
        putValue(NAME, "SwingAction");
        putValue(SHORT_DESCRIPTION, "Some short description");
    }
    public void actionPerformed(ActionEvent e) {
    }
}
公共类gui{
私有JFrame;
私有最终按钮组按钮组=新按钮组();
/**
*启动应用程序。
*/
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
gui窗口=新建gui();
window.frame.setVisible(true);
}捕获(例外e){
e、 printStackTrace();
}
}
});
}
/**
*创建应用程序。
*@抛出FileNotFoundException
*/
公共gui()引发FileNotFoundException{
初始化();
}
/**
*初始化框架的内容。
*@抛出FileNotFoundException
*/
private void initialize()引发FileNotFoundException{
FileReader=newFileReader(“C:\\Users\\kkj\\workspace\\javaproject\\src\\Database.txt”);
扫描仪输入=新扫描仪(读卡器);
BList餐厅=新BList();
BList ATM=新BList();
BList医院=新BList();
BList Hotels=新BList();
BList汽油=新BList();
最终Llist位置=新的Llist();
系统输出打印项次(“加载”);
while(在.hasNextLine()中)
{
BNode BNode=新的BNode();
bnode.name=in.nextLine();
//System.out.println(bnode.name);
字符串类型=in.nextLine();
bnode.loc=in.nextLine();
if(类型等于(“餐厅”))
{
餐厅。插入(bnode);
}
if(类型等于(“ATM”))
{
ATM.insert(bnode);
}
if(类型等于(“医院”))
{
医院.插入(bnode);
}
if(类型等于(“酒店”))
{
酒店。插入(bnode);
}
if(类型等于(“汽油”))
{
汽油机.插入件(B节点);
}
}
FileReader reader2=新的FileReader(“C:\\Users\\kkj\\workspace\\javaproject\\src\\locations.txt”);
扫描仪inL=新扫描仪(读取器2);
int s=0;
while(inL.hasNextLine())
{
LNode loc=新LNode();
loc.Name=inL.nextLine();
loc.dist=s++;
B节点温度;
temp=餐厅负责人;
while(临时下一步!=null)
{如果(临时位置等于(位置名称))
{loc.rest=temp;break;}
温度=下一个温度;
}
temp=医院负责人;
while(临时下一步!=null)
{如果(临时位置等于(位置名称))
{loc.Hospital=temp;break;}
温度=下一个温度;
}
temp=Hotels.head;
while(临时下一步!=null)
{如果(临时位置等于(位置名称))
{loc.Hotels=temp;break;}
温度=下一个温度;
}
//位置:酒店=临时;
温度=自动取款机机头;
while(临时下一步!=null)
{如果(临时位置等于(位置名称))
{loc.ATM=temp;break;}
温度=下一个温度;
}
位置。插入(loc);
}
系统输出打印项次(“已加载”);

System.out.println(“>>>>>>>>>>>>>>>>餐厅我也是Java编程新手,但这可能行得通,对我来说也行

将整个if/else块放入“output”按钮的actionPerformed()方法中,如下所示:

JButton btnOutput = new JButton("output");
btnOutput.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) 
    {  if(rdbtnBsk.isSelected())
       {
         locin="Bsk";
       }
       else if(rdbtnKoramangala.isSelected())
       {
         locin="Koramangala";
       }
       else if(rdbtnMgRoad.isSelected())
       {
         locin="MG Road";
       }

       final String locinn=locin;
       Output out1=new Output();
       System.out.println(">>>>>>>>>>>"+typein+" in "+locinn+"<<<<<<<<<<<<");
       out1.display(locations, locinn, typein,curr);
    }
});
btnOutput.setBounds(182, 193, 89, 23);
frame.getContentPane().add(btnOutput);

    }
JButton btnOutput=新JButton(“输出”);
btnOutput.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件arg0)
{if(rdbtnBsk.isSelected())
{
locin=“Bsk”;
}
else if(rdbtnKoramangala.isSelected())
{
locin=“Koramangala”;
}
else if(rdbtnMgRoad.isSelected())
{
locin=“MG路”;
}
最终字符串locinn=locin;
Output out1=新的输出();
System.out.println(“>>>>>>>>>”+typein+“in”+locinn+”中