📄 mainapplet.java
字号:
package jdeveloper.patterns.command;import java.awt.*;import java.awt.event.*;import java.applet.*;/** * Title: Jdeveloper's Java Projdect * Description: n/a * Copyright: Copyright (c) 2001 * Company: soho * @author jdeveloper * @version 1.0 */public class MainApplet extends Applet { boolean isStandalone = false; Button Invoker = new Button(); FlowLayout flowLayout1 = new FlowLayout(); TextField textField1 = new TextField(); TextField textField2 = new TextField(); /**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 MainApplet() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { Invoker.setLabel("Invoker"); this.setLayout(flowLayout1); textField2.setColumns(8); textField2.setEditable(false); textField1.setColumns(8); textField1.setEditable(false); this.add(Invoker, null); this.add(textField1, null); this.add(textField2, null); Command1 cmd1 = new Command1(); Command2 cmd2 = new Command2(); Invoker.addActionListener(cmd1); Invoker.addActionListener(cmd2); } /**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) { MainApplet applet = new MainApplet(); 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); } class Command1 implements ActionListener{ public void actionPerformed(ActionEvent e){ textField1.setText("Hello"); } } class Command2 implements ActionListener{ public void actionPerformed(ActionEvent e){ textField2.setText("World"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -