首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

JAVA,该怎么处理

2012-11-23 
JAVAimport java.awt.BorderLayoutimport java.awt.Panelimport java.awt.event.ActionEventimport jav

JAVA
import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Java5 extends JFrame implements ActionListener{
///private JDesktopPane desktopPane;
private JPanel panel;
private JLabel StuName,StuSex,Habit,Home,Others;
private JTextField name;
private JRadioButton Man,Woman;
private ButtonGroup btnGroup;
private JComboBox home;
private JCheckBox list1,list2,list3,list4,list5,list6;
private JTextArea textArea1,textArea2;
private JButton btn1;
public Java5(){
Panel panel = new Panel(null);
  ///desktopPane = new JDesktopPane();
StuName = new JLabel("姓名:",4);
  StuSex = new JLabel("性别:",4);
  Habit = new JLabel("爱好:",4);
Home = new JLabel("籍贯:",4);
Others = new JLabel("其他信息:",4);
 
name = new JTextField(10);
 
Man = new JRadioButton("男");
Woman = new JRadioButton("女");
 
btnGroup = new ButtonGroup();
btnGroup.add(Man);
btnGroup.add(Woman);
 
list1 = new JCheckBox("运动");
list2 = new JCheckBox("跳舞");
list3 = new JCheckBox("唱歌");
list4 = new JCheckBox("画画");
list5 = new JCheckBox("下棋");
list6 = new JCheckBox("登山");
 
home = new JComboBox(new String[]{"泸州","自贡","成都","康定","重庆","内江"});
 
textArea1 = new JTextArea();
textArea2 = new JTextArea();
 
btn1 = new JButton("确定");
//////////////////////////////////////
btn1.addActionListener(this);
//////////////////////////
StuName.setBounds(50, 20, 50, 25);
name.setBounds(110, 20, 90, 25);
 
StuSex.setBounds(50, 60, 50, 25);
Man.setBounds(110, 60, 40, 25);
Woman.setBounds(150, 60, 40, 25);
 
Habit.setBounds(50, 100, 50, 25);
list1.setBounds(110, 100, 60, 25);
list2.setBounds(180, 100, 60, 25);
list3.setBounds(240, 100, 60, 25);
list4.setBounds(110, 140, 60, 25);
list5.setBounds(180, 140, 60, 25);
list6.setBounds(240, 140, 60, 25);
 
Home.setBounds(50, 180, 50, 25);
home.setBounds(110, 180, 80, 25);

Others.setBounds(49, 220, 80, 25);
textArea1.setBounds(140, 220, 240, 100);
 
btn1.setBounds(160, 340, 70, 25);
 
textArea2.setBounds(105, 400, 240, 100);
 
 
///////////////////////////////////////

this.setContentPane(panel);
panel.add(StuName);
panel.add(name);
panel.add(StuSex);
panel.add(Man);
panel.add(Woman);
panel.add(Habit);
panel.add(list1);
  panel.add(list2);
panel.add(list3);
panel.add(list4);
panel.add(list5);
panel.add(list6);
panel.add(Home);
panel.add(home);
panel.add(Others);
panel.add(textArea1);
panel.add(btn1);
panel.add(textArea2);
 


 
this.setBounds(10, 10, 410, 620);
 this.setVisible(true);
 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 this.setResizable(false);
}

/**
* @param args
**/
public static void main(String[] args) {


// TODO Auto-generated method stub
  new Java5();
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource().equals(btn1)){
  save();
}

}

private void save() {
// TODO Auto-generated method stub
String str="";
str = name.getText().trim();
str = "男";

str = home.getSelectedItem().toString();
str = Others.getText().trim();

if(Woman.isSelected()){
str ="女";
}

JOptionPane.showMessageDialog(null, "确定");

}
}

当点击确定后,怎样将确定以上的内容显示到下面一个文本域里面?????
初学.....

[解决办法]
差不多就这个意思

Java code
private void save() {        // TODO Auto-generated method stub        String str = "";        str = name.getText().trim();        str = "男";        str = home.getSelectedItem().toString();        str = Others.getText().trim();        if (Woman.isSelected()) {            str = "女";        }        JOptionPane.showMessageDialog(null, "确定");        textArea2.setText("姓名  "+name.getText()+"\n性别  "+"\n"+str+"\n"+textArea1.getText());//加上这句     } 

热点排行