使用单选按钮允许用户显示另一个类的框架

时间:2011-10-24 16:07:14

标签: java swing

我有这个JRadioButton程序,但我不确定在

之后输入什么
public void actionPerformed(ActionEvent e)
{
    if (e.getSource() == r1)
}

以便显示来自另一个类的帧。简而言之,应该在点击后运行来自另一个类的程序。我得到了所有的程序,除了我搞砸了这条线。

以下是代码:

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
javax.swing.JRadioButton;

public class UseRadio
{
public static void main(String []x)
{
JFrame aFrame = new JFrame("Using Radio Buttons");
aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aFrame.setLayout(new GridLayout(2, 1));

} // main
} // UseRadio

class RadioPanel extends JPanel implements ActionListener
{
JRadioButton r1, r2, r3;
public RadioPanel()
{
r1 = new JRadioButton("Pick Me");
r2 = new JRadioButton("Pick Me", true);
r3 = new JRadioButton("Pick Me");
ButtonGroup g = new ButtonGroup();
g.add(r1); g.add(r2); g.add(r3);
r1.addActionListener(this);
r2.addActionListener(this);
r3.addActionListener(this);
add(r1); add(r2); add(r3);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == r1)
//getclass(PJLoan);
????

//JOptionPane.showMessageDialog(null, "#1");
if (e.getSource() == r2)
JOptionPane.showMessageDialog(null, "#2");
if (e.getSource() == r3)
JOptionPane.showMessageDialog(null, "#3");
} // actionPerformed
} // RadioPanel

enter code here

0 个答案:

没有答案