我对 JAVA 完全陌生。我想创建一个带有两个单选按钮的表单,一个用于学生,另一个用于教师。当用户单击学生时,应打开另一个与学生相关的表单,当用户单击教师时,应打开教师表单,然后要求用户输入相关数据....这是我的第一个代码....
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
public class Frm1 extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Frm1 frame = new Frm1();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Frm1() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JRadioButton rb1=new JRadioButton("STUDENT");
add(rb1);
JRadioButton rb2=new JRadioButton("TEACHER");
add(rb2);
}
}
it adds only teacher radio button to the form not the student,can any one help plus how will i make the program to go to teacher or student form when respective radio button is selected.
提前致谢