我有问题帮帮我啊。。。
import java.io.*;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class StudentData extends JFrame {
final static int NAME_SIZE = 32;
final static int GENDER_SIZE = 6;
final static int RECORD_SIZE =
(NAME_SIZE + GENDER_SIZE);
private RandomAccessFile raf;
private JTextField jtfName = new JTextField(NAME_SIZE);
private JRadioButton rb1 = new JRadioButton("Male");
private JRadioButton rb2 = new JRadioButton("Female");
private JButton jbtAdd = new JButton("Add");
public StudentData() {
// Open or create a random access file
try {
raf = new RandomAccessFile("StudentData.dat", "rw");
}
catch(IOException ex) {
System.out.print("Error: " + ex);
System.exit(0);
}
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1, 2));
p1.add(new JLabel("Name"));
p1.add(new JLabel("Gender"));
JPanel jpGender = new JPanel();
jpGender.setLayout(new GridLayout(1, 2));
jpGender.add(rb1);
jpGender.add(rb2);
ButtonGroup group1 = new ButtonGroup();
group1.add(rb1);
group1.add(rb2);
我只能读取name的资料。。。
要怎样才能读取以及保存所选的radio button数值??
----------------解决方案--------------------------------------------------------
你为radio button创建一个事件监听。
----------------解决方案--------------------------------------------------------
回复 2楼 ggggwffgqeg
怎样说呢??我是新手不太会呢...
可以详解吗??
----------------解决方案--------------------------------------------------------