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

📄 mainframe.java

📁 RMI通讯
💻 JAVA
字号:
/**
 * 
 */
package com.vanceinfo.socket.client;

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JToolBar;

import com.vanceinfo.socket.today.Item;
import com.vanceinfo.socket.today.Today;

/**
 * @author 谷明亮
 * @description 客户端主窗体
 */
public class MainFrame {

	private Today today = null;

	private JFrame jfMain = null;

	private JToolBar jtb = null;
	private JButton[] jbtnItems;

	private JEditorPane jep = null;

	// 参数提供配置信息
	public MainFrame(Today today) {
		this.today = today;
		this.initFrame();
	}

	// 根据从服务器端获得的配置信息初始化主窗体,
	public void initFrame() {
		jfMain = new JFrame(today.getMetaInfo().getTitle());

		// 主窗体居中显示
		Toolkit tk = Toolkit.getDefaultToolkit();
		int screenWidth = tk.getScreenSize().width;
		int screenHeight = tk.getScreenSize().height;
		int x = (screenWidth - today.getMetaInfo().getWidth()) / 2;
		int y = (screenHeight - today.getMetaInfo().getHeight()) / 2;
		jfMain.setBounds(x, y, today.getMetaInfo().getWidth(), today
				.getMetaInfo().getHeight());

		// 工具栏组件
		jtb = new JToolBar();
		HashSet<Item> items = today.getToolBar().getItems();
		Iterator<Item> iterator = items.iterator();
		int itemCount = items.size();// 工具栏子项目数量
		jbtnItems = new JButton[itemCount];
		Item item = null;
		URL url = null;
		for (int i = 0; i < itemCount; i++) {
			item = (Item) iterator.next();

			try {
				url = new URL(item.getIcon().trim());
			} catch (MalformedURLException e1) {
				e1.printStackTrace();
			}

			jbtnItems[i] = new JButton(new ImageIcon(url));
			jbtnItems[i].setToolTipText(item.getType());
			jbtnItems[i].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

				}
			});

			jtb.add(jbtnItems[i]);
		}

		jfMain.getContentPane().setLayout(new BorderLayout());
		jfMain.getContentPane().add(jtb, BorderLayout.NORTH);

		// 设置窗体大小是否可变
		jfMain.setResizable(today.getMetaInfo().isResizable());

		jfMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jfMain.setVisible(true);

	}

	public JFrame getJfMain() {
		return jfMain;
	}

	public void setJfMain(JFrame jfMain) {
		this.jfMain = jfMain;
	}
}

⌨️ 快捷键说明

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