硬件领域出现了单片式计算机系统
20世纪90年代,硬件领域出现了单片式计算机系统,这种价格低廉的系统一出现就立即引起了自动控制领域人员的注意,因为使用它可以大幅度提升消费类电子产品(如电视机顶盒、面包烤箱、移动电话等)的智能化程度。Sun公司为了抢占市场先机,在1991年成立了一个称为Green的项目小组,帕特里克、詹姆斯•高斯林、麦克•舍林丹和其他几个工程师一起组成的工作小组在加利福尼亚州门洛帕克市沙丘路的一个小工作室里面研究开发新技术,专攻计算机在家电产品上的嵌入式应用。
1 package Com.SwingTest; 2 3 4 import java.awt.BorderLayout; 5 import java.awt.GridBagConstraints; 6 import java.awt.GridBagLayout; 7 import java.awt.GridLayout; 8 import java.awt.Insets; 9 import java.awt.event.ActionEvent; 10 import java.util.Arrays; 11 import java.util.List; 12 13 import javax.swing.AbstractAction; 14 import javax.swing.Action; 15 import javax.swing.BorderFactory; 16 import javax.swing.JButton; 17 import javax.swing.JComponent; 18 import javax.swing.JFrame; 19 import javax.swing.JLabel; 20 import javax.swing.JOptionPane; 21 import javax.swing.JPanel; 22 import javax.swing.JPasswordField; 23 import javax.swing.JTextField; 24 import javax.swing.SwingUtilities; 25 import javax.swing.UIManager; 26 27 28 /** 29 * @author Administrator 30 * 31 */ 32 public class SwingText_11 extends JPanel { 33 34 private static final String LABEL_USERNAME = "用户账号:"; 35 private static final String LABEL_PASSWORD = "用户密码:"; 36 37 private static final String LABEL_OK = "确定"; 38 private static final String LABEL_Cancel = "取消"; 39 40 private static final int FIELD_COLS = 20; 41 42 private JTextField fieldUsername; 43 private JPasswordField fieldPassword; 44 45 private Action actionOK; 46 private Action actionCancel; 47 48 49 public static void main(String[] args) { 50 51 SwingUtilities.invokeLater(new Runnable() { 52 @Override 53 public void run() { 54 try { 55 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 56 } catch (Exception e) { 57 e.printStackTrace(); 58 } 59 JFrame test = new JFrame("欢迎进入本系统"); 60 test.setContentPane(new SwingText_11()); 61 test.pack(); 62 test.setResizable(false); 63 test.setLocationRelativeTo(null); 64 test.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 65 test.setVisible(true); 66 } 67 }); 68 } 69 70 71 72 SwingText_11() { 73 74 super(new BorderLayout(5, 5)); 75 assert SwingUtilities.isEventDispatchThread(); 76 // 文本框 77 fieldUsername = new JTextField(FIELD_COLS); 78 // 密码框 79 fieldPassword = new JPasswordField(FIELD_COLS); 80 81 actionOK = new AbstractAction(LABEL_OK) { 82 @Override 83 public void actionPerformed(ActionEvent e) { 84 // @TODO to be implemented. 实现确认按钮的操作 85 //TODO 86 String text = fieldUsername.getText(); 87 if (text.isEmpty()) { 88 JOptionPane.showMessageDialog(null, "用户名不能为空!", "提示", JOptionPane.ERROR_MESSAGE); 89 return; 90 } 91 92 JOptionPane.showMessageDialog(null, "这是一个假登录"+text, "提示", JOptionPane.ERROR_MESSAGE); 93 } 94 }; 95 96 actionCancel = new AbstractAction(LABEL_Cancel) { 97 @Override 98 public void actionPerformed(ActionEvent e) { 99 // @TODO to be implemented. 实现取消按钮的操作 100 //退出程序 101 System.exit(0); 102 } 103 }; 104 // BorderLayout.NORTH 这是指定向北浮动 105 add(layoutText(Arrays.asList( "第一行文字", "第二行文字", "第三行文字")), BorderLayout.NORTH); 106 add(layoutFields(), BorderLayout.CENTER); 107 add(layoutControl(), BorderLayout.SOUTH); 108 109 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 110 } 111 112 private JComponent layoutControl() { 113 // 控件布局 114 JComponent result = new JPanel(); 115 // 这里是确认 和 取消的按钮 116 result.add(new JButton(actionOK)); 117 result.add(new JButton(actionCancel)); 118 119 return result; 120 } 121 122 private JComponent layoutFields() { 123 // 布局位置 124 JComponent result = new JPanel(new GridBagLayout()); 125 GridBagConstraints gbc = new GridBagConstraints(); 126 127 gbc.gridx = 0; 128 gbc.gridy = 0; 129 //固定 向西 130 gbc.anchor = GridBagConstraints.WEST; 131 //是否填充 132 gbc.fill = GridBagConstraints.NONE; 133 gbc.insets = new Insets(5, 5, 5, 5); 134 //加入文字描述 135 result.add(new JLabel(getBoldHTML(LABEL_USERNAME)), gbc); 136 gbc.gridy++; 137 result.add(new JLabel(getBoldHTML(LABEL_PASSWORD)), gbc); 138 139 gbc.gridx++; 140 gbc.gridy = 0; 141 gbc.fill = GridBagConstraints.HORIZONTAL; 142 result.add(fieldUsername, gbc); 143 gbc.gridy++; 144 result.add(fieldPassword, gbc); 145 146 return result; 147 } 148 149 private JComponent layoutText(List<String> lines) { 150 151 assert lines != null; 152 153 JComponent result = new JPanel(new GridLayout(lines.size(), 1)); 154 for (String line : lines) 155 result.add(new JLabel(line)); 156 157 result.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10)); 158 return result; 159 } 160 161 private String getBoldHTML(String s) { 162 // 设置字体的大小粗细 163 return "<html><b>" + s + "</b></html>"; 164 } 165 }