javaswing!!!!!!!!!!!!!!!

hcnmgal 2011-01-25 12:13:39
package com.newer.ui;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;
public class MyFrame extends JFrame {

private static final long serialVersionUID = 1L;
private JTextArea txaMessage;
private JButton btnTest;

private JRadioButton radMan;
private JRadioButton radWoman;

private JCheckBox chkIT;
private JCheckBox chkRead;
private JCheckBox chkSport;

private JComboBox cmbGrade;


private ButtonGroup bgSex;

private JScrollPane sclMessage;
public MyFrame(){
init();
this.setVisible(true);
}

private void init(){
this.setSize(700,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(this);

Container c = this.getContentPane();
c.setBackground(Color.RED);
c.setLayout(null);

txaMessage = new JTextArea();
//txaMessage.setBounds(10, 10, 100, 100);
txaMessage.setLineWrap(true);
//c.add(txaMessage);

sclMessage = new JScrollPane();
sclMessage.setBounds(200, 10, 200, 200);
sclMessage.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
sclMessage.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
sclMessage.getViewport().add(txaMessage);
c.add(sclMessage);

radMan = new JRadioButton("男");
radMan.setBounds(405,10,50,25);
c.add(radMan);

radWoman = new JRadioButton("女");
radWoman.setBounds(460,10,50,25);
radWoman.setSelected(true);
c.add(radWoman);


bgSex = new ButtonGroup();
bgSex.add(radMan);
bgSex.add(radWoman);

chkIT = new JCheckBox("IT");
chkIT.setBounds(405, 50, 80,25);
chkIT.setSelected(true);
c.add(chkIT);

chkRead = new JCheckBox("Read");
chkRead.setBounds(495, 50, 80,25);
c.add(chkRead);

chkSport = new JCheckBox("Sport");
chkSport.setBounds(580, 50, 80,25);
c.add(chkSport);

//Object[] objs = new Object[]{"s1","s2","y2"};
Vector vec = new Vector();
vec.add("s1");
vec.add("s2");
vec.add("s3");

DefaultComboBoxModel model = new DefaultComboBoxModel(vec);
cmbGrade = new JComboBox(model);
cmbGrade.setSelectedIndex(1);
cmbGrade.setBounds(10, 50, 100, 25);
c.add(cmbGrade);


btnTest = new JButton("测试");
btnTest.setBounds(10, 10, 80, 25);
btnTest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//获得单选按钮的值
// String sex = "";
// if(radMan.isSelected()){
// sex = radMan.getText();
// }
// else if(radWoman.isSelected()){
// sex = radWoman.getText();
// }
// txaMessage.setText(sex);
// cmbGrade.addItem(sex);

String it = chkIT.getText();
String sport = chkSport.getText();
String read = chkRead.getText();

Vector vec = new Vector();
vec.add(it);
vec.add(sport);
vec.add(read);

DefaultComboBoxModel model = new DefaultComboBoxModel(vec);
cmbGrade.setModel(model);


}

});
c.add(btnTest);
//启用/禁用

}
}
...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zn85600301 2011-01-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lk198186 的回复:]

你到底想问什么问题?
[/Quote]
楼主的意思是标准的回复可见吧??!!
lk198186 2011-01-25
  • 打赏
  • 举报
回复
你到底想问什么问题?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧