import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Xx extends JFrame implements ActionListener , ItemListener{
String STR1="";
String STR1_1="";
String STR1_2="";
String STR1_3="";
String STR1_4="";
String STR1_5="";
String STR2="";
JRadioButton radio1;
JRadioButton radio2;
JRadioButton radio3;
JRadioButton radio4;
JRadioButton radio5;
ButtonGroup group;
JCheckBox checkbox1;
JCheckBox checkbox2;
JCheckBox checkbox3;
JCheckBox checkbox4;
JCheckBox checkbox5;
JLabel label1;
JLabel label2;
JLabel label3;
JTextField text;
JButton bt1;
JButton bt2;
public Xx(){
super("个人信息调查");
setBounds(300,300,500,300);
JLabel lb1 = new JLabel("年龄段:");
add(lb1);
ButtonGroup group = new ButtonGroup();
JRadioButton radio1 = new JRadioButton("5~15岁");
JRadioButton radio2 = new JRadioButton("16~25岁");
JRadioButton radio3 = new JRadioButton("16~25岁");
JRadioButton radio4 = new JRadioButton("16~25岁");
JRadioButton radio5 = new JRadioButton("16~25岁");
group.add(radio1);
group.add(radio2);
group.add(radio3);
group.add(radio4);
group.add(radio5);
add(radio1);
add(radio2);
add(radio3);
add(radio4);
add(radio5);
JLabel lb2 = new JLabel("兴趣爱好:");
add(lb2);
JCheckBox checkBox1 = new JCheckBox("交友");
JCheckBox checkBox2 = new JCheckBox("户外");
JCheckBox checkBox3 = new JCheckBox("购物");
JCheckBox checkBox4 = new JCheckBox("旅游 ");
JCheckBox checkBox5 = new JCheckBox("其它 ");
add(checkBox1);
add(checkBox2);
add(checkBox3);
add(checkBox4);
add(checkBox5);
JLabel lb3 = new JLabel("调查结果为:");
add(lb3);
text=new JTextField(25);
add(text);
JButton bt1 =new JButton("提交");
JButton bt2 =new JButton("清空");
add(bt1);
add(bt2);
checkBox1.addItemListener(this);
checkBox2.addItemListener(this);
checkBox3.addItemListener(this);
checkBox4.addItemListener(this);
checkBox5.addItemListener(this);
radio1.addItemListener(this);
radio2.addItemListener(this);
radio3.addItemListener(this);
radio4.addItemListener(this);
radio5.addItemListener(this);
show();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == bt1){
STR1=STR1_1+","+STR1_2+","+STR1_3+","+STR1_4+","+STR1_5;
text.setText("你是一个"+STR2+"的人,"+"你比较喜欢"+STR1+"。");
//System.out.println("提交成功!");
}else if(e.getSource() == bt2){
STR1="";
STR1_1="";
STR1_2="";
STR1_3="";
STR1_4="";
STR1_5="";
STR2="";
text.setText(null);
//System.out.println("删除成功!");
}
}
public void itemStateChanged(ItemEvent e) {
if(e.getItem()==checkbox1){
String str=checkbox1.getText();
STR1_1=str;
}else if(e.getItem()==checkbox2){
String str=checkbox2.getText();
STR1_2=str;
}else if(e.getItem()==checkbox3){
String str=checkbox3.getText();
STR1_3=str;
}else if(e.getItem()==checkbox4){
String str=checkbox4.getText();
STR1_4=str;
}else if(e.getItem()==checkbox5){
String str=checkbox5.getText();
STR1_5=str;
}
if(e.getItem()==radio1){
String str=radio1.getText();
STR2=str;
}else if(e.getItem()==radio2){
String str=radio2.getText();
STR2=str;
}else if(e.getItem()==radio3){
String str=radio3.getText();
STR2=str;
}else if(e.getItem()==radio4){
String str=radio4.getText();
STR2=str;
}else if(e.getItem()==radio5){
String str=radio5.getText();
STR2=str;
}
}
}
public class Dc {
public static void main(String[] args) {
Xx xx = new Xx();
xx.setLayout(new FlowLayout());
}
}
以下答案由GPT-4.5Plus大模型(语音)与博主A努力中.......共同编写:
从您提供的代码来看,界面中有单选按钮、复选按钮和文本框,用于选取年龄段和兴趣爱好,并显示结果。但是运行后没有显示任何结果,这很可能是由以下几个原因导致的:
解决方法是为按钮和选项框添加监听器,例如:
java
bt1.addActionListener(this); // this实现了ActionListener
radio1.addItemListener(this);// this实现了ItemListener
解决方法是在监听器方法中调用updateUI():
java
public void actionPerformed(ActionEvent e) {
// ...
updateUI();
}
解决方法是在修改这些变量后立即调用updateUI()刷新界面。
解决方法是在修改STR1后,调用:
java
text.setText(STR1);
将STR1的值设置到文本框中。
除此之外,其他注意点有:
所以,解决这个问题的思路是:
线程 的存在与电脑的CPU有关,早期CPU是单核的,一个CPU在一个时间单位内只能做一件事。这就存在了问题,当执行的任务比较多的时候单核CPU的处理能力就不够用了。于是后来就有了多核CPU。
CPU核心多了,存在CPU核心之间的通信,他们之间需要协同完成一下任务。
很抱歉,根据提供的参考资料并没有明确的问题和代码,无法给出具体解决方案。请提供更具体的问题和相关代码,我会尽力提供帮助。