用户注册



邮箱:

密码:

用户登录


邮箱:

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

发表随想


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

代码4

2018-06-20 作者: 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.JFrame;
 
public class Jpaneldemo extends JFrame {
    private List list = new List(50,true);
    private Label le = new Label("姓    名:");
    private TextField tx = new TextField();
    private Label le2 = new Label("电话号码:");
    private TextField te= new TextField();
    private Button bt = new Button("添加");
    private Button bt2 = new Button("删除");
    public Jpaneldemo() {
        setTitle("电话簿");
        this.le.setBounds(20, 10, 50, 20);
        this.tx.setBounds(80, 10, 100, 20);
        this.le2.setBounds(200, 10, 60, 20);
        this.te.setBounds(260, 10, 100, 20);
        this.bt.setBounds(380, 10, 50, 20);
        this.bt2.setBounds(450, 10,50, 20);
        this.list.setBounds(10, 50, 500, 400);
        this.list.add("姓名"+"             "+"电话号码");
        this.list.add("张三"+"             "+"123456789",1);
        this.list.add("刘11"+"           "+"1111111111",2);
        this.list.setMultipleMode(false);
        this.setLayout(null);
        this.add(this.list);
        this.add(this.le2);
        this.add(this.te);
        this.add(this.le);
        this.add(this.tx);
        this.add(this.bt);
        this.add(this.bt2);
        this.setSize(540, 400);
        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.bt.addActionListener(new ActionListener() {
         
        public void actionPerformed(ActionEvent e) {
           String name = j1.tx.getText();
           String phone = j1.te.getText();
           j1.list.add(name+"             "+phone);
           j1.tx.setText(null);
           j1.te.setText(null);
        }
    });
    j1.bt2.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、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

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

加载中,请稍后...