是这样的,我想实现一个登陆的界面,上面有姓名,性别,爱好以及学历
目标:点击提交按扭,能够在黑屏中显示填写人的资料
实现:
1:在黑屏中显示人名(实现)
2在黑屏幕中显示性别(单选实现,但是不知道如何来监听这个选中)
3:爱好(复选,不知道怎么来监听选种,不知道是否和单选一致)
4:学历(下拉框以实现,但是不知道怎么监听选种)
代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class news{
public static void main(String[] args){
myframe mfra = new myframe();
mfra.setSize(300,200);
mfra.setVisible(true);
}
}
class myframe extends JFrame{
JLabel jl = new JLabel("姓名:");//姓名
JTextField jtf =new JTextField(15);
JRadioButton jrb1 = new JRadioButton("男",true);/**单选按扭*/
JRadioButton jrb2 = new JRadioButton("女");
JCheckBox jcb1 = new JCheckBox("游泳");/**复选按扭*/
JCheckBox jcb2 = new JCheckBox("游戏");
String[] str = {"高中","大专","本科"};
JComboBox jcom = new JComboBox(str);
JButton jb = new JButton("递交");
Container pane = this.getContentPane();//桌布
JPanel pan1 = new JPanel();//模块1~5
JPanel pan2 = new JPanel();
JPanel pan3 = new JPanel();
JPanel pan4 = new JPanel();
JPanel pan5 = new JPanel();
ButtonGroup few = new ButtonGroup();
public myframe(){
pane.setLayout(new GridLayout(5,1));
pan1.setLayout(new FlowLayout());
pan2.setLayout(new FlowLayout());
pan3.setLayout(new FlowLayout());
pan4.setLayout(new FlowLayout());
pan4.setLayout(new FlowLayout());
pane.add(pan1);
pane.add(pan2);
pane.add(pan3);
pane.add(pan4);
pane.add(pan5);
pan1.add(jl);
pan1.add(jtf);
pan2.add(jrb1);
pan2.add(jrb2);
pan3.add(jcb1);
pan3.add(jcb2);
pan4.add(jcom);
pan5.add(jb);
few.add(jrb1);
few.add(jrb2);
jb.addActionListener(new mylistener(this));
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
public void shower(ActionEvent e){
System.out.println(jl.getText() + jtf.getText());//点击实现黑屏输出
}
}
class mylistener implements ActionListener{
myframe mf;
public mylistener(myframe a){
mf = a;
}
public void actionPerformed(ActionEvent e){
mf.shower(e);
}
}