Java GUI 电话簿

1.主页面package phoneBookGUI;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.EventQueue;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import java.util.Vector;import javax.swin
摘要由CSDN通过智能技术生成

1.主页面

package phoneBookGUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class GUI extends JFrame {  //总页面
    JButton addButton = new ColorButton("添加",new Color(230,230,255));  //五个功能按钮
	JButton deleteButton = new ColorButton("删除",new Color(240,255,255));
	JButton setButton = new ColorButton("修改",new Color(250,235,215));
	JButton findButton = new ColorButton("查找",new Color(255,250,205));
	JButton backButton = new ColorButton("复原",new Color(135,206,250));
	private static TableModel model = null;  //表格控件
	private static GUITable table = null;

	public GUI(String title) {  
		super(title);
		String[] titles = {"姓名","电话","性别"};
		model = new TableModel(titles);	
		table = new GUITable(model);
		this.setBounds(0, 0, 600, 600);
		this.add(new PanelGUI(),BorderLayout.NORTH);
		this.add(new PanelTable(table));
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setResizable(false);
		addButton.addActionListener((e)->{add();});
		deleteButton.addActionListener((e)->{delete();});
		findButton.addActionListener((e)->{find();});
		setButton.addActionListener((e)->{set();});
		backButton.addActionListener((e)->{back();});
	}
	

	private class PanelGUI extends JPanel{  //总页面上层面板,放置五个按钮
		public PanelGUI() {
			this.setBounds(0, 0, 600, 50);
			this.add(addButton);
			this.add(deleteButton);
			this.add(findButton);
			this.add(setButton);	
			this.add(backButton);
		}
	}
	
	private class PanelTable extends JPanel{  //总页面下层面板,放置表格
		public PanelTable(JTable table) {
			this.setBounds(0, 0, 800, 400);
			this.add(table);
			this.add(new JScrollPane(table),BorderLayout.CENTER);
			
		}
	}
	
	private void add() {  //添加联系人
		Add add = new Add(this);
		add.setTitle("添加联系人");
		add.setModal(true);
		add.setVisible(true);
		boolean flag = true;
		if(add.getAccepted()) {
			for(int i = 0; i < table.getRowCount(); i++) {
				if(table.getValueAt(i, 1).equals(add.getValue().getPhoneNo())) {
					flag = false;
					 JOptionPane.showMessageDialog(null, "该号码不能重复保存", "错误",JOptionPane.ERROR_MESSAGE);
				}
			}
			if(flag == true)
			{
				model.addRow(add.getValue());	
			}
		}
	}
	
	private void delete() {  //删除联系人
		int[] rows = table.getSelectedRows();
		for(int i = rows.length - 1; i >= 0; i--)
		{
			int index = rows[i];
			model.removeRow(index);
		}
	}
	
	private void find() {
		Find find = new Find(this);
		find.setModal(true);
		find.set
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值