JAVA编程 通过文本行输入学生姓名,通过单选按钮选择性别,复选框选择课程,在文本框中显示所填写及选择信

如题所述

第1个回答  2012-07-30
package helloworld;

import java.awt.*;

import javax.swing.*;
//import com.borland.jbcl.layout.XYLayout;
//import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Frame1 extends JFrame {
//XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
public static void main(String[] args) {
Frame1 frame=new Frame1();
frame.setBounds(100, 100, 200, 300);
frame.setVisible(true);
}
public Frame1() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

private void jbInit() throws Exception {
//getContentPane().setLayout(xYLayout1);
getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
jLabel1.setText("性 别:");
//xYLayout1.setWidth(326);
//xYLayout1.setHeight(214);
jButton1.setText("提 交");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jRadioButton2.setText("女");
jLabel2.setText("爱 好:");
jCheckBox1.setText("唱歌");
jCheckBox2.setText("跳舞");
jCheckBox3.setText("阅读");
this.getContentPane().add(jLabel1);//, new XYConstraints(31, 60, 46, 21));
this.getContentPane().add(jRadioButton1);//,new XYConstraints(127, 60, -1, -1));
this.getContentPane().add(jRadioButton2);//,new XYConstraints(216, 60, -1, -1));
this.getContentPane().add(jLabel2);//, new XYConstraints(31, 111, -1, -1));
this.getContentPane().add(jCheckBox1);//, new XYConstraints(97, 106, -1, -1));
this.getContentPane().add(jCheckBox2);//,new XYConstraints(164, 106, -1, -1));
this.getContentPane().add(jCheckBox3);//,new XYConstraints(233, 106, -1, -1));
this.getContentPane().add(jButton1);//, new XYConstraints(124, 154, -1, -1));
jRadioButton1.setText("男");
jRadioButton1.setSelected(true);
ButtonGroup bg=new ButtonGroup();
bg.add(jRadioButton1);
bg.add(jRadioButton2);

}

public void jButton1_actionPerformed(ActionEvent e) {
System.out.println("性别:"+(jRadioButton1.isSelected()?jRadioButton1.getText():jRadioButton2.getText()));
if(jCheckBox1.isSelected()){
System.out.println(jCheckBox1.getText());
}
if(jCheckBox2.isSelected()){
System.out.println(jCheckBox2.getText());
}
if(jCheckBox3.isSelected()){
System.out.println(jCheckBox3.getText());
}
}
}

class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
第2个回答  2010-12-28
就是jsp+servlet代码,用request.getParameter(arg0)得到数据,不明白百度hi上聊

java输入学生姓名如何编写
1.通过文本行输入学生姓名,通过单选按钮选择性别,通过复选框选择课程,并在文本框中显示所填写及选择的信息;2.其界面如右图所示;3.用Swing组件实现。*\/ import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.text.*;public class CourseSel extends JFrame { private ...

JAVA编写一个窗口(frame),要求窗口中有文本框,按钮,标签,单选框,复选...
JLabel label; \/\/标签 JComboBox combobox;\/\/下拉菜单 JCheckBox checkbox;\/\/复选框 JRadioButton radiobutton;\/\/单选框 JTextField textfield;\/\/文本框 button = new JButton("按钮");label = new JLabel("标签:");checkbox = new JCheckBox("复选框一");radiobutton = new JRadioButton(...

JAVA编程题
sex = e.getActionCommand(); \/\/获得单选按钮表示的性别字符串 }3、单选按钮可以注册选择事件监听器: radiobutton_male.addItemListener(this); \/\/注册复选框的选择事件监听器 public void itemStateChanged(ItemEvent e) \/\/在组合框的下拉列表中选择数据项时触发执行 { \/\/选择单选按钮时触发执行 if (e.getSou...

JAVA 两个单选按钮(男、女),一个文本框,一个确定按钮。在文本框输入男...
import java.awt.GridLayout;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JRadioButton;import javax.swing.JTextField;public class Chooser { public static void main(String[] args) { final String...

用Java语言设计一个界面,
学生姓名 学号 显示信息 需要用到文本框JTextField 单选按钮 需要用到组件 JRadioButton 复选框 需要用到组件 JCheckBox 组合框 需要用到组件 JComboBox 图片效果 参考代码如下 \/\/导入所需要的包import java.awt.event.*;import javax.swing.border.*;import javax.swing.*;import java.awt.*...

设计一个文本框 用户在文本框中输入什么 窗体标题就同步显示什么 怎么...
1、首先需要选择创建窗体设计按钮,如下图所示。2、创建好一个新窗体后,右键单击窗体左上角选择属性命令,如下图所示。3、接下来需要在右侧的属性表标题处输入测试窗体,如下图所示。4、接下来需要设置好后关闭窗体,如下图所示。5、接下来需要保存窗体设计,如下图所示。6、最后需要修改窗体名称即可...

相似回答