⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 communicationbook.java

📁 用java做的通信录 可以显示个人详细信息 使用mysql数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/***
 this program shows basic useage of the JSplitPane;
*/


package com;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.sql.*;

//import com.jgoodies.forms.builder.PanelBuilder;
//import com.jgoodies.forms.layout.CellConstraints;
//import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.*;
import com.jgoodies.forms.builder.*;
import com.jgoodies.forms.layout.*;
public class CommunicationBook extends JFrame
{       
        JTabbedPane jtp;
        LeftControlPane controlPanel;
        PersonInforPanel personInforPanel;
        FamilyInforPanel familyInforPanel;
        CompanyInforPanel companyInforPanel;
        OperateToDetailInfor operToDetailInfor;
        
	 public CommunicationBook()
	 {

	 	  super("  个人通讯录");
	 	  setSize(1200,600);
	 	  setDefaultCloseOperation(EXIT_ON_CLOSE);
                  
                  jtp=new JTabbedPane();
                  personInforPanel=new PersonInforPanel();
                  familyInforPanel=new FamilyInforPanel();
                  companyInforPanel=new CompanyInforPanel();
                  operToDetailInfor=new OperateToDetailInfor(personInforPanel,familyInforPanel,companyInforPanel);
                  controlPanel=new LeftControlPane(operToDetailInfor);
                  
                  jtp.addTab("个人",personInforPanel.buildPanel());
                  jtp.addTab("家庭",familyInforPanel.buildPanel());
                  jtp.addTab("单位",companyInforPanel.buildPanel());
      
      
      
      
	 	  JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,controlPanel.buildPanel(),jtp);
	 	  getContentPane().add(sp,BorderLayout.CENTER);
	 }
	 public static void main(String[] args)
	 {
		 CommunicationBook ssb=new CommunicationBook();
	 	 ssb.setVisible(true);
	 }
}

//------------------------------------------------------------------------------------------------------------------------

class PersonInforPanel
{
	//the labels will be used;
 private JLabel personNameLabel; //姓名标签
 private JLabel personSexLabel;  //性别标签
 private JLabel personRelationLabel;//关系标签;
 private JLabel personBirthDateLabel;//生日标签
 private JLabel personFancyLabel;   //个人爱好标签
 private JLabel personSpecialtyLabel; //个人特长标签
 private JLabel personCellPhoneLabel; //个人手机号标签
 private JLabel personCallPhoneLabel; //个人寻呼号标签
 private JLabel personQQLabel; //个人QQ号标签;
 private JLabel personEmailLabel;//个人Email标签
 private JLabel personWebsiteLabel;//个人主页标签
 private JLabel otherInfoLabel;//其他信息标签;
 
 //the textField will be used;
 public JTextField personNameField;
 public JTextField personBirthDateField;
 public JTextField personFancyField;
 public JTextField personSpecialtyField;
 public JTextField personCellPhoneField;
 public JTextField personCallPhoneField;
 public JTextField personQQField;
 public JTextField personEmailField;
 public JTextField personWebsiteField;
 
 public JTextField personSexField;
 public JTextField personRelationField;
 //the comboBox will be used;
 /*private JComboBox personSexComboBox;
 private JComboBox personRelationComboBox;*/
 
 //the textArea will be used for other information
 private Component  otherInfoArea;
 
 //picture panel will be used;
 public PicturePanel picturePanel;
 private void initComponent()
 {
 	//the initialization of labels;
 	personNameLabel=new JLabel("姓名");
 	personSexLabel=new JLabel("性别");
 	personRelationLabel=new JLabel("关系");
 	personBirthDateLabel=new JLabel("生日");
 	personFancyLabel=new JLabel("爱好");
 	personSpecialtyLabel=new JLabel("特长");
 	personCellPhoneLabel=new JLabel("手机");
 	personCallPhoneLabel=new JLabel("寻呼");
 	personQQLabel=new JLabel("QQ号");
 	personEmailLabel=new JLabel("电子邮件");
 	personWebsiteLabel=new JLabel("个人主页");
 	otherInfoLabel=new JLabel("其他");
 	
 	//the initiallization of TextFields
 	personNameField=new JTextField(10);
  personBirthDateField=new JTextField(10);
  personFancyField=new JTextField();
  personSpecialtyField=new JTextField();
  personCellPhoneField=new JTextField();
  personCallPhoneField=new JTextField();
  personQQField=new JTextField();
  personEmailField=new JTextField();
  personWebsiteField=new JTextField();
  
  personSexField=new JTextField();
  personRelationField=new JTextField();
  
  //the initailization of the ComboBox;
  /*personSexComboBox=new JComboBox();
  personRelationComboBox=new JComboBox();	*/
  
  //the initailization of textArea;
  otherInfoArea=new JScrollPane(new JTextArea());
  
  //picturePanel initialize
  picturePanel=new PicturePanel("image/axiu.jpg");
  picturePanel.setBackground(Color.white);
  
 }
 public JComponent buildPanel()
 {
 	 initComponent();
 	 FormLayout layout=new FormLayout(
 	   "right:pref,3dlu,pref,7dlu,right:pref,3dlu,pref,5dlu,6cm",
 	   "p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,"
 	   +"p,5cm");
 	   
 	 PanelBuilder builder=new PanelBuilder(layout);
 	 builder.setDefaultDialogBorder();
 	 
 	 CellConstraints cc=new CellConstraints();
 	 builder.add(personNameLabel,cc.xy(1,1));
 	 builder.add(personNameField,cc.xy(3,1));
 	 builder.add(personSexLabel,cc.xy(1,3));
 	 builder.add(personSexField,cc.xy(3,3));
 	 builder.add(personRelationLabel,cc.xy(5,1));
 	 builder.add(personRelationField,cc.xy(7,1));
 	 builder.add(personBirthDateLabel,cc.xy(5,3));
 	 builder.add(personBirthDateField,cc.xy(7,3));
 	 builder.add(personFancyLabel,cc.xy(1,5));
 	 builder.add(personFancyField,cc.xyw(3,5,5));
 	 builder.add(personSpecialtyLabel,cc.xy(1,7));
 	 builder.add(personSpecialtyField,cc.xyw(3,7,5));
 	 builder.add(personCellPhoneLabel,cc.xy(1,9));
 	 builder.add(personCellPhoneField,cc.xyw(3,9,5));
 	 builder.add(personCallPhoneLabel,cc.xy(1,11));
 	 builder.add(personCallPhoneField,cc.xyw(3,11,5));
 	 builder.add(personQQLabel,cc.xy(1,13));
 	 builder.add(personQQField,cc.xyw(3,13,5));
 	 builder.add(personEmailLabel,cc.xy(1,15));
 	 builder.add(personEmailField,cc.xyw(3,15,7));
 	 builder.add(personWebsiteLabel,cc.xy(1,17));
 	 builder.add(personWebsiteField,cc.xyw(3,17,7));
 	 builder.add(picturePanel,cc.xywh(9,1,1,13));
 	 builder.add(otherInfoLabel,cc.xy(1,19));
 	 builder.add(otherInfoArea,cc.xywh(2,19,8,2));
 	 return builder.getPanel();
 }
}

class PicturePanel extends JPanel
{
	String pictureFilePath;
	Image img;
	public PicturePanel()
	{
		pictureFilePath="";
		img=null;
	}
	public PicturePanel(String picFilePath)
	{
		pictureFilePath=picFilePath;
		//LoadImage(pictureFilePath);
	}
	public void setPicPath(String picFilePath)
	{
		pictureFilePath=picFilePath;
	}
	public void update()
	{
		this.repaint();
	}
	private void LoadImage(String picFilePath)
	{
		
		img=Toolkit.getDefaultToolkit().getImage(getClass().getResource(picFilePath));
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		LoadImage(pictureFilePath);
		g.drawImage(img,0,0,this);
	}
}

//---------------------------------------------------------------------------------------------------------------------------------
class FamilyInforPanel
{
	private JLabel countryLabel;
	private JLabel provinceLabel;
	private JLabel townLabel;
	private JLabel postNumLabel;
	private JLabel addressLabel;
	private JLabel homePhoneLabel;
	private JLabel homeFaxLabel;
	private JLabel otherLabel;
	
	/*private JComboBox countryBox;
	private JComboBox provinceBox;
	private JComboBox townBox;*/
	
	public JTextField postNumField;
	public JTextField addressField;
	public JTextField homePhoneField;
	public JTextField homeFaxField;
	
	public JTextField countryField;
	public JTextField provinceField;
	public JTextField townField;
	
	private Component otherArea;
	
	private void initComponent()
	{
		countryLabel=new JLabel("国家/地区");
		provinceLabel=new JLabel("省市/自治区");
		townLabel=new JLabel("县州市");
		postNumLabel=new JLabel("邮政编码");
		addressLabel=new JLabel("门牌地址");
		homePhoneLabel=new JLabel("家庭电话");
		homeFaxLabel=new JLabel("家庭传真");
		otherLabel=new JLabel("其他");
		
		/*countryBox=new JComboBox();
		provinceBox=new JComboBox();
		townBox=new JComboBox();*/
		
		countryField=new JTextField();
	  provinceField=new JTextField();
	  townField=new JTextField();
		
		postNumField=new JTextField(10);
		addressField=new JTextField();
		homePhoneField=new JTextField();
		homeFaxField=new JTextField();
		
		otherArea=new JScrollPane(new JTextArea());
	}
	
	public JComponent buildPanel()
	{
		 initComponent();
		 FormLayout layout=new FormLayout(
		    "right:pref,3dlu,5cm,10dlu,right:pref,3dlu,5cm",
		    "p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,top:pref,4cm");
		 
		 PanelBuilder builder=new PanelBuilder(layout);
		 builder.setDefaultDialogBorder();
		 
		 CellConstraints cc=new CellConstraints();
		 builder.add(countryLabel,cc.xy(1,1));
		 builder.add(countryField,cc.xy(3,1));
		 builder.add(provinceLabel,cc.xy(5,1));
		 builder.add(provinceField,cc.xy(7,1));
		 builder.add(townLabel,cc.xy(1,3));
		 builder.add(townField,cc.xy(3,3));
		 builder.add(postNumLabel,cc.xy(5,3));
		 builder.add(postNumField,cc.xy(7,3));
		 builder.add(addressLabel,cc.xy(1,5));
		 builder.add(addressField,cc.xyw(3,5,5));
		 builder.add(homePhoneLabel,cc.xy(1,7));
		 builder.add(homePhoneField,cc.xyw(3,7,5));
		 builder.add(homeFaxLabel,cc.xy(1,9));
		 builder.add(homeFaxField,cc.xyw(3,9,5));
		 builder.add(otherLabel,cc.xy(1,11));
		 builder.add(otherArea,cc.xywh(2,11,6,2));
		 
		return builder.getPanel();
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------

class CompanyInforPanel
{
	private JLabel companyNameLabel;
	private JLabel countryLabel;
	private JLabel provinceLabel;
	private JLabel townLabel;
	private JLabel postNumLabel;
	private JLabel addressLabel;
	private JLabel companyPhoneLabel;
	private JLabel companyFaxLabel;
	private JLabel companyWebSiteLabel;
	private JLabel positionLabel;
	private JLabel departmentLabel;
	private JLabel otherLabel;
	
	/*private JComboBox countryBox;
	private JComboBox provinceBox;
	private JComboBox townBox;
	private JComboBox positionBox;
	private JComboBox departmentBox;*/
	
	public JTextField countryField;
	public JTextField provinceField;
	public JTextField townField;
	public JTextField positionField;
	public JTextField departmentField;
	
	public JTextField companyNameField;
	public JTextField postNumField;
	public JTextField addressField;
	public JTextField companyPhoneField;
	public JTextField companyFaxField;
	public JTextField companyWebsiteField;
	
	private Component otherArea;
	
	private void initComponent()
	{
		companyNameLabel=new JLabel("单位名称");
		countryLabel=new JLabel("国家/地区");
		provinceLabel=new JLabel("省市/自治区");
		townLabel=new JLabel("县州市");
		postNumLabel=new JLabel("邮政编码");
		addressLabel=new JLabel("门牌地址");
		companyPhoneLabel=new JLabel("单位电话");
		companyFaxLabel=new JLabel("单位传真");
		companyWebSiteLabel=new JLabel("单位主页");
		positionLabel=new JLabel("职位");
		departmentLabel=new JLabel("部门/科室");
		otherLabel=new JLabel("其他");
		
		/*countryBox=new JComboBox();
		provinceBox=new JComboBox();
		townBox=new JComboBox();
		positionBox=new JComboBox();
		departmentBox=new JComboBox();*/
		
		countryField=new JTextField();
	  provinceField=new JTextField();
	  townField=new JTextField();
	  positionField=new JTextField();
	  departmentField=new JTextField();
		
		companyNameField=new JTextField();
		postNumField=new JTextField(10);
		addressField=new JTextField();
		companyPhoneField=new JTextField();
		companyFaxField=new JTextField();
		companyWebsiteField=new JTextField();
		
		otherArea=new JScrollPane(new JTextArea());
	}
	
	public JComponent buildPanel()
	{
		 initComponent();
		 FormLayout layout=new FormLayout(
		    "right:pref,3dlu,5cm,10dlu,right:pref,3dlu,5cm",
		    "p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,top:pref,4cm");
		 
		 PanelBuilder builder=new PanelBuilder(layout);
		 builder.setDefaultDialogBorder();
		 
		 CellConstraints cc=new CellConstraints();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -