请高手写个java课程设计的代码
我要做的java课程设计是一个“个人信息调查表”,就是简单的单选按钮和复选框的运用,希望高手能高帮忙写个代码,要能运行的,下边会给出个课本的范例。到时候还要答辩,最好能说...
我要做的java课程设计是一个“个人信息调查表”,就是简单的单选按钮和复选框的运用,希望高手能高帮忙写个代码,要能运行的,下边会给出个课本的范例。到时候还要答辩,最好能说下作用和功能。。。(java没学好)。。。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class survry extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JCheckBox[] jcbArray = { new JCheckBox("交友"), new JCheckBox("户外"),
new JCheckBox("购物"), new JCheckBox("旅游"), new JCheckBox("其他") };
private JRadioButton[] jrbArray = { new JRadioButton("5~15岁"),
new JRadioButton("16~25岁", true), new JRadioButton("26~35岁"),
new JRadioButton("36~45岁"), new JRadioButton("46~55岁") };
private JButton[] jbArray = { new JButton("提交"), new JButton("清空") };
private JLabel[] jlArray = { new JLabel("年龄段:"), new JLabel("兴趣爱好:"),
new JLabel("调查的结果为:") };
private JTextField jtf = new JTextField();
private ButtonGroup bg = new ButtonGroup();
public survry() {
jp.setLayout(null);
for (int i = 0; i < 2; i++) {
jbArray[i].setBounds(40 + i * 100, 40, 80, 30);
jlArray[i].setBounds(40 + i * 120, 100, 120, 30);
jp.add(jrbArray[i]);
jp.add(jcbArray[i]);
jrbArray[i].addActionListener(this);
jcbArray[i].addActionListener(this);
bg.add(jrbArray[i]);
if (i > 1)
continue;
jlArray[i].setBounds(20, 20 + i * 50, 80, 30);
jbArray[i].setBounds(400 + i * 120, 200, 80, 26);
jp.add(jlArray[i]);
jp.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
jlArray[2].setBounds(20, 150, 120, 30);
jp.add(jlArray[2]);
jtf.setBounds(120, 150, 500, 26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("个人信息调查表");
this.setBounds(100, 100, 700, 280);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbArray[1]) {
for (int i = 0; i < jcbArray.length; i++)
jcbArray[i].setSelected(false);
jtf.setText("");
} else {
StringBuffer temp1 = new StringBuffer("你是一个");
StringBuffer temp2 = new StringBuffer();
for (int i = 0; i < 5; i++) {
if (jrbArray[i].isSelected()) {
temp1.append(jrbArray[i].getText());
if (jcbArray[i].isSelected()) {
temp2.append(jcbArray[i].getText() + ",");
}
}
if (temp2.length() == 0) {
jtf.setText("兴趣爱好不能为空!!!");
} else {
temp1.append("的人,你比较喜欢");
temp1.append(temp2.substring(0, temp2.length() - 1));
jtf.setText(temp1.append("。").toString());
}
}
}
}
public static void main(String[] args) {
new survry();
}
}
这是课本上修改一小段的 希望高手能帮改下 不要和上边一样 内容随便 总之是个人信息调查表就行了 小弟在此谢过了。。。
东西是不难,问题倒是遇到了。。。明后2天就要交了,一个是时间赶不上,二个这学期java又没怎么学,简单也弄不出来。。。过后再打算看 希望有人能帮忙修改下 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class survry extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JCheckBox[] jcbArray = { new JCheckBox("交友"), new JCheckBox("户外"),
new JCheckBox("购物"), new JCheckBox("旅游"), new JCheckBox("其他") };
private JRadioButton[] jrbArray = { new JRadioButton("5~15岁"),
new JRadioButton("16~25岁", true), new JRadioButton("26~35岁"),
new JRadioButton("36~45岁"), new JRadioButton("46~55岁") };
private JButton[] jbArray = { new JButton("提交"), new JButton("清空") };
private JLabel[] jlArray = { new JLabel("年龄段:"), new JLabel("兴趣爱好:"),
new JLabel("调查的结果为:") };
private JTextField jtf = new JTextField();
private ButtonGroup bg = new ButtonGroup();
public survry() {
jp.setLayout(null);
for (int i = 0; i < 2; i++) {
jbArray[i].setBounds(40 + i * 100, 40, 80, 30);
jlArray[i].setBounds(40 + i * 120, 100, 120, 30);
jp.add(jrbArray[i]);
jp.add(jcbArray[i]);
jrbArray[i].addActionListener(this);
jcbArray[i].addActionListener(this);
bg.add(jrbArray[i]);
if (i > 1)
continue;
jlArray[i].setBounds(20, 20 + i * 50, 80, 30);
jbArray[i].setBounds(400 + i * 120, 200, 80, 26);
jp.add(jlArray[i]);
jp.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
jlArray[2].setBounds(20, 150, 120, 30);
jp.add(jlArray[2]);
jtf.setBounds(120, 150, 500, 26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("个人信息调查表");
this.setBounds(100, 100, 700, 280);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbArray[1]) {
for (int i = 0; i < jcbArray.length; i++)
jcbArray[i].setSelected(false);
jtf.setText("");
} else {
StringBuffer temp1 = new StringBuffer("你是一个");
StringBuffer temp2 = new StringBuffer();
for (int i = 0; i < 5; i++) {
if (jrbArray[i].isSelected()) {
temp1.append(jrbArray[i].getText());
if (jcbArray[i].isSelected()) {
temp2.append(jcbArray[i].getText() + ",");
}
}
if (temp2.length() == 0) {
jtf.setText("兴趣爱好不能为空!!!");
} else {
temp1.append("的人,你比较喜欢");
temp1.append(temp2.substring(0, temp2.length() - 1));
jtf.setText(temp1.append("。").toString());
}
}
}
}
public static void main(String[] args) {
new survry();
}
}
这是课本上修改一小段的 希望高手能帮改下 不要和上边一样 内容随便 总之是个人信息调查表就行了 小弟在此谢过了。。。
东西是不难,问题倒是遇到了。。。明后2天就要交了,一个是时间赶不上,二个这学期java又没怎么学,简单也弄不出来。。。过后再打算看 希望有人能帮忙修改下 展开
展开全部
只是简单的改了一下,在爱好的“其他”中加入了一个用来输入的文本框,不知道你想改成什么样子的呢?
类的名字最好首字母大写。
package game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class survry extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JRadioButton man = new JRadioButton("男",true);
private JRadioButton woman = new JRadioButton("女");
ButtonGroup sexBG = new ButtonGroup();
JLabel sexSTR = new JLabel("你的性别:");
JLabel likeSTR = new JLabel("你的爱好:");
JLabel ageSTR = new JLabel("你的年龄:");
private JCheckBox[] jcbArray = {new JCheckBox("灌水"), new JCheckBox("游戏"),
new JCheckBox("发呆"), new JCheckBox("旅游"),
new JCheckBox("其他")};
private JRadioButton[] jrbArray = {new JRadioButton("小学毕业"),
new JRadioButton("亭亭玉立", true),
new JRadioButton("而立之年"),
new JRadioButton("大展宏图"),
new JRadioButton("涛声依旧")};
private JButton[] jbArray = {new JButton("提交"), new JButton("清空")};
private JLabel[] jlArray = {new JLabel("年龄段:"), new JLabel("兴趣爱好:"),
new JLabel("调查的结果为:")};
private JTextField otherTF = new JTextField();
private JTextField jtf = new JTextField();
private ButtonGroup bg = new ButtonGroup();
boolean isViewOtherTF = false;
public survry() {
jp.setLayout(null);
sexBG.add(man);
sexBG.add(woman);
man.setBounds(100, 20, 50, 30);
woman.setBounds(150, 20, 50, 30);
jp.add(man);
jp.add(woman);
sexSTR.setBounds(30, 20, 75, 30);
jp.add(sexSTR);
likeSTR.setBounds(30, 50, 75, 30);
jp.add(likeSTR);
ageSTR.setBounds(30, 80, 75, 30);
jp.add(ageSTR);
for (int i = 0; i < jcbArray.length; i++) {
jcbArray[i].setBounds(60 * i + 100, 50, 60, 30);
jp.add(jcbArray[i]);
}
otherTF.setBounds(410, 50, 100, 22);
jp.add(otherTF);
otherTF.setVisible(false);
jcbArray[jcbArray.length - 1].addActionListener(this);
for (int i = 0; i < jrbArray.length; i++) {
jrbArray[i].setBounds(90 * i + 100, 80, 90, 30);
jp.add(jrbArray[i]);
bg.add(jrbArray[i]);
}
jbArray[0].setBounds(30, 110, 80, 30);
jp.add(jbArray[0]);
jbArray[1].setBounds(120, 110, 80, 30);
jp.add(jbArray[1]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jtf.setBounds(120, 150, 500, 26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("个人信息调查表");
this.setBounds(100, 100, 700, 280);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jcbArray[jcbArray.length - 1]){
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}else{
otherTF.setVisible(true);
isViewOtherTF = true;
}
}
if (e.getSource() == jbArray[1]) {
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}
for (int i = 0; i < jcbArray.length; i++){
jcbArray[i].setSelected(false);
}
jtf.setText("");
otherTF.setText("");
sexBG.setSelected(man.getModel(),true);
bg.setSelected(jrbArray[1].getModel(),true);
}
if (e.getSource() == jbArray[0]) {
StringBuffer temp1 = new StringBuffer("你是一个");
StringBuffer temp2 = new StringBuffer();
for (int i = 0; i < 5; i++) {
if (jrbArray[i].isSelected()) {
temp1.append(jrbArray[i].getText());
}
if (jcbArray[i].isSelected()) {
if (i == 4) {
temp2.append(otherTF.getText());
} else {
temp2.append(jcbArray[i].getText() + ",");
}
}
}
if (temp2.length() == 0) {
jtf.setText("难道你没有爱好?");
} else {
temp1.append("的人,你比较喜欢");
temp1.append(temp2.substring(0, temp2.length() - 1));
jtf.setText(temp1.append("。").toString());
}
}
}
public static void main(String[] args) {
new survry();
}
}
类的名字最好首字母大写。
package game;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class survry extends JFrame implements ActionListener {
private JPanel jp = new JPanel();
private JRadioButton man = new JRadioButton("男",true);
private JRadioButton woman = new JRadioButton("女");
ButtonGroup sexBG = new ButtonGroup();
JLabel sexSTR = new JLabel("你的性别:");
JLabel likeSTR = new JLabel("你的爱好:");
JLabel ageSTR = new JLabel("你的年龄:");
private JCheckBox[] jcbArray = {new JCheckBox("灌水"), new JCheckBox("游戏"),
new JCheckBox("发呆"), new JCheckBox("旅游"),
new JCheckBox("其他")};
private JRadioButton[] jrbArray = {new JRadioButton("小学毕业"),
new JRadioButton("亭亭玉立", true),
new JRadioButton("而立之年"),
new JRadioButton("大展宏图"),
new JRadioButton("涛声依旧")};
private JButton[] jbArray = {new JButton("提交"), new JButton("清空")};
private JLabel[] jlArray = {new JLabel("年龄段:"), new JLabel("兴趣爱好:"),
new JLabel("调查的结果为:")};
private JTextField otherTF = new JTextField();
private JTextField jtf = new JTextField();
private ButtonGroup bg = new ButtonGroup();
boolean isViewOtherTF = false;
public survry() {
jp.setLayout(null);
sexBG.add(man);
sexBG.add(woman);
man.setBounds(100, 20, 50, 30);
woman.setBounds(150, 20, 50, 30);
jp.add(man);
jp.add(woman);
sexSTR.setBounds(30, 20, 75, 30);
jp.add(sexSTR);
likeSTR.setBounds(30, 50, 75, 30);
jp.add(likeSTR);
ageSTR.setBounds(30, 80, 75, 30);
jp.add(ageSTR);
for (int i = 0; i < jcbArray.length; i++) {
jcbArray[i].setBounds(60 * i + 100, 50, 60, 30);
jp.add(jcbArray[i]);
}
otherTF.setBounds(410, 50, 100, 22);
jp.add(otherTF);
otherTF.setVisible(false);
jcbArray[jcbArray.length - 1].addActionListener(this);
for (int i = 0; i < jrbArray.length; i++) {
jrbArray[i].setBounds(90 * i + 100, 80, 90, 30);
jp.add(jrbArray[i]);
bg.add(jrbArray[i]);
}
jbArray[0].setBounds(30, 110, 80, 30);
jp.add(jbArray[0]);
jbArray[1].setBounds(120, 110, 80, 30);
jp.add(jbArray[1]);
jbArray[0].addActionListener(this);
jbArray[1].addActionListener(this);
jtf.setBounds(120, 150, 500, 26);
jp.add(jtf);
jtf.setEditable(false);
this.add(jp);
this.setTitle("个人信息调查表");
this.setBounds(100, 100, 700, 280);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jcbArray[jcbArray.length - 1]){
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}else{
otherTF.setVisible(true);
isViewOtherTF = true;
}
}
if (e.getSource() == jbArray[1]) {
if(isViewOtherTF){
otherTF.setVisible(false);
isViewOtherTF = false;
}
for (int i = 0; i < jcbArray.length; i++){
jcbArray[i].setSelected(false);
}
jtf.setText("");
otherTF.setText("");
sexBG.setSelected(man.getModel(),true);
bg.setSelected(jrbArray[1].getModel(),true);
}
if (e.getSource() == jbArray[0]) {
StringBuffer temp1 = new StringBuffer("你是一个");
StringBuffer temp2 = new StringBuffer();
for (int i = 0; i < 5; i++) {
if (jrbArray[i].isSelected()) {
temp1.append(jrbArray[i].getText());
}
if (jcbArray[i].isSelected()) {
if (i == 4) {
temp2.append(otherTF.getText());
} else {
temp2.append(jcbArray[i].getText() + ",");
}
}
}
if (temp2.length() == 0) {
jtf.setText("难道你没有爱好?");
} else {
temp1.append("的人,你比较喜欢");
temp1.append(temp2.substring(0, temp2.length() - 1));
jtf.setText(temp1.append("。").toString());
}
}
}
public static void main(String[] args) {
new survry();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询