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

📄 cnc.java

📁 主类CNC.java
💻 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;  //显示屏状态,分9个,和主菜单为0 其他和主菜单上写的一样 
	/*系统说明,当按下复位键后,系统进入(主菜单)0状态 这个时候的快捷按钮有12345678 ,
	 * 按1进入文件管理  有快捷键0总清 和 1,编辑 ,2复制 ,3删除 ,↑ 回退到主菜单  ,并有 输入程序名的输入框 
	 * 编辑状态只有一个ok键 使返回文件管理界面
	 * 每个状态里面又有若干快捷操作, 比如文件管理里面,还有编辑,删除等操作,状态为 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("****数控系统 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("关于我们");
		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("数控系统");
		
		
		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("自家组装数控系统");
		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);
		//以下是菜单监听器
		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 + -