📄 famousuniversity.java
字号:
package university;import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.UIManager;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class famousUniversity extends Applet { private boolean isStandalone = false; private Label label1 = new Label(); private Button button1 = new Button(); private Checkbox checkbox1 = new Checkbox(); private Checkbox checkbox2 = new Checkbox(); private Label label2 = new Label(); private Choice choice2 = new Choice(); private TextArea textArea1 = new TextArea(); private TextField textField1 = new TextField(); private Checkbox checkbox3 = new Checkbox(); private TextField textField2 = new TextField(); private Label label3 = new Label(); private Button button2 = new Button(); private TextField textField3 = new TextField(); private Label label4 = new Label(); private Choice choice1 = new Choice(); private Label label5 = new Label(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public famousUniversity() { } //Initialize the applet public void init() { choice1.addItem("网络安全"); choice1.addItem("人工智能"); choice1.addItem("数据库技术"); choice1.addItem("计算机应用技术"); choice1.addItem("软件技术"); choice2.addItem("北京"); choice2.addItem("湖北武汉"); choice2.addItem("安徽合肥"); choice2.addItem("陕西西安"); choice2.addItem("上海"); choice2.addItem("天津"); choice2.addItem("吉林长春"); choice2.addItem("黑龙江哈尔滨"); choice2.addItem("广东广州市"); button1.setEnabled(false); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { label1.setForeground(Color.red); label1.setText("大学:"); label1.setBounds(new Rectangle(4, 20, 47, 25)); this.setLayout(null); button1.setLabel("确定"); button1.setBounds(new Rectangle(348, 19, 62, 23)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); checkbox1.setBackground(Color.orange); checkbox1.setFont(new java.awt.Font("Dialog", 1, 12)); checkbox1.setLabel("国家重点学科"); checkbox1.setBounds(new Rectangle(18, 64, 110, 18)); checkbox1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { checkbox1_itemStateChanged(e); } }); checkbox2.setBackground(Color.orange); checkbox2.setFont(new java.awt.Font("Dialog", 1, 12)); checkbox2.setLabel("博士学位授予权"); checkbox2.setBounds(new Rectangle(19, 86, 110, 15)); checkbox2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { checkbox2_itemStateChanged(e); } }); label2.setForeground(Color.red); label2.setText("所在地区:"); label2.setBounds(new Rectangle(147, 55, 65, 20)); choice2.setBounds(new Rectangle(223, 56, 120, 21)); choice2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { choice2_itemStateChanged(e); } }); textArea1.setFont(new java.awt.Font("Dialog", 1, 22)); textArea1.setBounds(new Rectangle(7, 168, 373, 153)); textField1.setLocale(new java.util.Locale("zh", "CN", "")); textField1.setBounds(new Rectangle(58, 19, 115, 23)); textField1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) { textField1_keyPressed(e); } }); textField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { textField1_actionPerformed(e); } }); checkbox3.setBackground(Color.orange); checkbox3.setFont(new java.awt.Font("Dialog", 1, 12)); checkbox3.setLabel("具有两院院士"); checkbox3.setBounds(new Rectangle(21, 108, 108, 14)); textField2.setLocale(new java.util.Locale("zh", "CN", "")); textField2.setBounds(new Rectangle(221, 94, 153, 23)); textField2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { textField2_actionPerformed(e); } }); label3.setForeground(Color.red); label3.setText("网络地址:"); label3.setBounds(new Rectangle(149, 92, 64, 23)); button2.setLabel("置空"); button2.setBounds(new Rectangle(349, 55, 60, 23)); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); textField3.setLocale(new java.util.Locale("zh", "CN", "")); textField3.setBounds(new Rectangle(69, 136, 309, 27)); label4.setForeground(Color.red); label4.setText("补充信息:"); label4.setBounds(new Rectangle(3, 138, 62, 24)); choice1.setBounds(new Rectangle(222, 19, 122, 22)); choice1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { choice1_itemStateChanged(e); } }); label5.setBackground(Color.white); label5.setForeground(Color.red); label5.setText("学科:"); label5.setBounds(new Rectangle(181, 20, 38, 21)); this.setBackground(SystemColor.info); this.add(label1, null); this.add(label4, null); this.add(textField1, null); this.add(label5, null); this.add(choice1, null); this.add(choice2, null); this.add(label2, null); this.add(label3, null); this.add(checkbox2, null); this.add(checkbox3, null); this.add(button1, null); this.add(textArea1, null); this.add(button2, null); this.add(checkbox1, null); this.add(textField2, null); this.add(textField3, null); } //Start the applet public void start() { } //Stop the applet public void stop() { } //Destroy the applet public void destroy() { } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } //Main method public static void main(String[] args) { famousUniversity applet = new famousUniversity(); applet.isStandalone = true; Frame frame; frame = new Frame(){ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public synchronized void setTitle(String title) { super.setTitle(title); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } }; frame.setTitle("Applet Frame"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(400,320); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); } void checkbox1_itemStateChanged(ItemEvent e) { textArea1.setText(""); textArea1.setForeground(Color.blue); textArea1.setFont(new java.awt.Font("Dialog",1,15)); textArea1.append("!!!焦点在checkbox1处!!!\r\n"); } void choice2_itemStateChanged(ItemEvent e) { textArea1.setText(""); textArea1.setForeground(Color.yellow); textArea1.setFont(new java.awt.Font("Dialog",1,16)); textArea1.append("!!!焦点在choice2处!!!\r\n"); } void checkbox2_itemStateChanged(ItemEvent e) { textArea1.setText(""); textArea1.setForeground(Color.green); textArea1.setFont(new java.awt.Font("Dialog",1,18)); textArea1.append("!!!焦点在checkbox2处!!!\r\n"); } void textField1_actionPerformed(ActionEvent e) { textArea1.setText(""); textArea1.setForeground(Color.pink); textArea1.setFont(new java.awt.Font("Dialog",1,20)); textArea1.append("!!!焦点在textField1处!!!\r\n"); } void button1_actionPerformed(ActionEvent e) { textArea1.setForeground(new Color(255,0,0)); textArea1.setFont(new java.awt.Font("Dialog",1,16)); textArea1.setText(""); if (textField1.getText()!=""){ textArea1.append("大学名称:"+textField1.getText()+"\r\n"); textArea1.append("该大学所在地理位置:"+choice2.getSelectedItem()+"\r\n"); if(choice1.getSelectedItem()=="网络安全"){ textArea1.append("学科名称:网络安全\r\n"); } else if(choice1.getSelectedItem()=="人工智能"){ textArea1.append("学科名称:人工智能\r\n"); } else if(choice1.getSelectedItem()=="数据库技术"){ textArea1.append("学科名称:数据库技术\r\n"); } else if(choice1 .getSelectedIndex()==3){ textArea1.append("学科名称:计算机应用技术\r\n"); } else if(choice1 .getSelectedIndex()==4){ textArea1.append("学科名称:软件技术\r\n"); } if(checkbox1.isEnabled()==true){ textArea1.append("该学科是国家重点建设学科\r\n"); } if (checkbox2.isEnabled()==true){ textArea1.append("该学科具有博士学位授予权\r\n");}if (checkbox3.isEnabled()==true){ textArea1.append("该学科拥有两院院士\r\n");}textArea1.append("该大学的网络地址:"+textField2.getText()+"\r\n");textArea1.append("该大学的补充信息:"+textField3.getText()+"\r\n");}} void textField1_keyPressed(KeyEvent e) {button1.setEnabled(true); }void button2_actionPerformed(ActionEvent e) {textField1.setText("");textField2.setText("");textField3.setText("");button1.setEnabled(false);textArea1.append(""); } void choice1_itemStateChanged(ItemEvent e) { textArea1.setText(""); textArea1.setForeground(Color.black); textArea1.append("输入焦点在choice1处\r\n"); } void textField2_actionPerformed(ActionEvent e) { textArea1.setText(""); textArea1.setForeground(Color.yellow); textArea1.append("!!输入焦点在textField2处!!\r\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -