📄 a070144c3a21001c153ef0b6b1b0026a
字号:
package cn.nawang.test;
import javax.swing.JButton;
import javax.swing.JFrame;
//import javax.swing.JDialog;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.awt.event.*;
import javax.swing.*;
//import javax.swing.event.*;
//import javax.swing.Timer;
public class UIBuilder
{
public void initUI(UI FrameUI)
{
FrameUI.mainFrame = this.createMainFrame(FrameUI);
FrameUI.settingBtn = this.createSettingBtn(FrameUI);
FrameUI.helpBtn = this.createHelpBtn(FrameUI);
FrameUI.aboutBtn = this.createAboutBtn(FrameUI);
FrameUI.startBtn = this.createStartBtn(FrameUI);
FrameUI.refreshBtn = this.createRefreshBtn(FrameUI);
FrameUI.hintBtn = this.createHintBtn(FrameUI);
FrameUI.bombBtn = this.createBombBtn(FrameUI);
FrameUI.showBtn = this.createShowBtn(FrameUI);
FrameUI.timeLabel = this.createTimeLabel(FrameUI);
FrameUI.statusLabel = this.createStatusLabel(FrameUI);
FrameUI.gotoTop = this.createGotoTop(FrameUI);
FrameUI.scoreLabel = this.createScoreLabel(FrameUI);
this.layoutManage(FrameUI);
//this.btnClickHandle(FrameUI);
}
public JFrame createMainFrame (UI FrameUI)
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image icon = toolkit.getImage("cn/nawang/image/kyodai16.gif");
JFrame frame = new JFrame();
frame.setTitle("连连看1.0");
frame.setSize(780, 500);
frame.setIconImage(icon);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return frame;
}
public JButton createSettingBtn(UI FrameUI)
{
JButton settingBtn = new JButton();
//settingBtn.setText("设置");
settingBtn.setBorder(BorderFactory.createEmptyBorder());
settingBtn.setSize(100, 50);
settingBtn.setIcon(this.getIcon("setup.gif"));
return settingBtn;
}
public JButton createHelpBtn(UI FrameUI)
{
JButton helpBtn = new JButton();
//helpBtn.setText("帮助");
helpBtn.setBorder(BorderFactory.createEmptyBorder());
helpBtn.setSize(100, 50);
helpBtn.setIcon(this.getIcon("help.gif"));
return helpBtn;
}
public JButton createAboutBtn(UI FrameUI)
{
JButton aboutBtn = new JButton();
//aboutBtn.setText("关于");
aboutBtn.setBorder(BorderFactory.createEmptyBorder());
aboutBtn.setSize(100, 50);
aboutBtn.setIcon(this.getIcon("about.gif"));
return aboutBtn;
}
public JButton createStartBtn(UI FrameUI)
{
JButton startBtn = new JButton();
//startBtn.setText("开始");
startBtn.setBorder(BorderFactory.createEmptyBorder());
startBtn.setSize(100, 50);
startBtn.setIcon(this.getIcon("start.gif"));
return startBtn;
}
public JButton createRefreshBtn(UI FrameUI)
{
JButton refreshBtn = new JButton();
//refreshBtn.setText("刷新");
refreshBtn.setBorder(BorderFactory.createEmptyBorder());
refreshBtn.setSize(100, 50);
refreshBtn.setIcon(this.getIcon("refresh.gif"));
return refreshBtn;
}
public JButton createHintBtn(UI FrameUI)
{
JButton hintBtn = new JButton();
//hintBtn.setText("提示");
hintBtn.setBorder(BorderFactory.createEmptyBorder());
hintBtn.setSize(100, 50);
hintBtn.setIcon(this.getIcon("hint.gif"));
return hintBtn;
}
public JButton createBombBtn(UI FrameUI)
{
JButton bombBtn = new JButton();
//bombBtn.setText("炸弹");
bombBtn.setBorder(BorderFactory.createEmptyBorder());
bombBtn.setSize(100, 50);
bombBtn.setIcon(this.getIcon("bomb.gif"));
return bombBtn;
}
public JButton createShowBtn(UI FrameUI)
{
JButton showBtn = new JButton();
//showBtn.setText("演示");
showBtn.setBorder(BorderFactory.createEmptyBorder());
showBtn.setSize(100, 50);
showBtn.setIcon(this.getIcon("demo.gif"));
return showBtn;
}
//public Timer createTimer(UI FrameUI)
//{
//Timer timer = new Timer(100, EventHandler);
// }
public JLabel createTimeLabel(UI FrameUI)
{
JLabel timeLabel = new JLabel(" Time: 000.0");
timeLabel.setFont(new Font("Arial", Font.BOLD, 25));
timeLabel.setForeground(new Color(0xd4ffc8));
return timeLabel;
}
public JLabel createStatusLabel(UI FrameUI)
{
JLabel statusLabel = new JLabel("欢迎使用连连看 1.0 alpha");
statusLabel.setFont(new Font("宋体", Font.PLAIN, 12));
statusLabel.setForeground(Color.WHITE);
return statusLabel;
}
public JLabel createGotoTop(UI FrameUI)
{
JLabel gotoTop = new JLabel("Goto top 10");
gotoTop.setFont(new Font("Arial", Font.PLAIN, 12));
gotoTop.setForeground(Color.LIGHT_GRAY);
return gotoTop;
}
public JLabel createScoreLabel(UI FrameUI)
{
JLabel scoreLabel = new JLabel(" $0000");
scoreLabel.setFont(new Font("Arial", Font.BOLD, 30));
scoreLabel.setForeground(Color.YELLOW);
return scoreLabel;
}
public void layoutManage(UI FrameUI)
{
FrameUI.contentPanel = new JPanel();
FrameUI.contentPanel.setBackground(new Color(0x374d76));
FrameUI.contentPanel.setLayout(new GridLayout(10, 17, 10, 10));
FrameUI.toolBar = new JPanel();
FrameUI.toolBar.setBackground(new Color(0x374d76));
FrameUI.toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 50, 0));
FrameUI.toolBar.add(FrameUI.settingBtn);
FrameUI.toolBar.add(FrameUI.helpBtn);
FrameUI.toolBar.add(FrameUI.aboutBtn);
FrameUI.actionPanel = new JPanel();
FrameUI.actionPanel.setBackground(new Color(0x6c93d6));
FrameUI.actionPanel.setLayout(new BoxLayout(FrameUI.actionPanel, BoxLayout.Y_AXIS));
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.scoreLabel);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.startBtn);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.refreshBtn);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.hintBtn);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.bombBtn);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.showBtn);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.actionPanel.add(FrameUI.timeLabel);
FrameUI.actionPanel.add(Box.createGlue());
FrameUI.statusPanel = new JPanel();
FrameUI.statusPanel.setBackground(new Color(0x374d76));
FrameUI.statusPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 0));
FrameUI.statusPanel.add(FrameUI.statusLabel);
for(int i = 0; i<25; i++)
{
FrameUI.statusPanel.add(Box.createGlue());
}
FrameUI.statusPanel.add(FrameUI.gotoTop);
FrameUI.mainContainer = FrameUI.mainFrame.getContentPane();
FrameUI.mainPanel = new JPanel();
FrameUI.mainPanel.setLayout(new BorderLayout(3,3));
FrameUI.mainPanel.add(FrameUI.toolBar, BorderLayout.NORTH);
FrameUI.mainPanel.add(FrameUI.contentPanel, BorderLayout.CENTER);
FrameUI.mainPanel.add(FrameUI.statusPanel, BorderLayout.SOUTH);
FrameUI.mainPanel.add(FrameUI.actionPanel, BorderLayout.EAST);
FrameUI.mainContainer.add(FrameUI.mainPanel, 0);
}
public static ImageIcon getIcon(String filename)
{
ImageIcon icon = new ImageIcon("cn/nawang/image/"+filename);
return icon;
}
// public void btnClickHandle(UI FrameUI)
// {
// FrameUI.startBtn.addActionListener(new ActionListener(){
// public void actionPerformed(ActionEvent evt)
// {
// EventHandler.startBtnClick();
// }
// });
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -