用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

添加的窗体

2018-06-01 作者: liuqqqq举报

[java]代码库

import java.awt.Button;
import java.awt.Label;
import java.awt.List;

import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class Jpaneldemo extends JFrame {
	private List list = new List(50,true);
	private Label name1 = new Label("姓    名:");
	private TextField namet = new TextField();
	private Label tel = new Label("性    别:");
	private JRadioButton jBM = new JRadioButton("男");
	private JRadioButton jBS= new JRadioButton("女");
	private String [] sele = {"请选择系别","计算机科学与技术","生物医学工程","眼视光"};
	JComboBox jC = new JComboBox(sele);
	private Button addt = new Button("添加");
	private Button del = new Button("删除");
	public Jpaneldemo() {
		setTitle("学生信息输入窗口");
	    this.name1.setBounds(240, 20, 50, 20);
	    this.namet.setBounds(290,20,80,20);
		this.list.setBounds(10, 20, 200, 180);
		this.tel.setBounds(240, 60, 50, 20);
		this.jBM.setBounds(290, 60, 50, 20);
		this.jBS.setBounds(340, 60, 50, 20);
		this.jC.setBounds(240, 90, 130, 20);
		this.addt.setBounds(240, 120, 50, 40);
		this.del.setBounds(320,120, 50, 40);
		ButtonGroup bg = new ButtonGroup();
		bg.add(jBM);
		bg.add(jBS);
		this.list.add("姓名"+"          "+"性别"+"                 "+"系别");
		this.list.add("张三"+"          "+"男"+"                 "+"计算机科学与技术",1);
		this.list.add("刘33"+"          "+"男"+"                 "+"计算机科学与技术",2);
		this.list.setMultipleMode(false);
		this.setLayout(null);
		this.add(this.list);
		this.add(this.tel);
		this.add(this.jBM);
		this.add(this.jBS);
		this.add(this.name1);
		this.add(this.namet);
		this.add(this.addt);
		this.add(this.del);
		this.add(this.jC);
		this.setSize(400, 280);
		this.setLocation(100, 100);
		this.setVisible(true);
	}
public static void main(String[] args) {
	final Jpaneldemo j1 = new Jpaneldemo();
	j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	j1.addt.addActionListener(new ActionListener() {

		public void actionPerformed(ActionEvent e) {
		   String name = j1.namet.getText();
		   String sex = null;
		   if(j1.jBM.isSelected()){
			   sex=j1.jBM.getText();
		   }else if(j1.jBS.isSelected()){
			   sex=j1.jBS.getText();
		   }
		   String sb =(String)j1.jC.getSelectedItem();
		   j1.list.add(name+"          "+sex+"                 "+sb);
		   j1.namet.setText(null);
		}
	});
	j1.del.addActionListener(new ActionListener() {	
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			int a = j1.list.getSelectedIndex();
			j1.list.delItem(a);
		}
	});
}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...