📄 gui_ioports.java
字号:
import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * Projet de langage JAVA IFITEP 3 2005 - Simulateur 8051 * <p> * GUI_IOPorts * * @author Matthieu SIMON * @version 1.0 du 28/06/05 */public class GUI_IOPorts extends JDialog { String[] ioPortsStr = { "P0", "P1", "P2", "P3" }; int[] ioPorts = { CORE_CPU8051.P0, CORE_CPU8051.P1, CORE_CPU8051.P2, CORE_CPU8051.P3 }; JCheckBox[] checkBoxes = new JCheckBox[32]; String[] checkStr = new String[32]; public GUI_IOPorts(JFrame frame) { super(frame); setTitle("I/O Ports"); JPanel panel = new JPanel(new GridLayout(4, 9)); JLabel label; CheckBoxesActionListener listener = new CheckBoxesActionListener(); for(int i = 0; i < checkBoxes.length; i++) { if(i%8 == 0) { label = new JLabel(ioPortsStr[i/8] + " :"); panel.add(label); } checkBoxes[i] = new JCheckBox(); checkBoxes[i].addActionListener(listener); panel.add(checkBoxes[i]); checkStr[i] = ioPortsStr[i/8] + "." + (7-(i%8)); } getContentPane().add(panel); } private class CheckBoxesActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { JCheckBox box = (JCheckBox)e.getSource(); for(int i = 0; i < checkBoxes.length; i++) if(box.equals(checkBoxes[i])) { int port = 0; for(int j = 0; j < 4; j++) if(checkStr[i].substring(0, 2).equals(ioPortsStr[j])) { port = ioPorts[j]; break; } int bit = Integer.parseInt(checkStr[i].substring(3)); int sel = checkBoxes[i].isSelected()?1:0; CORE_CPU8051.internalDataMem[port] = (CORE_CPU8051.internalDataMem[port]&(~(1<<bit))) | (sel<<bit); return; } } } public void fillIOPorts() { for(int i = 0; i < ioPortsStr.length; i++) for(int j = 0; j < 8; j++) checkBoxes[i*8+j].setSelected( (CORE_CPU8051.internalDataMem[ioPorts[i]]&(1<<(7-j))) != 0 ); } public void setDefaultLocation() { setSize(210, 110); setLocation(530+250, 385+40); setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -