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

📄 mymainframe.java

📁 通讯录设计说明 各模块说明 myHeaderBean: 开头动画
💻 JAVA
字号:
package Communication;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class myMainFrame extends JFrame implements Runnable,ActionListener
{
	myHeaderBean mhb;	
	Image mycur;
	Cursor mycursor;
	JMenuBar jmb=new JMenuBar();
	JMenu menuFile;
	JMenu menuHelp;
	JMenuItem miadd=new JMenuItem("添加");
	JMenuItem miupdate=new JMenuItem("更新");
	JMenuItem midelete=new JMenuItem("删除");
	JMenuItem miout=new JMenuItem("退出");
	JMenuItem mdetail=new JMenuItem("帮助");
	JMenuItem mversion=new JMenuItem("版本信息");
	myTreeBean mtb;
	public myMainFrame()
	{
		this.setSize(600,480);
		this.setVisible(false);
		this.setTitle("通讯录");
		this.setResizable(false);						//设置可伸缩性
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);	//设置窗体退出的执行方式
		this.setLocation((1024-getWidth())/2,(768-getHeight())/2);
		Thread t=new Thread(this);
		t.start();
		usemyCursor();				//加载用户自定义的鼠标
		initmenu();					//初始化菜单栏
		initmytree();				//初始化主内容
		addactionListener();		//添加响应
	}
	
	public void run()
	{
		mhb=new myHeaderBean();		//初始化片头
		while(!mhb.isOver())
		{	try
			{
				Thread.sleep(100);
			}
			catch(InterruptedException e){}
		}
		setVisible(true);
		show();	
	}
	
	public void initmytree()
	{
		mtb=new myTreeBean();
		this.getContentPane().add(mtb,"Center");
	}
	
	public void usemyCursor()			
	{
	
		mycur=Toolkit.getDefaultToolkit().getImage("Images\\mycur.gif");
		mycursor=Toolkit.getDefaultToolkit().createCustomCursor(mycur,new Point(0,0),"mycur");
		this.setCursor(mycursor);
		this.setBackground(Color.white);
	}
	
	public void initmenu()
	{
		menuFile=new JMenu("文件");
		menuHelp=new JMenu("帮助");
		jmb.add(menuFile);
		menuFile.add(miadd);
		menuFile.addSeparator();
		menuFile.add(miupdate);
		menuFile.addSeparator();
		menuFile.add(midelete);
		menuFile.addSeparator();
		menuFile.add(miout);
		jmb.add(menuHelp);
		menuHelp.add(mdetail);
		menuHelp.addSeparator();
		menuHelp.add(mversion);
		this.setJMenuBar(jmb);
	}
	
	public void addactionListener()
	{
		miout.addActionListener(this);
		miadd.addActionListener(this);
		miupdate.addActionListener(this);
		midelete.addActionListener(this);
		mversion.addActionListener(this);
		mdetail.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==miout)
		{
			dispose();
			System.exit(0);
		}
		if(e.getSource()==miadd)
		{
			addPersonBean apb=new addPersonBean();
			apb.show();
		}
		if(e.getSource()==miupdate)
		{
			if(mtb.selectedIsLeaf())			//判断当前是否已选择了对象
			{
			updatePersonBean upb=new updatePersonBean(mtb.getSelected());
			upb.show();
			}
			else
			{
				JOptionPane jop=new JOptionPane();
				jop.setVisible(true);
				jop.showMessageDialog(null,"请先选择你的联系人");
				jop.show();
			}
		}
		if(e.getSource()==midelete)
		{
			if(mtb.selectedIsLeaf())		//选中并准备删除
			{
				mtb.removeNode();
			}
			else
			{
				JOptionPane jop=new JOptionPane();
				jop.setVisible(true);
				jop.showMessageDialog(null,"请先选择你的联系人");
				jop.show();
			}
		}
		if(e.getSource()==menuHelp)
		{
			
		}
		if(e.getSource()==mversion)
		{
			myVersionBean mvb=new myVersionBean();
			mvb.show();
		}
	}
	public static void main(String args[])
	{
		myMainFrame mf=new myMainFrame();
	}
}

⌨️ 快捷键说明

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