?? cnc.java
字號:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
public class CNC { //主程序
public static int maincontrol_state=-1; //顯示屏狀態(tài),分9個,和主菜單為0 其他和主菜單上寫的一樣
/*系統(tǒng)說明,當按下復位鍵后,系統(tǒng)進入(主菜單)0狀態(tài) 這個時候的快捷按鈕有12345678 ,
* 按1進入文件管理 有快捷鍵0總清 和 1,編輯 ,2復制 ,3刪除 ,↑ 回退到主菜單 ,并有 輸入程序名的輸入框
* 編輯狀態(tài)只有一個ok鍵 使返回文件管理界面
* 每個狀態(tài)里面又有若干快捷操作, 比如文件管理里面,還有編輯,刪除等操作,狀態(tài)為 10 11 12
* */
public static void main(String[] args) {
CNCFrame frame=new CNCFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class CNCFrame extends JFrame
{
private static final long serialVersionUID = -1754417042391360362L;
private JMenuBar menubar;
private JMenu menu,style,about;
private JMenuItem exit,guanyu;
private JCheckBoxMenuItem window,motif,metal;
private AboutWindow aboutwindow=null;
private ManagePanel mp;
public static DisplayPanel dp;
public static JPanel screenPanel;
private static Sys_runTime runpanel;
public CNCFrame()
{
this.setTitle("****數(shù)控系統(tǒng) by CNC-***");
Dimension d=getToolkit().getScreenSize();
this.setSize(d.width,d.height-30);
menu=new JMenu("菜單");
exit=new JMenuItem("退出");
menu.add(exit);
style=new JMenu("切換風格");
menu.add(style);
window=new JCheckBoxMenuItem("windows風格");
motif=new JCheckBoxMenuItem("Motif風格");
metal=new JCheckBoxMenuItem("Metal風格");
motif.setSelected(true);
style.add(window);
about=new JMenu("幫助");
guanyu=new JMenuItem("關(guān)于我們");
about.add(guanyu);
style.add(motif);
String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
setWindowStyle(plaf);
style.add(metal);
ButtonGroup bgu=new ButtonGroup();
bgu.add(window);
bgu.add(motif);
bgu.add(metal);
menu.add(style);
menubar=new JMenuBar();
menubar.add(menu);
menubar.add(about);
this.setJMenuBar(menubar);
JPanel mainPanel=new JPanel(null);
mainPanel.setBackground(new Color(181,255,255));
mainPanel.setSize(d.width-30,d.height-70);
mainPanel.setLocation(15,10);
mainPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
ToolPanel toolPanel=new ToolPanel(CNCFrame.this);
toolPanel.setBackground(new Color(128,0,128));
Border border=BorderFactory.createLineBorder(Color.WHITE);
toolPanel.setBorder(border);
toolPanel.setSize(d.width*3/5-10,d.height*3/6);
toolPanel.setLocation(d.width*2/5-20,50);
mainPanel.add(toolPanel);
Container contentPane=getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(new Color(128,0,128));
contentPane.add(mainPanel);
screenPanel=new JPanel(null);
screenPanel.setBackground(new Color(128,0,128));
screenPanel.setSize(d.width*2/5-10,d.height*3/6);
screenPanel.setLocation(10,50);
screenPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
dp=new DisplayPanel(d.width*2/5-50,d.height*3/6-20);
dp.setSize(d.width*2/5-50,d.height*3/6-20);
dp.setLocation(10,5);
screenPanel.add(dp);
mainPanel.add(screenPanel);
JLabel screenLabel=new JLabel("數(shù)控系統(tǒng)");
runpanel=new Sys_runTime(dp.getSize());
runpanel.setSize(dp.getSize().width,dp.getSize().height);
runpanel.setLocation(10,5);
screenLabel.setSize(220,33);
screenLabel.setLocation(120,10);
screenLabel.setFont(new Font("華文彩云",Font.BOLD,33));
mainPanel.add(screenLabel);
JLabel rightLabel=new JLabel(" MACHINE TOOL CNC SYSTEM");
rightLabel.setSize(200,25);
rightLabel.setLocation(d.width*3/5-10,10);
rightLabel.setBackground(new Color(128,255,128));
rightLabel.setForeground(Color.RED);
rightLabel.setBorder(BorderFactory.createLineBorder(Color.YELLOW));
mainPanel.add(rightLabel);
mp=new ManagePanel(runpanel);
mp.setBounds(10,d.height*3/5+45,d.width-43,d.height*2/5-125);
mainPanel.add(mp);
JLabel screenLabel1=new JLabel("MODEL CNC 2005TC");
JLabel screenLabel2=new JLabel("自家組裝數(shù)控系統(tǒng)");
screenLabel1.setFont(new Font("華文彩云",Font.BOLD,33));
screenLabel2.setFont(new Font("華文彩云",Font.BOLD,33));
screenLabel1.setBounds(120,d.height*4/7+20,d.width/2,33);
screenLabel2.setBounds(d.width*3/5-10,d.height*4/7+20,d.width-43,33);
mainPanel.add(screenLabel1);
mainPanel.add(screenLabel2);
//以下是菜單監(jiān)聽器
window.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
setWindowStyle(plaf);
}
});
motif.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
setWindowStyle(plaf);
}
});
metal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
setWindowStyle(plaf);
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});
guanyu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (aboutwindow==null){
aboutwindow=new AboutWindow();
}
aboutwindow.setVisible(true);
}
});
}
private void setWindowStyle(String plaf) {
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
}
}
public static void updateDisplayPanel(int i){
dp.removeAll();
runpanel.setstatestr(i);
dp.add(runpanel);
dp.updateUI();
}
public static void setmdi(String str){
runpanel.setmdiinput(str);
}
public static String getmditext(){
String str=runpanel.getmditext();
return str;
}
public static void clearmdiinput(){
runpanel.clearmdiinput();
}
public static Sys_runTime getruntimepanel(){
return runpanel;
}
public static void setmdibackspace(){
runpanel.setmdibackspace();
}
}
class AboutWindow extends JWindow{
private static final long serialVersionUID = -373716560737607340L;
public AboutWindow(){
JPanel panel =new JPanel();
panel.setBackground(Color.BLACK);
this.setSize(300,300);
this.setLocationRelativeTo(null);
panel.setLayout(null);
JLabel logo=new JLabel(new ImageIcon("img\\fangda.jpg"));
logo.setBounds(0,0,40,40);
panel.add(logo);
Container c=getContentPane();
c.add(panel);
this.addWindowListener(new WindowAdapter(){
public void windowDeactivated(WindowEvent arg0) {
setVisible(false);
dispose();
}
});
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -