?? mainframe.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 + -