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

📄 gui_7segdisplay.java

📁 這是一個8051的模擬器 以java寫成
💻 JAVA
字号:
import javax.swing.*;import java.awt.*;/** * Projet de langage JAVA IFITEP 3 2005 - Simulateur 8051  * <p>  * Simulation d'un composant graphique du type afficheur 7 segments. * Un bus d'un largueur de 4 bits est param鑤rable. Ce qui permet d'affficher * tous les chiffres de la base 16. *   * @author Matthieu SIMON * @version 1.0 du 28/06/05 */public class GUI_7SegDisplay extends JFrame  {		/*	 * 7 Segment Display :	 * 	 *   F A B	 *   F   B	 *   F G B	 *   E G C	 *   E   C	 *   E D C	 * 	 * N -> A | B | C | D | E | F | G	 	 * -------|---|---|---|---|---|---	 * 0 -> 1 | 1 | 1 | 1 | 1 | 1 | 0  -> 7E	 * 1 -> 0 | 1 | 1 | 0 | 0 | 0 | 0  -> 30	 * 2 -> 1 | 1 | 0 | 1 | 1 | 0 | 1  -> 6D	 * 3 -> 1 | 1 | 1 | 1 | 0 | 0 | 1  -> 79	 * 4 -> 0 | 1 | 1 | 0 | 0 | 1 | 1  -> 33	 * 5 -> 1 | 0 | 1 | 1 | 0 | 1 | 1  -> 5B	 * 6 -> 1 | 0 | 1 | 1 | 1 | 1 | 1  -> 5F	 * 7 -> 1 | 1 | 1 | 0 | 0 | 0 | 0  -> 70	 * 8 -> 1 | 1 | 1 | 1 | 1 | 1 | 1  -> 7F	 * 9 -> 1 | 1 | 1 | 1 | 0 | 1 | 1  -> 7B	 * A -> 1 | 1 | 1 | 0 | 1 | 1 | 1  -> 77	 * B -> 0 | 0 | 1 | 1 | 1 | 1 | 1  -> 1F	 * C -> 1 | 0 | 0 | 1 | 1 | 1 | 0  -> 4E	 * D -> 0 | 1 | 1 | 1 | 1 | 0 | 1  -> 3D	 * E -> 1 | 0 | 0 | 1 | 1 | 1 | 1  -> 4F	 * F -> 1 | 0 | 0 | 0 | 1 | 1 | 1  -> 47	 */	/**	 * La table de resolution du d閏odage BCD -> 7 segments	 */	public final static int[] RESOLVE_7SEG = {			0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47	};	private JComboBox[] comboBoxes = new JComboBox[4];	private DisplayPnl disp;		/**	 * Cr閑 une fenetre afficheur 7 segments.	 */	public GUI_7SegDisplay() {		super();		setTitle("7 Seg");		getContentPane().add(disp = new DisplayPnl());		JPanel panel = new JPanel(new GridLayout(4, 2));				createComboBoxes(panel);		getContentPane().add(panel, BorderLayout.SOUTH);		setSize(120, 220);			setLocation(530+250, 385+40+110+10);		setVisible(true);		setResizable(false);		drawSeg();	}		/**	 * Cr閑 les 4 combobox pour la selection des bits du bus	 * @param panel Le panel sur lequel on ajoute les combobox.	 */	private void createComboBoxes(JPanel panel) {		JLabel label;		String[] str = new String[4*8];		for(int j = 0; j < 4; j++)			for(int k = 0; k < 8; k++)				str[8*j+k] = "P" + j + "." + k;		for(int i = 0; i < 4; i++) {			label = new JLabel("Bit " + i + " :");			panel.add(label);						comboBoxes[i] = new JComboBox(str);			comboBoxes[i].setSelectedIndex(i);			panel.add(comboBoxes[i]);		}	}		/**	 * D閏odage BCD -> 7 segments	 * @param boxes Les combobox.	 * @return La valeur ou chaque bit repr閟ente un segment	 */	private int resolveStateFromBoxes(JComboBox[] boxes) {		int[] tbl = { CORE_CPU8051.P0, CORE_CPU8051.P1, CORE_CPU8051.P2, CORE_CPU8051.P3 };		int port, bit, tmp = 0;		for(int i = 0; i < 4; i++) {			port = Integer.parseInt(((String)boxes[i].getSelectedItem()).substring(1, 2));			bit  = Integer.parseInt(((String)boxes[i].getSelectedItem()).substring(3, 4));			tmp |= (((CORE_CPU8051.internalDataMem[tbl[port]]&(1<<bit)) != 0 ? 1 : 0)<<i)&0xFF;		}		return  RESOLVE_7SEG[tmp];	}		private class DisplayPnl extends JPanel {		private final static int WI = 30;		private final static int HE = 10;			private void drawRect(Graphics g, int st, int x, int y, int or) {			int w, h;			if(or == 0) {// horiz				w = WI; h = HE;			}			else {				w = HE; h = WI;			}			if(st != 0)				g.setColor(Color.RED);			else				g.setColor(Color.WHITE);			g.fillRect(x, y, w, h);						}				public void paint(Graphics g) {			super.paint(g);			g.setColor(Color.RED);			int x = (120-(WI+3*HE))/2, y = 10;						drawRect(g, state&0x40, x + HE     , y              , 0);			drawRect(g, state&0x20, x + HE + WI, y + HE         , 1);			drawRect(g, state&0x10, x + HE + WI, y + HE   +   WI, 1);			drawRect(g, state&0x08, x + HE     , y + HE   + 2*WI, 0);			drawRect(g, state&0x04, x          , y + HE   +   WI, 1);			drawRect(g, state&0x02, x          , y + HE         , 1);			drawRect(g, state&0x01, x + HE     , y + HE/2 +   WI, 0);					}	}		private int oldstate = 0;	private int state;		/**	 * Met 

⌨️ 快捷键说明

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